IoT based Home Automation System(4 Channel Relay), using NodeMCU ESP8266 12E, which is an Cayenne IoT platform, thereby enabling full control of all the loads in the system from anywhere in the world, via a public web application, with an internet connection.
Home Automation gives us access to control devices in our homes from a mobile device anywhere on Planet Earth.
Here to learn how to build an IoT system using ESP8266, myDevices Cayenne, and MQTT. In more detail, this IoT tutorial discovers how to use an ESP8266 to send data to Cayenne using the MQTT protocol. Moreover, this ESP8266 MQTT project investigates how to use MQTT to control remote peripheral devices using a web interface. This is a complete step-by-step tutorial on building an IoT system using Cayenne and ESP.
On the other hand, Cayenne is an IoT cloud platform that provides several cloud services, such as:
Data visualization
IoT cloud
Alerts
Scheduling Events
We will focus our attention on data visualization and on the IoT cloud services.
Cayenne
Cayenne IoT Platform accelerates the development of IoT-based solutions, including quick design, prototyping and other commercialized projects. It is a drag-and-drop IoT project builder that can help developers build complete, ready-to-use IoT solutions with little to no coding.
Cayenne IoT Platform contains a vast catalog of certified IoT-ready devices and connectivity options. This allows users to easily add any device to the library utilizing MQTT API. All devices in Cayenne are interoperable and benefit from features such as rules engine, asset tracking, remote monitoring and control, and tools to visualize real-time and historical data.
MQTT is a lightweight messaging protocol for sensors and mobile devices.
NodeMCU
NodeMCU ESP8266-12E MCU is a development board with one analogue and many general-purpose input output (GPIO) pins. It has 4MB flash memory, and can operate at a default clock frequency of 80MHz. In this project, digital pin D5,D6, D7 & D8 of NodeMCU is used Output Data 0 or 1 to Relay Channel Board.
4 Channel Isolated 5A or 10A Relay HW-316
The 4 Channel Relay Breakout is an easy way to use your Arduino, Raspberry Pi, or other microcontroller to switch high voltages and high current loads. ... Each relay has the common, normally open, and normally closed pin broken out to a convenient 5.0mm pitch screw terminal.
While this board can be used to switch mains power, it should be done so using extreme caution. This should not be done without the aid of an experienced electrician.
Equiped with high-current relay, AC250V 10A ; DC30V 10A
5V 4-Channel Relay interface board, and each one needs 50-60mA Driver Current
Be able to control various appliances, and other equipments with large current
Application:Supports all MCU control, The industrial field, PLC control, Smart home control
Indication LED's for Relay output status
Circuit Diagram
Installing the ESP8266_Arduino_Library
Download the Cayenne-MQTT-ESP-master library from this link.
Click on Add ZIP Library and add Cayenne-MQTT-ESP-master zip file, or directly copy the folder (Cayenne-MQTT-ESP-master) and paste it in Libraries folder of Arduino IDE.
After installing the library, go to your Arduino IDE. Make sure you have the Nodemcu 1.0 ESP-12E board selected, and then, Copy and Paste code in Arduino IDE.
Subscribe and Download code.
Arduino Code
#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
const int relay[] = {12, 13, 14, 15};
char ssid[] = "TP-Link_3200"; // your SSID
char password[]="9500112137"; // YOUR WIFI PASSWORD
char username[] = "2031dd30-5414-11eb-b767-3f1a8f1211ba"; // yours
char mqtt_password[] = "f2ce829d98df3a768328ac6936eae9fd47d28289"; // yours
char cliend_id[] = "8497f0b0-54a1-11eb-883c-638d8ce4c23d"; // yours
void setup() {
Serial.begin(9600);
Cayenne.begin(username, mqtt_password, cliend_id, ssid, password);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
digitalWrite(14, HIGH);
digitalWrite(15, HIGH);
}
void loop() {
Cayenne.loop();
}
CAYENNE_IN(1)
{
digitalWrite(12, !getValue.asInt());
Serial.println(digitalRead(12));
}
CAYENNE_IN(2)
{
digitalWrite(13, !getValue.asInt());
Serial.println(digitalRead(13));
}
CAYENNE_IN(3)
{
digitalWrite(14, !getValue.asInt());
Serial.println(digitalRead(14));
}
CAYENNE_IN(4)
{
digitalWrite(15, !getValue.asInt());
Serial.println(digitalRead(15));
}
Hardware interfacing with Cayenne IoT platform
Click on Add new and then Device/Widget in Settings, Add New Device here and select Generic ESP8266 for in this project.
Configure device Generic ESP8266, MQTT username, password and client ID from Create App
Paste these respective details under username, password and client ID in Arduino source code , along with your Wi-Fi name and password.
After successfully compiling and uploading the code to NodeMCU, You will see ESP8266 connected to Wi-Fi. After the connection is established, the previous page is automatically updated on Cayenne. A new dashboard opens in the browser. Cayenne generates an ID and a device icon for your device.
Click on Custom Widgets and then value, and populate all fields . The channel number should be 1. (Make sure the channel number is same as in code.) Now, click on Add Widget.
Add New Widget, select Button
Relay ON/OFF by click Button Icon here, relay ON Shown in below snap
Relay ON/OFF by click Button Icon here, relay OFF Shown in below snap
Kommentarer