Tuesday, December 24, 2024

Smallest IoT Home Automation using ESP8266 – 01 with Videos (Hindi & English)

- Advertisement -

In this project, we will be using the ESP8266 – 01 Wi-Fi Development board to make a small IoT home automation that has Wi-Fi featured in it. The system operates on a local web server and is easy to use for the novice. With this project, we can control at most two AC appliances which suit best for your small IoT projects.

Espressif developed Wi-Fi enabled microchip – ESP8266 proved to be a boon in the IoT field. This caused the arrival of various other ESPs and Open Source Development boards thereby allowing even a novice to make Wi-Fi featuring applications.

Fig. 1: ESP-01 1MB version(extreme left) and 0.5MB version(extreme right)

On a local web server, we do not require Internet and handling everything over Wi-Fi is possible. Here, we will be handling the two Input & Output pins and switching relays on a web page of the local server. We can connect our home appliances with the Relay Module that will be driven by ESP8266 – 01.

- Advertisement -

Material required for the IoT project

  1. ESP8266 – 01: It will serve as the brain of our project.
    Fig. 2: ESP8266 – 01
  2. FTDI Board (USB to TTL): To upload code in ESP8266 – 01.

    Fig. 3: FTDI Board
  3. 2 AC Appliances
  4. One(1) 2-Channel Relay Module

    Fig. 4: 2 Channel relay module
  5. Breadboard with some wires.

Steps for the ESP8266 Setup in Arduino IDE

(Ignore this step if you already have the setup for Arduino IDE)

To code the ESP8266 we need an Integrated Development Environment and we will use Arduino IDE software. Arduino IDE is a cross-platform application. It is written in Java and coded in C/C++ with some special rules. To download the latest Arduino IDE click here.

Arduino IDE does not contain support of ESP8266 family so to install the ESP8266 Boards library in Arduino IDE, follow the instructions below.

  1. Open Arduino IDE. Go to File > Preferences.

    Fig. 5: Preferences in Arduino IDE
  2. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into the “Additional Board Manager URLs” field. Now, click the “OK” button.
  3. Go to Tools > Board > Boards Manager.

    Fig. 6: Boards manager in Arduino IDE
  4. Search and scroll down ESP8266 board in menu and install “esp8266 by Esp8266 community”.
  5. Select your ESP8266 board from Tools > Board > Generic ESP8266 Module.

    Fig. 7: Board Selection in Arduino IDE
  6. Restart your Arduino IDE.

Source Code of the IoT project

Download the Code from the link below and Open it in Arduino IDE. Before uploading you need to make some changes in the code. Let’s understand the code.

Place your Wi-Fi credentials here within the double quotes. The <ESP8266WiFi.h> library helps to run the functions of Wi-Fi in Arduino IDE.

Fig. 8: Wifi credentials

In the void setup(), we place all the one-time setup codes. All the instructions written here will run only once or after every Reset.

Fig. 9: Void Setup()

So, the GPIOs 0 and 2 of ESP8266 are made OUTPUT here and the server is started.

Void loop() is the place for the main executable instructions. The GPIO values are changed here as per the request of the client connected.

Fig. 10: Void Loop()

This request is displayed via this HTML page.

Fig. 11: HTML Web page in the source code

Save the Code. To Upload the code, follow the instructions below.

  1. Connect the FTDI pins to ESP8266 as shown below.

    Fig. 12: Flashing ESP8266 – 01
  2. Select your COM Port from Tools > Port after connecting FTDI USB to your PC or Laptop.
  3. Also, check if your ESP8266 supports 9600 or any other Baud Rate.
  4. Now Click Upload.

The code in ESP8266 is uploaded in Flash Mode, which is when GPIO 0 is grounded.

Now, to run the code in it, we need to remove it from Flash Mode. For this, simply remove GPIO 0 from the ground and Reset.

To Reset ESP8266, simply touch the Reset Pin of ESP8266 to Ground for half a second. Its Blue LED will flicker.

Circuit diagram for Home automation

Flow the circuit diagram for making the home automation system.

GPIO 0 -> Relay IN 1

GPIO 2 -> Relay IN 2

We will use 5 volts input supply for driving the Relay Module and 3.3 Volts Input for the ESP8266.

Circuit diagram for IoT Home Automation
Fig. 13: Circuit diagram for IoT Home Automation

Connecting to the web using the IP address

After uploading the code, go to Open Tools>Serial Monitor. ESP8266 will try to connect to Wi-Fi and display its IP address on Arduino serial monitor. This IP is needed only the first time. The IP remains the same forever so have this IP before making the main connections.

Make sure that the Wi-Fi router to be connected is already open. Hit this IP address in the browser of the device connected to the same Wi-Fi.

Url:  http://192.168.xx.xx (your IP displayed in Arduino serial monitor)

You will be able to see the HTML Web page mentioned in the code.

Fig. 14: HTML Web page

Now, by changing the values in the URL you can switch your appliances.

IoT Home Automation Project Testing
Fig. 15: Testing the IoT Home Automation project

Try with,

http://<your IP address>/gpio1/0

http://<your IP address>/gpio1/1

http://<your IP address>/gpio2/0

http://<your IP address>/gpio2/1

IoT Home Automation System Testing
Fig. 16: IoT Home Automation System Testing

To download the source code click here.

To purchase the components for this project visit kitsNspares.

8 COMMENTS

  1. With the ESP-01S-Relay-v1.0 module, I want to use my home lamp both from WiFi and manually.
    I want to turn it on and off from the wifi while the lamp switch is off.
    How can I do that? Can you help me.

SHARE YOUR THOUGHTS & COMMENTS

EFY Prime

Unique DIY Projects

Electronics News

Truly Innovative Electronics

Latest DIY Videos

Electronics Components

Electronics Jobs

Calculators For Electronics

×