IOT Based Device Controlled with Security

IoT is getting popular and better day to day, due to its advantage like remote control, user-friendly, securer control of appliance, etc. So, today in this article we are going to design an IoT Based Device Controlled with Security using Node MCU. The reason of selection Node MCU for this project is cheap, powerful as well as Arduino compatible.

With the purposed design is shown below one can control different electrical devices securely. You can increase and decrease the number of devices according to your requirement with little modification in software code and circuit diagram.

Features of IoT Based Device Controlled with Security

  1. Secure: People with usernames and passwords can only control the device.
  2. No dedicated app is needed: One can control the device using any browser.
  3. Multiple device control: With the purposed design, one can control 4 devices at a time but can easily increase and decrease the number.
  4. Cheap and easy design: Node MCU is cheaper in comparison with other IoT devices and easy because it is Arduino friendly.
  5. Lockdown features: If any user enters username and password incorrectly three times, the system locks down for 3 minutes. This time can be increased and decreased.

Component Required

  1. Node MCU
  2. 4 x 1N4007 diode
  3. 4 x 12V Relay
  4. 4 x BC548
  5. 4 x 5K resistor
  6. 1 x LM7805
  7. 1 x 100 uF

Circuit Description IOT Based Device Controlled with Security:

The circuit “IOT Based Device Controlled with Security” shown in figure 1 is very simple and straightforward. This circuit contains node MCU and for switching circuit. This node MCU is used to switch ON and OFF the appliance according to the command we give online.

IOT Based Device Controlled with Security

Switching Circuit:

The switching circuit is designed around transistor BC548 and relay. These four switching circuits are identical. The signal from node MCU is given to the base of the transistor which energizes the relay and switch on the device.

A diode is connected across the relay coil to protect the control circuit from flyback voltage from the relay coil. Mains line is given to mains line connector where four devices are connected to four connectors (Load 1 to Load 4).

Here, we are using Node MCU based on ESP8266 for controlling all switches. As we are controlling four devices, four digital pins are used i.e. D5, D6, D7, and D8.

Software for IoT Based Device Controlled with Security:

Before going to software code, we have to configure Arduino IDE to program Node MCU using Arduino IDE.

Please check the previous article on how to configure ARDUINO IDE for programming Node MCU. How to configure Arduino IDE Node MCU

Now it’s time to get your IP Address. For that go to the website link “https://tttapa.github.io/ESP8266/Chap07%20-%20Wi-Fi%20Connections.html” and upload station mode code to your Node MCU and then open the serial monitor (Ctrl + Shift + M). There you will get your IP address. Note it down, because this IP address is your URL where you can control your device (Switch ON and OFF).

Screenshot for web-page

login page

Figure 2: Web Login Page

After Login Page

Figure 3: Device Control Page

device status page

Figure 4: Device Status Page

The function used in Software:

When we type the URL (IP Address) this function is called to check the status. void statusCheck()

This function is used to generate 32-bit cookies from random characters. void generate cookie()

This function is used to check whether cookies are valid or not. bool if_authenticated()

This function is used to check the status of output pins. void pinControl()

This function is used to generate the webpage where background_color is used to change the color of the button. void webPage()

This function is used to handle invalid webpage requests. void handle not found()

This function handles the login page and is responsible for the invalid count and lock user. void handleLogin()

Code Modification: You have to modify some parts of the code.

Operation mode: Here you decide the operating mode of ESP8266 (STA or APM).

WiFi Configuration: Here you have to set your SSID name and its Password.

Logging Details: Here you have to set logging user name and password.

Header Message: Edit your header here.

Wrong Attempt: Number of the wrong attempts allowed (after that user will be locked down).

Lockdown Time: Lockdown time when the user exceeds the wrong attempt.

Cookies Time: The time for cookies expire

Refresh Time: Time for the refreshing webpage for a status check.

After changing the code according to your requirement upload the entire code to your Node MCU. And your IOT device is ready.

2 Thoughts to “IOT Based Device Controlled with Security”

  1. Parampreet Singh

    call of overloaded ‘abs(long unsigned int)’ is ambiguous
    shows above error for below line bro
    if(abs(millis() – inactiveTime) > cookieExpireTime){ // if there is no activity from loged in user,a new cookie is generated

    1. I have recompiled the code and found no error.
      please update the IDE (Version Arduino 1.8.13) and board (select board NodeMCU 1.0).

Leave a Comment