In this tutorial to build PIR motion sensor connected to Cayenne IoT Cloud platform, If Motion detected in the PIR sensor (monitor the office for activity, alert for suspicious activity) then Triggers the Notification from cayenne server sent to Email alert and SMS Message to mobile number. PIR sensor Produces Digital pulse high (3.3V) when triggered (motion detected) digital low(0V) when idle(no motion detected.
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.
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.
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 D0 of NodeMCU is used to read Data of PIR motion sensor.
PIR motion sensor
The HC-SR501 module uses a passive infrared sensor and an integrated circuit (IC) to detect motion. It features adjustable sensitivity that allows for a motion detection range from 3 meters to 7 meters. The module also includes time delay adjustments and trigger selection for fine tuning.
Connecting the PIR sensor
he PIR sensor typically has 3 leads attached: VCC, OUT and GND.
Connect the VCC PIR sensor pin to a 3v3 pin on the NodeMCU.
Connect the GND PIR sensor pin to a GND pin on the NodeMCU.
Connect the OUT PIR sensor pin to a D0 pin on the NodeMCU.
Now, we are ready to configure the device firmware.
Component Required
HC-SR501 PIR motion sensor
ESP8266 board
Female to female jumper wires
Micro USB cable (if necessary for your breakout board)
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>
#include <ESP8266WiFi.h>
char ssid[] = "SSID"; // YOUR SSID
char password[]="PASSWORD"; // YOUR PASSWORD
char username[] = "2031dd30-5414-11eb-b767-3f1a8f1211ba"; // YOURS
char mqtt_password[] = "f2ce829d98df3a768328ac6936eae9fd47d28289"; / /YOURS
char client_id[] = "3d65e860-5414-11eb-a2e4-b32ea624e442"; // YOURS
const int PIRpin = D0;// pir pin
int PIRval = 0;// for reading pir value
void setup()
{
pinMode(PIRpin,INPUT);//......| Seting sensors and modules input or output
Serial.begin(9600);
Cayenne.begin(username,mqtt_password,client_id,ssid,password);// starting cayenne
}
void loop()
{
Cayenne.loop();
PIRval = digitalRead(PIRpin); // read and store pir value
Serial.println(PIRval);
// send sensor values to cayenne
Cayenne.virtualWrite(5,PIRval);
}
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.
When a connection is made, sensor data gets uploaded to Cayenne. Temperature and Humidity data on Cayenne.
Widget Icon change here.
PIR sensor value setting for If and Then for trigger alert.
SMS notification in Mobile
Email Notification
You can get a PIR sensor data by cluck Data cloud icon instantly.
You can get a graphical representation of PIR sensor data by clicking on the Graph icon.
コメント