Home Automation System Using WiFi Module ESP8266

These days, home automation becomes very popular. It provides comfort in a private home. On the other side, a home automation system allows centralized controls of heating, ventilation, air-condition, and lighting. It also contributes to an overall cost reduction and saves energy. Energy-saving is the main issue in the present time.

Existing and well-established systems are based on wire communication. This system has not faced any problem as long as it plans before the physical construction of those buildings. But in a complete building when there is a requirement of extension, the wiring system requires much effort and cost.

Then the concept of wireless or automation systems comes. In recent years, wireless systems reached their breakthrough. Wireless systems are used everywhere. Examples are wireless security cameras, wireless alarms, wireless home appliances, etc.

In this project, we are going to build a home automation system using Arduino and WiFi module ESP8266. For control relays, we use manual switches and smartphones. This project can sense sunlight and room temperature to turn on and off lights and fans automatically.

Features of WiFi Home Automation System

This project has the following features:

  • Wifi controlled home appliances using relay
  • Temperature and humidity detection system
  • LDR controlled home appliances

Principle of Home Automation Project

This system has two main parts. The first part is the server, which presents the core of the system. It manages, controls, and monitors users’ homes.

The second part is the hardware module, which provides an appropriate interface to sensors and actuators of the home automation system. But most of the automation system available in the market is scalable that one server can manage many hardware modules. Because they exist on WiFi network coverage.


Circuit Diagram

Home Automation Using ESP8266 Circuit Diagram

Components Required

  • ESP8266 NodeMCU module
  • 4N33 Opto Coupler (x2)
  • DHT11 Temperature and Humidity sensor
  • Light Dependent Resistor (LDR)
  • 12V single changeover Relay (x2)
  • BC547 npn transistor (x2)
  • 5mm LED (x2)
  • IN4007 Diodes (x2)
  • 100uF/25V Capacitor
  • 0.1uF Capacitor
  • 1K Resistor (x5)
  • 10k, 3.3K, 4.7K Resistors
  • Switch (on/off)
  • 4- pin connector
  • 2- pin terminal connector for battery

About Home Automation System Project Parts

An IoT system is build up with some basic components. The components are sensors, actuators, embedded systems, networks, user interfaces, and data storage.


In this project, two types of sensors are used. The first one is an LDR or light-dependent resistor to sense the intensity of light. The second one is DHT11 to sense temperature and humidity.


The output pins are connected to the relays are used as actuators. Electrical loads like lights, fans are connected to contacts of the relays. These relays are controlled by remote through a mobile app.

Embedded System

ESP8266 Wifi module used here as an embedded controller programmed by Arduino. The Arduino is used to handle analog or digital data received from sensors and to transmit over the web. At this time it accepts commands from the web and actuates connected devices or actuators.


Internet is used as a link to connect the embedded system to the others.

User Interface

For communication, the Cayenne platform supports MQTT or Message Queue Telemetry Transport protocol. This protocol is a lightweight messaging protocol for use of IP protocol. It is designed for low-power and low bandwidth devices.

Cayenne’s platform is very simple to use. This saves time and effort for programming the user interface.

Data Storage

The data storage is also created by the Cayenne platform. Big data storage is basically huge data that is collected from all devices. This type of data varies from device to device and data flow speed is very high. 

Circuit Design Using PCB Software

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the home automation project using the ESP8266 WiFi module on the breadboard. I will explain in detail how we can design and order PCB for our project.

Home Automation Using ESP8266 Gerber PCB

For the Gerber file check out this link Home Automation Using ESP8266

Order PCB From PCBWay

I ordered the PCB prototype board from the www.pcbway.com website. PCBWay is a Chinese-based PCB (printed circuit board) prototype, PCB assembly, SMD Stencil, and Flexible PCB manufacturer. They ship to more than 170 countries worldwide and process more than 2100 PCB orders a day. It feels like PCBWay gives an excellent price and customer service factor in one single serving. The quality of the PCB is awesome and its thickness is really great. What is also spectacular about PCBWay to me, as a maker and customer, is their service. From their friendly support staff to their intuitive, user-friendly website features, it all counts towards what makes PCBWay an ideal company and brand for any electronic hobbyists In this article, I will state that how can we order PCB from PCBWay with step by step guide.

Features of PCBWay

1. PCB prototyping and manufacturing

They produce FR-4 and Aluminum boards and advanced PCBs like Rogers, HDI, Flexible and Rigid-Flex boards, at a very reasonable price.

Visit the link for Instant Quote

Visit the link for Gerber file viewer

2. PCB assembly

SMT & THT assembly starts from only $30 with a free stencil and free worldwide shipping. The components can be sourced and provided by PCBWay, or by clients themselves.

3. Layout and design

Partnering with quality service providers to offer design services.

4. Open source community

Student sponsorship shared PCB projects an so on.

5. 3D Printing & CNC

On-demand Production and Rapid Prototyping in as Fast as 1 Day Leading the Digital Manufacturing Revolution.

Pcbway interface

Step 1: Go to the PCBWay website and sign up/sign in. Into the PCB Prototype tab, enter the dimensions of your PCB, the number of layers, and the number of PCBs you require. After that proceed by clicking on the ‘Quote Now’ button.

Pcbway interface 2

Step 2: You will be redirected to a page where to set a few additional parameters like the board type, layers, material for PCB, thickness, and more, most of them are selected by default, if you are opting for any specific parameters, you can edit it in here.

Pcbway interface 3

Step 3: The final step is to upload the Gerber file and proceed with the payment. To make sure the process is smooth, PCBWAY verifies if your Gerber file is valid before proceeding with the payment. This way, you can be sure that your PCB is fabrication friendly.

Working Principle of Home Automation System

