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-conditioning, and lighting. It also contributes to an overall cost reduction and saves energy. Energy saving is the main issue at the present time.
Existing and well-established systems are based on wire communication. This system has not faced any problems as long as it plans before the physical construction of those buildings. But in a complete building when there is a requirement for 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 will build a home automation system using Arduino and the 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 Using Cayenee
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 Using Cayenne
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 the sensors and actuators of the home automation system. But most of the automation system available in the market is scalable in that one server can manage many hardware modules. Because they exist on WiFi network coverage.
- 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 built 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 and are used as actuators. Electrical loads like lights and fans are connected to the contacts of the relays. These relays are controlled remotely through a mobile app.
The ESP8266 Wifi module is used here as an embedded controller programmed by Arduino. The Arduino handles Analog or digital data received from sensors and transmits over the web. At this time it accepts commands from the web and actuates connected devices or actuators.
The Internet is used as a link to connect the embedded system to others.
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 in programming the user interface.
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 the data flow speed is very high.
Circuit Design Using PCB Software
To make the circuit compact and give a professional look, I 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.
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 toward what makes PCBWay an ideal company and brand for any electronic hobbyist In this article, I will state how can we order PCB from PCBWay with step by step guide.
Working Principle of Home Automation System Using Cayenee
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 for 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 a 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 the 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 is built by this when connected to the network.
Using this Arduino IDE software:
- Open Arduino IDE software
- 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.
- For programming the ESP8266 module, three unique identities are required from the Cayenne website. These are the name, MQTT user name, MQTT password, and client ID. After connecting to a network these IDs help to communicate the device with it.
- Connecting to the local WiFi network requires WiFi SSID and password.
- Before compiling and loading 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.
This allows communication of the devices on the Cayenne platform.
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.
The next page will show three options: MQTT Username, MQTT Password and Client ID. Copy these strings and paste them into the 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.
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.
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 the “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 relays. For that click on Add New Device Widget then select the Custom Widgets button. Fill in the required field for “Channel 3” for the load. Again click on Add Widget and similarly repeat the settings for “Channel 4”.
Finally, the dashboard is shown in the above figure. Now you are ready to control “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.
#define CAYENNE_PRINT Serial
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;
#define DHTPIN D4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
if (millis() - lastMillis > 10000)
lastMillis = millis();
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(" *C ");
Serial.print("Heat index: ");
Serial.print(" *C ");
3 thoughts on “Home Automation System Using WiFi Module ESP8266 & Cayenee”
Thanks for this project, it literally help me out for my final year engineering project
Helpful for me
Thanks for this circuit. I literally found this in many websites that uses cayenee platform. Atlast I found it thank you.