Header Ads Widget

Home automation based on Cayenne IoT platform.

#IOT
#ESP8266 Project

IoT (Internet of Things) is a hot buzz around the world since last few years and lot of companies are entering this business. Although this concept has suddenly evolved in past few years, but this is not a new concept. Earlier this was limited to industries, now what is new is that we want to connect everything around us to internet, may it be your fridge, washing machine, microwave ovens, toaster, your car, bike or even each lighting bulb. CISCO calls this as “Internet of Everything (IoE)” and it is expected to have 50 billion devices will be connected to internet by 2020. Considering this, we can expect that in future almost everything may come with a unique IP address that can be connected to internet/your home wi-fi router and data can be pulled from each device thru connected sensors over internet at a remote location and remotely we can provide commands to actuators for performing some action at site.

Cayenne IoT Home Automation

With IPv4 there was limitation but with IPv6 in place we can have 2^128 different devices with unique IP. Today we have so many different service providers who are offering good bandwidth at lower prices. Smaller batteries can power devices for longer time and we have multiple sensors available to measure the physical parameters around us, hence above concept is easier to implement today. Here I have explained how to make a home automation system where we can measure temperature, relative humidity & light intensity and see it remotely on web, sitting anywhere in the world. At the same time, we can switch ON or switch OFF lights and fans or whatever devices connected to this device.

This article was also published in Electronics for You magazine in 2019 which is available here.

You can also download the “Cayenne” app from “Google Play Store”, login with same credentials and start controlling the things from anywhere over the internet.

Circuit Description: 

It has two input channels, one is analog input to measure light intensity thru LDR and second one is digital input to read value of temperature and relative humidity thru DHT11 sensor. For measuring wider range of temperature and humidity we can replace it with DHT22 and in code also, we need to replace the word ‘DHT11’ with ‘DHT22’. Table below shows basic comparison of DHT11 and DHT22. Rest all specs including pin configuration, is same.

ESP8266 Home Automation Circuit

The circuit is powered thru 12V supply as it need to drive the relays and a 5V supply has been derived using IC7805 which is required to power ESP8266 module. Additional battery backup can be added which is optional. It can be ignored if it is powered thru UPS or inverter line which has its own backup.

Here we have used NodeMCU V1.0/ESP8266 (ESP12) having 11 GPIO pins and 01 ADC input with 10bit resolution. It has inbuilt 3.3V voltage regulator and CP2102 based USB to serial converter which give easy interface with PC for loading the Arduino code.

NodeMCU is plugged into 30Pin (2X15) female header, and rest of the components around it are wired on the general-purpose PCB.

LDR1 is used to sense the intensity of light around it which is displayed as percentage on Cayenne dashboard. This is connected to A0 pin of module to read analog voltage being generated based on ambient light.

DHT11 sensor is used here to read the ambient temperature and relative humidity thru digital I/O pin D5 (GPIO14). This sensor has capability to split the data for temperature and relative humidity and send one by one thru same output pin.

Two 12V relays are used here which are driven thru 2N2222 transistor and can drive any load thru terminal headers connected to it as per relay rating.

Similar relay switches can further be added to the module depending on available I/O pins and your requirements.

Software Coding:

The software is written in easy to use Arduino platform which allows us to write the code in few lines and make the device communicate with Cayenne platform when connected to internet thru any access point or wi-fi router.

To add board manager for ESP8266 Gotoà File à Preferences à Paste below link in “Additional board Manager URL:”

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Open Boards Manager from Tools > Board menu and install esp8266 platform (and don't forget to select your ESP8266 board from Tools > Board menu after installation).

For programming the NodeMCU module, we need three unique identities from Cayenne web site, i.e. “MQTT user name”, “MQTT password” & “Client ID”. Whenever the device is connected on network, these IDs help Cayenne website to find the device and start communicating with it.

Other IDs required are your wi-fi “SSID” and “password” if any, to connect with local wi-fi network. Before compiling and loading the code to NodeMCU module, two libraries are supposed to be installed as described below.

Download required libraries from below link:

https://github.com/myDevicesIoT/Cayenne-MQTT-ESP

https://github.com/adafruit/Adafruit_Sensor

https://github.com/adafruit/DHT-sensor-library

Additional Libraries: After downloading and installing Arduino tool, goto Menu “Sketch” --> “Include Library” --> “Add .ZIP Libraries…” --> locate the zip file and install.
Cayenne-MQTT-ESP8266 Library: Allows NodeMCU to communicate with Cayenne MyDevices platform.

DTH Library: Allows DHT11 sensor to communicate with NodeMCU.Search word “Unified” under “Library Manager” and install “Adafruit Unified Sensor”.

Arduino Code:


Building Dashboard on Cayenne Website:

Open the website https://mydevices.com and click on login on right top.

From the pop-up select “Cayenne” login. Create an account thru “Register” link below login button.

Click “Bring Your Own Thing”, next page will give you three unique strings.

1-      MQTT Username

2-      MQTT Password

3-      Client ID

Page will wait here to connect with the device on network.

Copy these strings and paste at appropriate fields in arduino code. And load the code in NodeMCU module thru USB cable.

Once the module is connected to Wi-fi, the web page will move to next screen. Here your device will be given a unique name, which can be changed thru “Settings” icon on right top.

You should get a screen something like this.

Cayenne IoT Panel

Click on plus sign on each channel icon to add the channel to your dashboard. You will get the names of added channels on left has explorer.

Cayenne Channel List

Click on Settings icon  of “Channel 0” --> Click on “Settings”, changes its “Widget name” as “Luminosity”. Click on “Choose Icon” and select “Luminosity” by typing few letters “Lum…”, and click on “Save”. The Icon will change as below. It shows the light around LDR in percent.

Cayenne Panel Icon

Similarly change the name of “Channel 1” as “Temperature” and “Channel 2” as “Humidity”

Turn OFF the device, and proceed for configuring buttons to control two relays.

Go to “Settings” of Channel 3 & 4 and delete them, using “Remove” button.

Now Click on “Add New” --> “Device/Widget”

Select “Custom Widgets” --> Click on “Button”, fill the required data as below and Click on “Add Widget”.

Similarly repeat the steps for channel 4, as shown below.

Cayenne Channel Configuration

Final dashboard will look as below. Now you are ready to control the two relays attached to channel 3 and 4. And collect Luminosity, temperature and humidity level of place where your device is located.

Cayenne Final Dashboard

Enjoy your first IoT project. You can also download the "Cayenne" app from Google play store and login with same credentials. All your configured devices will display there. You can control from there also, rather than going to web page.


Return to List of content                                                Return to DIY Project List


Post a Comment

4 Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Awesome! Information. Great work thank you for sharing such useful information. keep it up all the best.

    ReplyDelete
  3. Thanks for Sharing!!

    George Stevens Manufacturing has been a global leader in designing and building innovative winding machines since 1943. A range of coil and transformer winding machines is ideal for semiautomatic machines.

    ReplyDelete