The ESP8266 based home automation system is built around Wifi module ESP8266, LDR, DHT11 sensor, optocouplers 4N33, and two relays.

This circuit has two parts. The first part is an analog input to measure light intensity through LDR1. The second part is digital input to read values of temperature and humidity through DHT11. For measuring a wide range of temperature and humidity, you can use DHT22 as the replacement of DHT11.

To power this circuit we need a 12V DC supply, as It needs to drive relays. Then we have to power the ESP8266 module, but it requires 5V. IC 7805 provides the 5V to the module.

NodeMCU V1.0 or ESP8266 has 11 GPIO pins and one ADC pin with 10-bit resolution. In the figure, we explain the pin configuration of esp8266. This module has a 3.3V inbuilt voltage regulator. It also has a CP2102-based USB to serial converter that gives an easy interface with the PC for loading Arduino code to module.

ESP8266 has a 30-pin male header. Components the soldered on the PCB.

The LDR is used here to sense the light intensity around it. It is displayed as a percentage form on the cayenne dashboard. This is connected to the A0 pin of the ESP8266 module to read analog voltage based on ambient light.

DHT11 sensor is used here to read temperature and humidity through digital input pin D4. The given data is split into temperature and humidity by DHT11 through the same input pin.

Two BC547 transistors drive those relays through the 4N33 optocoupler. Each relay can drive AC/DC load through the terminal headers connected to it.


This communication between the cayenne platform and the device, built by this when connected to the network.

Using this Arduino IDE software:

  1. Open Arduino IDE software
  2. Go to File and select Preferences and paste the link “https://arduino.esp8266.com/stable/package_esp8266com_index.json” in Additional Board Manager URLs to add the ESp8266 Board. Open Boards Manager from the Tools menu and type esp8266 to install the esp8266 platform.
  3. For programming the ESP8266 module, three unique identities are required from the cayenne website. These are name, MQTT user name, MQTT password, and client ID. After connecting to a network these IDs help to communicate the device with it.
  4. To connect to the local WiFi network requires WiFi SSID and password.
  5. Before compiling and load the code to this module, we have to install the Adafruit sensor library, Cayenne-MQTT-ESP8266 library and DHT library.

To add these libraries to Arduino IDE, go to Sketch – Include Library – Add .zip Library – locate and install files.

Cayenne-MQTT-ESP8266 Library

This allows communication of the devices on the Cayenne platform.

DHT library

This library is used for the DHT11 sensor. This library communicates the ESP8266 module to the sensor. To use it search unified under Library Manager and install Adafruit Unified Sensor.

Building Home Automation System Dashboard Using Cayenne IoT

Open the official Cayenne website and create an account for yourself. Click on Bring Your Own Thing.

Home Automation System using cayenee software

The next page will show three options: MQTT Username, MQTT Password and Client ID. Copy these strings and paste them into appropriate fields of the Arduino ESP8266 code. After that, upload the Arduino IDE code to the NodeMCU module and wait some time to connect with the device on the network.

Home Automation System using cayenee software 2

Once the NodeMCU module is to the WiFi, the webpage will forward to the next screen where your device needs a name that can be changed after.

Now click the (+) button on each channel icon to add your desired channel to the dashboard. You will get the added channels on the left under Add New Page.

Click on the settings of each channel one after another and change their widget name to your desired name.

First set “Channel 0” name to Luminosity and click on Choose Icon and select Luminosity and click on Save. This function shows the light around LDR in percentage.

Similarly, change the “Channel 1” and “Channel 2” names to Temperature and Humidity respectively. Change the required settings as set on “Channel 0”.

Now we have to configure”Channel 3″ and “Channel 4” for controlling both the relays. For that click on Add New Device Widget then select the Custom Widgets button. Fill the required field for “Channel 3” for the load. Again click on Add Widget and similarly repeat the settings for “Channel 4”.

Home Automation System using cayenee software 3

Finally, the dashboard is shown in the above figure. Now you are ready for controlling the “Channel 3” and “Channel 4” and also the Luminosity, Temperature and Humidity level of a certain place.

Next, we need to download the Cayenne app and log in using the same credential id to start the home automation system from anywhere in the world over the internet.

Arduino Code

//DO not forget to replace SSID and WiFi password with your own WiFi IDs
#include <Adafruit_Sensor.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

char ssid[] = "Wifi Name";
char wifiPassword[] = "Password";

char username[] = "e2g58968-d026-11eb-8779-7d56e82df461";
      //Replace by your MQTT user name
char password[] = "3f2b61c76836fc5t489605346e4b110f80785ca";  //Replace by your MQTT password
char clientID[] = "73f369dr-d4f5-39da-8779-7d56e82df461";      //Replace by your Client ID

unsigned long lastMillis = 0;
#include "DHT.h"
#define DHTPIN D4     
#define DHTTYPE DHT11  
float h,t,f,hic,hif;

void setup()
Cayenne.begin(username, password, clientID, ssid, wifiPassword);

void loop()
if (millis() - lastMillis > 10000)
lastMillis = millis();
Cayenne.virtualWrite(0, h);
Cayenne.virtualWrite(1, t);
Cayenne.virtualWrite(2, hic);
h = dht.readHumidity();
t = dht.readTemperature();
f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f))
Serial.println("Failed to read from DHT sensor!");
hif = dht.computeHeatIndex(f, h);
hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(" *C ");
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(" *C ");
Serial.println(" *F");

int currentValue=getValue.asInt();

int currentValue=getValue.asInt();

int currentValue=getValue.asInt();

int currentValue=getValue.asInt();

Video Output

1 thought on “Home Automation System Using WiFi Module ESP8266”

  1. Thanks for this circuit. I literally found this in many websites that uses cayenee platform. Atlast I found it thank you.


Leave a Comment