top of page

Search Results

163 results found with an empty search

  • IoT Based Motion Detection with Email alert & SMS

    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 #include 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 refer detail: https://www.dofbot.com/post/cayenne-iot-based-weather-monitor 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.

  • IoT Based Internet Clock using Dot Matrix Display

    In this tutorial we are going to do is a simple connected clock that displays, on the MAX7219 LED matrix, the time, picked with NTP from web, and fixed Message for scrolling display. The display light also changed based on the light that the photoresistor measures so even if it's day or night you can read time properly and energy saver. Circuit Diagram Components Required NodeMCU ESP8266 12E MAX7219 dot matrix Module 4 in 1 Jumper Wires Breadboard (optional) MAX7219 4-in-1 Display Dot Matrix Module This Module is an integrated serial input/output common-cathode display driver, it connects the microprocessor 7-segment digital LED display with 8 digits, you can also connect a bar graph display or 64 independent LED. Thereon including a B-type BCD encoder chip, multi-channel scanning loop segment word driver, but also a static RAM 8 x 8 for storing each data. Only one external register is used to set the segment current of each LED. LDR Light dependent resistors, LDRs, or a photoresistor is a passive component that decreases resistance with respect to receiving luminosity on the component's sensitive surface. The resistance of a photoresistor decreases with increase in incident light intensity; in other words, it exhibits photoconductivity. In this project, Analog pin A0 of NodeMCU is used to read Voltage in Between LDR and Series Resister for controlling the Brightness of the Matrix display. Other way to control brightness using Potentiometer and adjust brightness manually. Installing Libraries Download Max72xxPanel. After downloading the .zip files, add the libraries in Arduino IDE by clicking on To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Subscribe and Download code. Arduino Code #include #include #include #include #include int pinCS = D4; int numberOfHorizontalDisplays = 4; int numberOfVerticalDisplays = 1; char time_value[20]; // LED Matrix Pin -> ESP8266 Pin // Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS) // Gnd -> Gnd (G on NodeMCU) // DIN -> D7 (Same Pin for WEMOS) // CS -> D4 (Same Pin for WEMOS) // CLK -> D5 (Same Pin for WEMOS) Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); int wait = 70; // In milliseconds int spacer = 1; int width = 5 + spacer; // The font width is 5 pixels int Brightness; void setup() { Serial.begin(9600); WiFi.begin("TP-Link_3200","9500112137"); // your SSID, your wifi password //CHANGE THE POOL WITH YOUR CITY. SEARCH AT https://www.ntppool.org/zone/@ configTime(0 * 3600, 0, "it.pool.ntp.org", "time.nist.gov"); setenv("TZ", "GMT-05:30",1); // INDIA //change time zone matrix.setIntensity(0); // Use a value between 0 and 15 for brightness matrix.setRotation(0, 1); // The first display is position upside down matrix.setRotation(1, 1); // The first display is position upside down matrix.setRotation(2, 1); // The first display is position upside down matrix.setRotation(3, 1); // The first display is position upside down matrix.fillScreen(LOW); matrix.write(); while ( WiFi.status() != WL_CONNECTED ) { matrix.drawChar(2,0, 'W', HIGH,LOW,1); // H matrix.drawChar(8,0, 'I', HIGH,LOW,1); // HH matrix.drawChar(14,0,'-', HIGH,LOW,1); // HH: matrix.drawChar(20,0,'F', HIGH,LOW,1); // HH:M matrix.drawChar(26,0,'I', HIGH,LOW,1); // HH:MM matrix.write(); // Send bitmap to display delay(250); matrix.fillScreen(LOW); matrix.write(); delay(250); } } void loop() { Brightness = map(analogRead(0),0,1024,0,12); matrix.setIntensity(Brightness); matrix.fillScreen(LOW); time_t now = time(nullptr); String time = String(ctime(&now)); time.trim(); //Serial.println(time); time.substring(11,19).toCharArray(time_value, 10); matrix.drawChar(2,0, time_value[0], HIGH,LOW,1); // H matrix.drawChar(8,0, time_value[1], HIGH,LOW,1); // HH matrix.drawChar(14,0,time_value[2], HIGH,LOW,1); // HH: matrix.drawChar(20,0,time_value[3], HIGH,LOW,1); // HH:M matrix.drawChar(26,0,time_value[4], HIGH,LOW,1); // HH:MM matrix.write(); // Send bitmap to display delay(3000); matrix.fillScreen(LOW); display_message("Welcome"); // change your text message } void display_message(String message){ for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) { //matrix.fillScreen(LOW); int letter = i / width; int x = (matrix.width() - 1) - i % width; int y = (matrix.height() - 8) / 2; // center the text vertically while ( x + width - spacer >= 0 && letter >= 0 ) { if ( letter < message.length() ) { matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background off, reverse to invert the image } letter--; x -= width; } matrix.write(); // Send bitmap to display delay(wait/2); } } After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board, And see the result in Dot Marix display.

  • IoT Based Notice Board Using Dot Matrix Display

    Wifi Controlled Display Board, In this tutorial, you will learn how to make an IOT “Internet of Things” based Notice Board using Nodemcu ESP8266 Wifi Module and Max7219 8×8 LED Matrix and to update a message via Wifi network Through a web page. The scrolling text message on the 8×8 LED Matrix can be updated at any time from local Web server. Circuit diagram components Required NodeMCU ESP8266 12E MAX7219 dot matrix Module 4 in 1 - 2 nos Jumper Wires Breadboard (optional) MAX7219 4-in-1 Display Dot Matrix Module This Module is an integrated serial input/output common-cathode display driver, it connects the microprocessor 7-segment digital LED display with 8 digits, you can also connect a bar graph display or 64 independent LED. Thereon including a B-type BCD encoder chip, multi-channel scanning loop segment word driver, but also a static RAM 8 x 8 for storing each data. Only one external register is used to set the segment current of each LED. Specifications and Features:- Dimensions: 128 x 32 x 1.5cm(LxWxH)(All 4 in 1) Dimension 32 x 32 x 1.5 cm (LxWxH) (Single Module) A single module can drive an 8×8 dot matrix common cathode Operating voltage: 5V Weight: 55 gm Fixing screws with 64 holes with a diameter 3mm Module with input and output interfaces Support for cascading multiple modules Wiring Instructions:- The left side of the module to the input port, the right to an output port. When the control of a single module, simply input port connected to CPU When a plurality of cascaded modules, input and output termination CPU, an input terminal of the second output end of the first module a module, the first two modules of the input terminal of the three termination modules, and so on.. Pin Description:- VCC 5V GND GND DIN P2.2 CS P2.1 CLK P2.0 Installing Libraries To install the library navigate to the Sketch > Include Library > Manage Libraries Wait for Library Manager to download libraries index and update list of installed libraries. And install MAX72xx Libraries. Subscribe and Download code. arduino Code // Connections for ESP8266 hardware SPI are: // Vcc 3v3 LED matrices seem to work at 3.3V // GND GND GND // DIN D7 HSPID or HMOSI // CS or LD D8 HSPICS or HCS // CLK D5 CLK or HCLK #include #include #include #define PRINT_CALLBACK 0 #define DEBUG 0 #define LED_HEARTBEAT 0 #if DEBUG #define PRINT(s, v) { Serial.print(F(s)); Serial.print(v); } #define PRINTS(s) { Serial.print(F(s)); } #else #define PRINT(s, v) #define PRINTS(s) #endif #if LED_HEARTBEAT #define HB_LED D2 #define HB_LED_TIME 500 // in milliseconds #endif // Define the number of devices we have in the chain and the hardware interface // NOTE: These pin numbers will probably not work with your hardware and may // need to be adapted //#define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW #define HARDWARE_TYPE MD_MAX72XX::FC16_HW #define MAX_DEVICES 8 // your connected no of display change it here #define CLK_PIN D5 // or SCK #define DATA_PIN D7 // or MOSI #define CS_PIN D8 // or SS // SPI hardware interface MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, CS_PIN, MAX_DEVICES); // Arbitrary pins //MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); // WiFi login parameters - network name and password const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; // your WIFi Password // WiFi Server object and parameters WiFiServer server(80); // Global message buffers shared by Wifi and Scrolling functions const uint8_t MESG_SIZE = 255; const uint8_t CHAR_SPACING = 1; const uint8_t SCROLL_DELAY = 75; char curMessage[MESG_SIZE]; char newMessage[MESG_SIZE]; bool newMessageAvailable = false; char WebResponse[] = "HTTP/1.1 200 OK\nContent-Type: text/html\n\n"; char WebPage[] = "" \ "" \ "" \ "" \ "" \ "" \ "" \ ""\ "IOT Based Notice Board Using Dot Matrix LED Display" \ "" \ "Type Your Message:" \ "" \ "" \ "" \ ""\ "" \ ""; char *err2Str(wl_status_t code) { switch (code) { case WL_IDLE_STATUS: return("IDLE"); break; // WiFi is in process of changing between statuses case WL_NO_SSID_AVAIL: return("NO_SSID_AVAIL"); break; // case configured SSID cannot be reached case WL_CONNECTED: return("CONNECTED"); break; // successful connection is established case WL_CONNECT_FAILED: return("CONNECT_FAILED"); break; // password is incorrect case WL_DISCONNECTED: return("CONNECT_FAILED"); break; // module is not configured in station mode default: return("??"); } } uint8_t htoi(char c) { c = toupper(c); if ((c >= '0') && (c <= '9')) return(c - '0'); if ((c >= 'A') && (c <= 'F')) return(c - 'A' + 0xa); return(0); } boolean getText(char *szMesg, char *psz, uint8_t len) { boolean isValid = false; // text received flag char *pStart, *pEnd; // pointer to start and end of text // get pointer to the beginning of the text pStart = strstr(szMesg, "/&MSG="); if (pStart != NULL) { pStart += 6; // skip to start of data pEnd = strstr(pStart, "/&"); if (pEnd != NULL) { while (pStart != pEnd) { if ((*pStart == '%') && isdigit(*(pStart+1))) { // replace %xx hex code with the ASCII character char c = 0; pStart++; c += (htoi(*pStart++) << 4); c += htoi(*pStart++); *psz++ = c; } else *psz++ = *pStart++; } *psz = '\0'; // terminate the string isValid = true; } } return(isValid); } void handleWiFi(void) { static enum { S_IDLE, S_WAIT_CONN, S_READ, S_EXTRACT, S_RESPONSE, S_DISCONN } state = S_IDLE; static char szBuf[1024]; static uint16_t idxBuf = 0; static WiFiClient client; static uint32_t timeStart; switch (state) { case S_IDLE: // initialise PRINTS("\nS_IDLE"); idxBuf = 0; state = S_WAIT_CONN; break; case S_WAIT_CONN: // waiting for connection { client = server.available(); if (!client) break; if (!client.connected()) break; #if DEBUG char szTxt[20]; sprintf(szTxt, "%03d:%03d:%03d:%03d", client.remoteIP()[0], client.remoteIP()[1], client.remoteIP()[2], client.remoteIP()[3]); PRINT("\nNew client @ ", szTxt); #endif timeStart = millis(); state = S_READ; } break; case S_READ: // get the first line of data PRINTS("\nS_READ"); while (client.available()) { char c = client.read(); if ((c == '\r') || (c == '\n')) { szBuf[idxBuf] = '\0'; client.flush(); PRINT("\nRecv: ", szBuf); state = S_EXTRACT; } else szBuf[idxBuf++] = (char)c; } if (millis() - timeStart > 1000) { PRINTS("\nWait timeout"); state = S_DISCONN; } break; case S_EXTRACT: // extract data PRINTS("\nS_EXTRACT"); // Extract the string from the message if there is one newMessageAvailable = getText(szBuf, newMessage, MESG_SIZE); PRINT("\nNew Msg: ", newMessage); state = S_RESPONSE; break; case S_RESPONSE: // send the response to the client PRINTS("\nS_RESPONSE"); // Return the response to the client (web page) client.print(WebResponse); client.print(WebPage); state = S_DISCONN; break; case S_DISCONN: // disconnect client PRINTS("\nS_DISCONN"); client.flush(); client.stop(); state = S_IDLE; break; default: state = S_IDLE; } } void scrollDataSink(uint8_t dev, MD_MAX72XX::transformType_t t, uint8_t col) // Callback function for data that is being scrolled off the display { #if PRINT_CALLBACK Serial.print("\n cb "); Serial.print(dev); Serial.print(' '); Serial.print(t); Serial.print(' '); Serial.println(col); #endif } uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t) // Callback function for data that is required for scrolling into the display { static enum { S_IDLE, S_NEXT_CHAR, S_SHOW_CHAR, S_SHOW_SPACE } state = S_IDLE; static char *p; static uint16_t curLen, showLen; static uint8_t cBuf[8]; uint8_t colData = 0; // finite state machine to control what we do on the callback switch (state) { case S_IDLE: // reset the message pointer and check for new message to load PRINTS("\nS_IDLE"); p = curMessage; // reset the pointer to start of message if (newMessageAvailable) // there is a new message waiting { strcpy(curMessage, newMessage); // copy it in newMessageAvailable = false; } state = S_NEXT_CHAR; break; case S_NEXT_CHAR: // Load the next character from the font table PRINTS("\nS_NEXT_CHAR"); if (*p == '\0') state = S_IDLE; else { showLen = mx.getChar(*p++, sizeof(cBuf) / sizeof(cBuf[0]), cBuf); curLen = 0; state = S_SHOW_CHAR; } break; case S_SHOW_CHAR: // display the next part of the character PRINTS("\nS_SHOW_CHAR"); colData = cBuf[curLen++]; if (curLen < showLen) break; // set up the inter character spacing showLen = (*p != '\0' ? CHAR_SPACING : (MAX_DEVICES*COL_SIZE)/2); curLen = 0; state = S_SHOW_SPACE; // fall through case S_SHOW_SPACE: // display inter-character spacing (blank column) PRINT("\nS_ICSPACE: ", curLen); PRINT("/", showLen); curLen++; if (curLen == showLen) state = S_NEXT_CHAR; break; default: state = S_IDLE; } return(colData); } void scrollText(void) { static uint32_t prevTime = 0; // Is it time to scroll the text? if (millis() - prevTime >= SCROLL_DELAY) { mx.transform(MD_MAX72XX::TSL); // scroll along - the callback will load all the data prevTime = millis(); // starting point for next time } } void setup() { #if DEBUG Serial.begin(115200); PRINTS("\n[MD_MAX72XX WiFi Message Display]\nType a message for the scrolling display from your internet browser"); #endif #if LED_HEARTBEAT pinMode(HB_LED, OUTPUT); digitalWrite(HB_LED, LOW); #endif // Display initialisation mx.begin(); mx.setShiftDataInCallback(scrollDataSource); mx.setShiftDataOutCallback(scrollDataSink); curMessage[0] = newMessage[0] = '\0'; // Connect to and initialise WiFi network PRINT("\nConnecting to ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { PRINT("\n", err2Str(WiFi.status())); delay(500); } PRINTS("\nWiFi connected"); // Start the server server.begin(); PRINTS("\nServer started"); // Set up first message as the IP address sprintf(curMessage, "%03d:%03d:%03d:%03d", WiFi.localIP()[0], WiFi.localIP()[1], WiFi.localIP()[2], WiFi.localIP()[3]); PRINT("\nAssigned IP ", curMessage); } void loop() { #if LED_HEARTBEAT static uint32_t timeLast = 0; if (millis() - timeLast >= HB_LED_TIME) { digitalWrite(HB_LED, digitalRead(HB_LED) == LOW ? HIGH : LOW); timeLast = millis(); } #endif handleWiFi(); scrollText(); } Result hen, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now the IP address is Shown in Dot Matrix Display. Click Web Browser and type IP address in the bar. Enter the message and hit Send Message button.

  • IoT Based Motion Detector

    In this tutorial. To learn how to interface PIR(Passive infrared) motion/intrusion detection sensor with nodemcu WiFi module, Buzzer alarm. PIR motion sensor will instantly detect the presence of it and rings a buzzer alarm to notify you about an intrusion. The project can be taken as a small security system and could be installed in garage, garden(to check the presence of wild animals dogs, cats, pigs, birds etc), house, pet house, shops and stores. Live body emits heat waves and heat waves contains infrared rations. The more the body emitting heat the more the infrared radiations. Generally the living bodies emit more heat than the raw materials. So pir sensor can be used to detect the motion of living bodies. Circuit Diagram Components Required NodeMCU ESP8266 12E Motion Sensor HC-SR501 (PIR Sensor) LCD 16x2 with I2C Module Buzzer Jumper Wires 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 The 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.Active Passive Buzzer Active Passive Buzzer Positive: Identified by (+) symbol or longer terminal lead. Can be Connected to NodeMCU pin D4. Negative: Identified by short terminal lead. Typically connected to the ground of the circuit. Buzzer Features and Specifications Rated Voltage: 6V DC Operating Voltage: 4-8V DC Rated current: <30mA Sound Type: Continuous Beep Resonant Frequency: ~2300 Hz Small and neat sealed package Breadboard and Perf board friendly LCD 16x2 (I2C module) This is a 16x2 LCD display screen with I2C interface. It is able to display 16x2 characters on 2 lines, white characters on blue background. This I2C 16x2 Arduino LCD Screen is using an I2C communication interface. It means it only needs 4 pins for the LCD display: VCC, GND, SDA, SCL. Connecting the LCD to NodeMCU Connect the VCC I2C pin to a Vin pin on the NodeMCU. Connect the GND I2C pin to a GND pin on the NodeMCU. Connect the SCL I2C pin to a D1 pin on the NodeMCU. Connect the SDA I2C pin to a D2 pin on the NodeMCU. Open 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 #include #include const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; //your WIFI Password #include LiquidCrystal_I2C lcd(0x27,16,2); ESP8266WebServer server(80); //Server on port 80 int buzzer = 2; //Buzzer alarm connected to GPIO-14 or D5 of nodemcu int PIRsensor = 16; //PIR sensor output connected to GPIO-5 or D1 of nodemcu String Message; const char MAIN_page[] PROGMEM = R"=====( Iot Based Motion Detector Real Time Data Logger TimeActivity )====="; void handleRoot() { String s = MAIN_page; //Read HTML contents server.send(200, "text/html", s); //Send web page } void readData() { lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); int state = digitalRead(PIRsensor); //Continuously check the state of PIR sensor delay(500); //Check state of PIR after every half second lcd.setCursor(0,0); lcd.print("PIR Scanning >>>"); lcd.setCursor(0,1); lcd.print("No Activity :) "); Serial.print(state); if(state == HIGH){ digitalWrite (buzzer, HIGH); //If intrusion detected ring the buzzer lcd.setCursor(0,1); lcd.print("Motion Detected!"); delay(1000); digitalWrite (buzzer, LOW); lcd.setCursor(0,1); lcd.print("Wait Reading..."); delay(1000); Message = "Motion Detected"; String data = "{\"Activity\":\""+ String(Message) +"\"}"; server.send(200, "text/plane", data); //Send ADC value, temperature and humidity JSON to client ajax request Serial.println("Motion detected!"); } } void setup() { Serial.begin(9600); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); Serial.print("Connecting to Wifi Network"); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("Successfully connected to WiFi."); Serial.println("IP address is : "); Serial.println(WiFi.localIP()); server.on("/", handleRoot); //Which routine to handle at root location. This is display page server.on("/readData", readData); //This page is called by java Script AJAX server.begin(); //Start server Serial.println("HTTP server started"); pinMode(PIRsensor, INPUT); // PIR sensor as input pinMode(buzzer, OUTPUT); // Buzzer alaram as output digitalWrite (buzzer, LOW);// Initially buzzer off } void loop(){ server.handleClient(); //Handle client requests } Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address. After That Open web address and Type IP address in address bar and get result.

  • IoT Controlled Wireless Notice Board

    In this Tutorial to Lean how to control a IoT Based Web Controlled Wireless Notice Board using NodeMCU ESP8266 & 16×2 LCD Display. Here We have created a local web server for demonstration, and for displaying the notice we have used 16×2 LCD. The LCD display is connected to a server system should continuously listen for the incoming notices from the user, process it and display it on the LCD screen. The message displayed should be updated each time the user sends new information. Generally, In shops, hotels, offices, railway stations, notice/ display boards are used. They are frequently used to display messages, notices, or for advertisement purposes. However, it is a tedious task to change it every day. So, here is the Smart Display Board. This project aims to develop a wireless display board that displays messages sent via Local Webpage through WIFI network. The main objective of the project is to develop a wireless notice board which displays messages sent from the webserver. Whenever a user sends a message, it is received by a wifi Module through Local Web Server. Components Required NodeMCU ESP8266 12E Board 16X2 LCD with I2c Module Jumper Wires Circuit Diagram Node MCU 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 D1 & D2 of NodeMCU is Connected to SCL & SDA Pin of LCD. LCD LCD modules are very commonly used in most embedded projects, the reason being its cheap price, availability and programmer friendly. Most of us would have come across these displays in our day to day life, either at PCO’s or calculators. The appearance and the pinouts have already been visualized above now let us get a bit technical. 16×2 LCD is named so because; it has 16 Columns and 2 Rows. There are a lot of combinations available like, 8×1, 8×2, 10×2, 16×1, etc. but the most used one is the 16×2 LCD. So, it will have (16×2=32) 32 characters in total and each character will be made of 5×8 Pixel Dots. I2C Module I2C Module has a inbuilt PCF8574 I2C chip that converts I2C serial data to parallel data for the LCD display. These modules are currently supplied with a default I2C address of either 0x27 or 0x3F. To determine which version you have check the black I2C adaptor board on the underside of the module. If there a 3 sets of pads labelled A0, A1, & A2 then the default address will be 0x3F. If there are no pads the default address will be 0x27. The module has a contrast adjustment pot on the underside of the display. This may require adjusting for the screen to display text correctly. Features:- Operating Voltage: 5V Backlight and Contrast is adjusted by potentiometer Serial I2C control of LCD display using PCF8574 Come with 2 IIC interface, which can be connected by Dupont Line or IIC dedicated cable Compatible for 16x2 LCD This is another great IIC/I2C/TWI/SPI Serial Interface With this I2C interface module, you will be able to realize data display via only 2 wires. Installing Library We need two libraries to make the local web server. Download these libraries from the given links ESPAsyncTCP Download ESPAsycnWebServer Download After downloading the .zip files, add the libraries in Arduino IDE by clicking on To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Subscribe and Download code. Arduino Code #include #include #include #include LiquidCrystal_I2C lcd(0x27,16,2); AsyncWebServer server(80); //replace ssid and password with your wifi network credentials const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; //your WIFI Password const char* PARAM_INPUT_1 = "input1"; const char index_html[] PROGMEM = R"=====( IoT Wireless Smart Notice Board Enter Text to Display: )====="; void notFound(AsyncWebServerRequest *request) { request->send(404, "text/plain", "Not found"); } void setup() { Serial.begin(115200); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Wireless Notice board"); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); if (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("WiFi Failed!"); return; } Serial.println(); Serial.print("IP Address: "); Serial.println(WiFi.localIP()); server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){ request->send_P(200, "text/html", index_html); }); server.on("/get", HTTP_GET, [] (AsyncWebServerRequest *request) { String message; String inputParam; if (request->hasParam(PARAM_INPUT_1)) { message = request->getParam(PARAM_INPUT_1)->value(); inputParam = PARAM_INPUT_1; // lcd.clear(); lcd.setCursor(0,1); lcd.print(message); } else { message = "No message sent"; inputParam = "none"; } Serial.println(message); request->send(200, "text/html", index_html); }); server.onNotFound(notFound); server.begin(); } void loop() { for (int positionCounter = 0; positionCounter < 29; positionCounter++) { lcd.scrollDisplayLeft(); delay(500); } } Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board. Open IP address, enter the message and hit Send button. You will see the message in serial monitor as well as on the LCD. So this is how this IOT based Digital Notice Board works, and now you can change the message on notice board from Local webpage.

  • Iot Cloud BH1750 LUX Monitor

    Here to make an IoT ESP8266 Based Lux Monitor or Light Gauge using BH1750 Ambient Light Sensor & Gauge Widget it an Ubidots delivered end-to-end IoT solutions. We can monitor the Light intensity of a particular location from anywhere in the world. For that, we need to use some hardware like NodeMCU ESP8266 & BH1750 Ambient Light Sensor Module, IoT cloud platform. BH1750 Ambient Light Sensor BH1750 is a digital ambient light sensor that is used commonly used in mobile phones to manipulate the screen brightness based on the environment lighting. This sensor can accurately measure the LUX value of light up to 65535lx. BH1750 Features Power Supply: 2.4V-3.6V (typically 3.0V) Less current consumption: 0.12mA Measuring Rang: 1-65535lx Communication: I2C bus Accuracy: +/-20% Built in A/D converter for converting analog illuminance in the digital data. Very small effect of IR radiation Highly responsive near to human eye. The BH1750 is a light intensity sensor that can be used to adjust the brightness of display in mobiles and LCD displays. It can also be used to turn the headlights of cars on/off based on the outdoor lighting. The sensor uses I2C communication protocol so that makes it super easy to use with microcontrollers. The SCL and SDA pins are for I2C. There is no calculation needed to measure the LUX value because the sensor directly gives the lux value. Actually, it measures the intensity according to the amount of light hitting on it. It operates on voltage range of 2.4V-3.6V and consumes really small current of 0.12mA. The results of the sensor does not depends upon the light source used and the influence of IR radiation is very less. There are very less chances of any error because the variation in measurement is as low as +/-20%. Hardware of the BH1750 is very simple. The main component is BH1750FVI IC. The module works on 3.3V so a voltage regulator is used. For I2C lines a pull up resistor of 4.7K is used. We get the lux values from BH1750 through I2C bus. The ADC in the IC converts the analog illuminance to the digital lux value. Now this data is transferred to microcontroller with the help of I2C pins SCL and SDA. The SCL is used to provide the clock pulse and the SDA is used to transfer the lux value. The IC uses a photodiode which gives the response equivalent to the human eye. There is also an internal oscillator in the IC which is used for the clock of internal logic of the IC. Applications Manipulate brightness in mobile phones/LCD Automobile Headlights on/off control based on surrounding lighting conditions. Used as Ambient light sensors to control the brightness of Display screens. BH1750 NodeMCU ESP8266 Circuit Diagram Now, let us interface the BH1750 Ambient Light Sensor with NodeMCU ESP8266 Board. The connection is fairly simple. Connect the I2C Pin of BH1750, i.e. SDA & SCL to D1 & D2 of NodeMCU Board Respectively. Connect the 3.3V pin of BH1750 to NodeMCU 3.3V pin & GND to GND. The circuit can be easily assembled on a breadboard. Installing Libraries Download: BH1750 Library Download : ubidots-nodemcu-master To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Subscribe and Download code. arduino Code #include "UbidotsMicroESP8266.h" #define TOKEN "BBFF-HYfUHivZQVJKjxO12FkQ6X7SWDpdiy" // Put here your Ubidots TOKEN #define WIFISSID "TP-Link_3200" // your SSID #define PASSWORD "9500112137" // your wifi password Ubidots client(TOKEN); //unsigned long lastMillis = 0; #include // I2C Arduino library #include // BH1750FVI Light sensor library BH1750FVI LightSensor; int lux; void setup() { Serial.begin(9600); LightSensor.begin(); LightSensor.setMode(Continuously_High_Resolution_Mode); // see datasheet page 5 for modes Serial.println("Light sensor BH1750FVI found and running"); client.wifiConnection(WIFISSID, PASSWORD); } void loop() { lux = LightSensor.getAmbientLight(); Serial.print("Ambient light intensity: "); Serial.print(lux); Serial.println(" lux"); delay(2000); client.add("sweetHome", lux); client.sendAll(true); } Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the ESP8266 board. UBIDOTS IoT Platform Setup I created an account on the Ubidots IoT platform. Before setting up the Ubidots IOT platform first, I uploaded both the programs in the Nodemcu modules and turned on the circuit boards. This step is really important, because when we first power up the Nodemcu modules it sends the variables to the Ubidots IoT platform which can be then used. We can display the values on the charts and assign some conditions. Creating a free Ubidots account and sign in. After filling the forms and completing other requirements, finally, registered on the Ubidots IoT Platform.As I created a new account so there are no events, no Dashboards, and no devices. Follow the Demo video, Currently, you can see the value in LUX Gauge widget in dash board. See Connected device, You can see variables, as have connected ESP8266. Currently, you can see the graphical representation value. That’s pretty much how the code works.

  • KY-039 Finger Heart beat detector

    In this project I describe how this signal is converted into a heartbeat rate like BPM (beats per minute). KY-039 This KY-039 Finger Detection Heartbeat Measuring Sensor Module uses bright infrared (IR) LED and a phototransistor to detect the pulse of the finger, a red LED flashes with each pulse. The LED is the light side of the finger, and the phototransistor on the other side of the finger, phototransistor used to obtain the flux emitted, when the blood pressure pulse by the finger when the resistance of the phototransistor will be slightly changed. We chose a very high resistance resistor R1 because most of the light through the finger is absorbed, it is desirable that the phototransistor is sensitive enough. Resistance can be selected by experiment to get the best results. The most important is to keep the shield stray light into the phototransistor. For home lighting that is particularly important because the lights at home mostly based 50HZ or 60HZ fluctuate, so faint heartbeat will add considerable noise. Features : Use IR LED and an optical transistor to detect pulsation in fingers Small and Compact module Easy to use. Connection Sensor pin S connect to Arduino pin Analoog 0 / A0 Sensor pin + (middle pin) connect to Arduino pin 5+ Sensor pin - connect to Arduino pin GND Subscribe and Download code. Arduino Test Code int sensorPin = 0; void setup() { Serial.begin(9600); } void loop () { while(1) { Serial.print(analogRead(sensorPin)); Serial.print('\n'); } } After Uploading to arduino Uno, Open Serial plotter and see the result. when placing finger in the sensor module, and you get something like this: Subscribe and Download code. Smoothing Final Code: #define samp_siz 4 #define rise_threshold 5 // Pulse Monitor Test Script int sensorPin = 0; void setup() { Serial.begin(9600); } void loop () { float reads[samp_siz], sum; long int now, ptr; float last, reader, start; float first, second, third, before, print_value; bool rising; int rise_count; int n; long int last_beat; for (int i = 0; i < samp_siz; i++) reads[i] = 0; sum = 0; ptr = 0; while(1) { // calculate an average of the sensor // during a 20 ms period (this will eliminate // the 50 Hz noise caused by electric light n = 0; start = millis(); reader = 0.; do { reader += analogRead (sensorPin); n++; now = millis(); } while (now < start + 20); reader /= n; // we got an average // Add the newest measurement to an array // and subtract the oldest measurement from the array // to maintain a sum of last measurements sum -= reads[ptr]; sum += reader; reads[ptr] = reader; last = sum / samp_siz; // now last holds the average of the values in the array // check for a rising curve (= a heart beat) if (last > before) { rise_count++; if (!rising && rise_count > rise_threshold) { // Ok, we have detected a rising curve, which implies a heartbeat. // Record the time since last beat, keep track of the two previous // times (first, second, third) to get a weighed average. // The rising flag prevents us from detecting the same rise // more than once. rising = true; first = millis() - last_beat; last_beat = millis(); // Calculate the weighed average of heartbeat rate // according to the three last beats print_value = 60000. / (0.4 * first + 0.3 * second + 0.3 * third); Serial.print(print_value); Serial.print('\n'); third = second; second = first; } } else { // Ok, the curve is falling rising = false; rise_count = 0; } before = last; ptr++; ptr %= samp_siz; } } To get a smoother output , take an average of say 20 last readings from the sensor. With an array size of 20 and a baud rate of 9600 in the serial monitor, I might get a plotting like this:

  • IoT Smart Irrigation Monitoring and Control System

    The Smart irrigation System has wide scope to automate the complete irrigation system. Here we are building a IoT based Irrigation System using ESP8266 NodeMCU Module and DHT11 Sensor. It will not only automatically irrigate the water based on the moisture level in the soil but also send the Data to ThingSpeak Server to keep track of the land condition. The System will consist a water pump which will be used to sprinkle water on the land depending upon the land environmental condition such as Moisture, Temperature and Humidity. Before starting, it is important to note that the different crops require different Soil Moisture, Temperature and Humidity Condition. So in this tutorial we are using such a crop which will require a soil moisture of about 50-55%. So when the soil loses its moisture to less than 50% then Motor pump will turn on automatically to sprinkle the water and it will continue to sprinkle the water until the moisture goes upto 55% and after that the pump will be turned off. The sensor data will be sent to ThingSpeak Server in defined interval of time so that it can be monitored from anywhere in the world. Components Required NodeMCU ESP8266 Soil Moisture Sensor Module Water Pump Module Relay Module DHT11 LCD20X4 Connecting Wires Circuit Diagram DHT11 The DHT11 is a commonly used Temperature and humidity sensor. The sensor comes with a dedicated NTC to measure temperature and an 8-bit microcontroller to output the values of temperature and humidity as serial data. The sensor is also factory calibrated and hence easy to interface with other microcontrollers. The sensor can measure temperature from 0°C to 50°C and humidity from 20% to 90% with an accuracy of ±1°C and ±1%. So if you are looking to measure in this range then this sensor might be the right choice for you. Specifications Operating Voltage: 3.5V to 5.5V Operating current: 0.3mA (measuring) 60uA (standby) Output: Serial data Temperature Range: 0°C to 50°C Humidity Range: 20% to 90% Resolution: Temperature and Humidity both are 16-bit Accuracy: ±1°C and ±1% Pump Motor Micro DC 3-6V Micro Submersible Pump Mini water pump For Fountain Garden Mini water circulation System DIY project. This is a low cost, small size Submersible Pump Motor which can be operated from a 3 ~ 6V power supply. It can take up to 120 liters per hour with very low current consumption of 220mA. Just connect tube pipe to the motor outlet, submerge it in water and power it. Make sure that the water level is always higher than the motor. Dry run may damage the motor due to heating and it will also produce noise. Specifications Operating Voltage : 3 ~ 6V Operating Current : 130 ~ 220mA Flow Rate : 80 ~ 120 L/H Maximum Lift : 40 ~ 110 mm Continuous Working Life : 500 hours Driving Mode : DC, Magnetic Driving Material : Engineering Plastic Outlet Outside Diameter : 7.5 mm Outlet Inside Diameter : 5 mm Relay This 1-channel 5V control Single-Pole Double-Throw (SPDT) High-level trigger AC power relay board can be controlled directly via a microcontroller and switch up to 10A at 250 VAC. The inputs of 1 Channel 5V Relay Module are isolated to protect any delicate control circuitry. Specifications Trigger Voltage: 5 VDC Trigger Current : 20 mA Maximum Switching Voltage: 250VAC@10A; 30VDC @10A Single Pole Double Throw (SPDT) Configuration Power supply indicator lamp Soil Moisture This soil moisture sensor module is used to detect the moisture of the soil. It measures the volumetric content of water inside the soil and gives us the moisture level as output. The module has both digital and analog outputs and a potentiometer to adjust the threshold level. Moisture Sensor Module Features & Specifications Operating Voltage: 3.3V to 5V DC Operating Current: 15mA Output Digital - 0V to 5V, Adjustable trigger level from preset Output Analog - 0V to 5V based on infrared radiation from fire flame falling on the sensor LEDs indicating output and power PCB Size: 3.2cm x 1.4cm LM393 based design Easy to use with Microcontrollers or even with normal Digital/Analog IC Small, cheap and easily available 20x4 LCD A 20x4 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. A 20x4 LCD means it can display 20 characters per line and there are 4 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. This is standard HD44780 controller LCD. There is no change code for interfacing standard 16x2 or 20x4 LCD. 20 Characters x 4 Lines Built-in HD44780 Equivalent LCD Controller Works directly with ATMEGA, ARDUINO, PIC amd many other microcontroller/kits. 4 or 8 bit data I/O interface Low power consumption Installing DHT Sensor Library To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Dht11: you need to Download and install the DHT11 library. LCD: Download Subscribe and Download code. ESP8266 Code #include #include String apiKey = "WH8PYV2IJPA4BVRT"; // Enter your Write API key here const char* server = "api.thingspeak.com"; const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; //your WIFI Password #include LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display #define DHTPIN D3 // GPIO Pin where the dht11 is connected DHT dht(DHTPIN, DHT11); WiFiClient client; const int moisturePin = A0; // moisteure sensor pin const int motorPin = D0; unsigned long interval = 10000; unsigned long previousMillis = 0; unsigned long interval1 = 1000; unsigned long previousMillis1 = 0; float moisturePercentage; //moisture reading float H; // humidity reading float T; //temperature reading void setup() { Serial.begin(115200); delay(10); lcd.init(); // initialize the lcd // Print a message to the LCD. lcd.backlight(); pinMode(motorPin, OUTPUT); digitalWrite(motorPin, HIGH); // keep motor off initally dht.begin(); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); // print ... till not connected } Serial.println(""); Serial.println("WiFi connected"); } void loop() { // Serial.print(digitalRead(motorPin)); unsigned long currentMillis = millis(); // grab current time H = dht.readHumidity(); // read humiduty T = dht.readTemperature(); // read temperature if (isnan(H) || isnan(T)) { Serial.println("Failed to read from DHT sensor!"); return; } moisturePercentage = ( 100.00 - ( (analogRead(moisturePin) / 1023.00) * 100.00 ) ); if ((unsigned long)(currentMillis - previousMillis1) >= interval1) { Serial.print("Soil Moisture is = "); Serial.print(moisturePercentage); Serial.println("%"); previousMillis1 = millis(); } if (moisturePercentage < 50) { digitalWrite(motorPin, LOW); // tun on motor lcd.setCursor(0,3); lcd.print("Pump Status: Running"); } if (moisturePercentage > 50 && moisturePercentage < 59) { digitalWrite(motorPin, LOW); //turn on motor pump lcd.setCursor(0,3); lcd.print("Pump Status: Running"); } if (moisturePercentage > 60) { digitalWrite(motorPin, HIGH); // turn off mottor lcd.setCursor(0,3); lcd.print("Pump Status: OFF "); } if ((unsigned long)(currentMillis - previousMillis) >= interval) { sendThingspeak(); //send data to thing speak previousMillis = millis(); client.stop(); } lcd.setCursor(0,0); lcd.print("Moisture % :"); lcd.setCursor(13,0); lcd.print(moisturePercentage); lcd.setCursor(0,1); lcd.print("Temp"); lcd.setCursor(8,1); lcd.print((char)223); lcd.setCursor(9,1); lcd.print("C :"); lcd.setCursor(13,1); lcd.print(T); lcd.setCursor(0,2); lcd.print("Humidity % :"); lcd.setCursor(13,2); lcd.print(H); delay(1000); } void sendThingspeak() { if (client.connect(server, 80)) { String postStr = apiKey; // add api key in the postStr string postStr += "&field1="; postStr += String(moisturePercentage); // add mositure readin postStr += "&field2="; postStr += String(T); // add tempr readin postStr += "&field3="; postStr += String(H); // add humidity readin postStr += String(T); // add tempr readin postStr += "&field4="; postStr += String(digitalRead(motorPin)); // add humidity readin postStr += "\r\n\r\n"; client.print("POST /update HTTP/1.1\n"); client.print("Host: api.thingspeak.com\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); //send lenght of the string client.print("\n\n"); client.print(postStr); // send complete string Serial.print("Moisture Percentage: "); Serial.print(moisturePercentage); Serial.print("%. Temperature: "); Serial.print(T); Serial.print(" C, Humidity: "); Serial.print(H); Serial.println("%. Sent to Thingspeak."); } } Finally the data is sent to ThingSpeak server using client.print() function which contains API key, server address and the string which is prepared in previous step. Finally this is how the data looks on ThingSpeak Dashboard

  • IoT Analog Dial Gauge

    In this tutorial to Learn and uses of JavaScripts, CSS and HTML. Here we are using LDR reading analog value of ADC and display it on HTML web page, which is served by ESP8266 Web server. And also SPIFFS lets you access the flash chip memory like you would do in a normal filesystem in your computer, but simpler and more limited. You can read, write, close, and delete files. SPIFFS doesn’t support directories, so everything is saved on a flat structure. Using SPIFFS with the ESP8266 board is specially useful to: Create configuration files with settings; Save data permanently; Create files to save small amounts of data instead of using a microSD card; Save HTML and CSS files,JavaScripts to build a web server; Save images, figures and icons; And much more. In most of our web server projects, we’ve written the HTML code for the web server as a String directly on the Arduino sketch. With SPIFFS, you can write the HTML and CSS in separated files and save them on the ESP8266 filesystem. refer previous tutorial about SPIFFS. https://www.dofbot.com/post/esp8266-spiffs-uploader ESP8266 have only one adc channel. Lets begin to read analog and make something cool. Circuit Diagram Component Required Node MCU ESP826612E LDR Resister - 10K 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, Analog pin A0 of NodeMCU is used to read Voltage in Between LDR and Series Resister. LDR Light dependent resistors, LDRs, or a photoresistor is a passive component that decreases resistance with respect to receiving luminosity on the component's sensitive surface. The resistance of a photoresistor decreases with increase in incident light intensity; in other words, it exhibits photoconductivity. https://www.dofbot.com/post/cayenne-based-iot-light-control-using-ldr 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. To do this create a folder named as “data” in your sketch folder i.e. where you saved your above .ino file. Then Download and unzip these files ESP8266-analog-gauge-data. Folder structure is your .ino file with data folder. In data folder you have these files index.html, style.css, jQuery.min.js, d3-gauge.js. Subscribe and Download code. Arduino code #include #include #include //Include File System Headers const char* htmlfile = "/index.html"; const char* ssid = "TP-Link_3200"; // your SSID const char* password = "9500112137"; //Your WIFi Password ESP8266WebServer server(80); void handleADC(){ int a = analogRead(A0); a = map(a,0,1023,0,100); String adc = String(a); Serial.println(adc); server.send(200, "text/plane",adc); } void handleRoot(){ server.sendHeader("Location", "/index.html",true); //Redirect to our html web page server.send(302, "text/plane",""); } void handleWebRequests(){ if(loadFromSpiffs(server.uri())) return; String message = "File Not Detected\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i=0; i

  • IoT Weather Station BMP180

    In this project, To interface BMP180 Barometric Pressure Sensor with NodeMCU ESP8266 12E. This sensor are fairly simple to use, pre-calibrated and don’t require extra components so you can start measuring temperature, pressure & altitude. Circuit Diagram Component required 1. NodeMCU ESP8266-12E Board 2. BMP 180 BMP180 Chip BMP180 can measure barometric pressure from 300 to 1100 hPa (9000m to -500m above sea level), and temperature from -40°C to 85°C with ±1.0°C accuracy.The pressure measurements are so precise (low altitude noise of 0.25m), you can even use it as an altimeter with ±1 meter accuracy. VCC is connected to the 3.3V of Node MCU. GND is connected to the ground of Node MCU. SCL is D1 of Node MCU. SDA is D2 of Node MCU. BMP180 MODULE Features Can measure temperature and altitude. Pressure range: 300 to 1100hPa High relative accuracy of ±0.12hPa Can work on low voltages 3.4Mhz I2C interface Low power consumption (3uA) Pressure conversion time: 5msec Potable size BMP180 MODULE Specifications Operating voltage of BMP180: 1.3V – 3.6V Input voltage of BMP180MODULE: 3.3V to 5.5V Peak current : 1000uA Consumes 0.1uA standby Maximum voltage at SDA , SCL : VCC + 0.3V Operating temperature: -40ºC to +80ºC Installing Libraries BMP180 Download Calculating the altitude and barometric pressure with BMP180 module needs to install Library so that we can use simple commands to read the temperature, barometric pressure and altitude data. Adafruit Bus IO Library This is a helper libary to abstract away I2C & SPI transactions and registers To install the library navigate to the Sketch > Include Library > Manage Libraries… Wait for Library Manager to download libraries index and update list of installed libraries. Subscribe and Download code. arduino Code #include #include #include #include Adafruit_BMP085 bmp; float temperature,pressure,pressuresealevel,altitude,altitudereal; const char* ssid = "TP-Link_3200"; // YOUR ssiD const char* password = "9500112137"; //?YOUR WIFI PASSWORD ESP8266WebServer server(80); void setup() { Serial.begin(9600); if (!bmp.begin()) { Serial.println("Could not find a valid BMP085 sensor, check wiring!"); while (1) {} } Serial.println("Connecting to "); Serial.println(ssid); //Connect to your local wi-fi network WiFi.begin(ssid, password); //check wi-fi is connected to wi-fi network while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected..!"); Serial.print("Got IP: "); Serial.println(WiFi.localIP()); server.on("/", handle_OnConnect); server.onNotFound(handle_NotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); } void handle_OnConnect() { temperature = bmp.readTemperature(); pressure = bmp.readPressure(); altitude = bmp.readAltitude(); pressuresealevel = bmp.readSealevelPressure(); altitudereal = bmp.readAltitude(); server.send(200, "text/html", SendHTML(temperature,pressure,pressuresealevel,altitude,altitudereal)); } void handle_NotFound(){ server.send(404, "text/plain", "Not found"); } String SendHTML(float temperature,float pressure,float pressuresealevel,float altitude, float altitudereal){ String ptr = ""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +="BMP180 Weather Station"; ptr +="ESP8266 Web Server"; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +="Temperature"; ptr +=""; ptr +=(int)temperature; ptr +="°C"; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +="Pressure"; ptr +=""; ptr +=(int)pressure; ptr +="hPa"; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +="Pressure Sea Level"; ptr +=""; ptr +=(int)pressuresealevel; ptr +="hPa"; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +="Altitude"; ptr +=""; ptr +=(int)altitude; ptr +="m"; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +=""; ptr +="Altitude Real"; ptr +=""; ptr +=(int)altitudereal; ptr +="m"; ptr +=""; ptr +=""; ptr +=""; ptr +=""; return ptr; } Then, upload the code to your NodeMCU board. Make sure you have selected the right board and COM port. Also, make sure you’ve inserted your WiFi Credentials in the code. After a successful upload, open the Serial Monitor at a baud rate of 115200. Press the “EN/RST” button on the ESP8266 board. Now it should print its IP address.

  • IoT Flood Monitoring and Email, SMS alert System

    Here to learn how to build an IoT Based Flood Monitoring and Email, SMS alert System using Ultrasonic, NodeMCU ESP8266 12E, myDevices Cayenne. In more detail, this IoT tutorial discovers how to use an ESP8266 to send data to Cayenne using the MQTT protocol. Abstract: Flood is one of the natural disasters that cannot be avoided. It happens too fast and affected so many lives and properties. Before this, most of the existing system that has been developed are only focus on certain areas. Other than that, majority of the public cannot monitor and have no idea when the flood going to be happened since they do not have any information and data about the weather condition. This system is suitable for cities and village areas. Furthermore, if the public has an internet access, they can monitor what is happening and predict if there is any upcoming flood at the web server. This project will update the water level at the web server and the system will issue an alert signal to the citizens for evacuation so that fast necessary actions can be taken. 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 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 catalogue 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. Circuit Diagram Components Required ESP8266 NodeMCU Ultrasonic Sensor LEDs (Red & Green) Breadboard Jumpers 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 D1 of NodeMCU is used to read Data of Dht11 temperature sensor. Ultrasonic: The HC-SR04 ultrasonic module is a module that can provide non-contact measurement within the range of 2cm to 400cm with ranging accuracy that can reach 3mm. It works on the principle of echolocation. The ultrasonic sensor as a trigger and an echo pin. The arduino provides a high signal of 10microseconds to this pin. After the HC-SR04 is triggered, it sends out eight 40Khz sound waves to the surface of the water. On getting to the surface of the water, the wave is echoed back to the sensor and the ESP8266 reads the echo pin to determine time spent between triggering and receiving of the echo. Since we know that the speed of sound is around 340m/s then we can calculate the distance using; Distance = (time/2)*speed of sound Ultrasonic HC-SR04 wiring to ESP8266 Ultrasonic HC-SR04 ESP8266 Vcc Pin Vin Pin Trig Pin D1 (GPIO 5) Echo Pin D2 (GPIO 4) GND Pin GND Installing the ESP8266_Arduino_Library To get readings from the Ultrasonic HC-SR04 sensor module you need to have the next library installed: Download Ultrasonic 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 #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include Ultrasonic ultrasonic(D1, D2); const int AlertLED = D3; #define NormalLED D4 int distance; int val = 0; #include char ssid[] = "TP-Link_3200"; // your SSID char password[]="9500112137"; // your WIFi password char username[] = "2031dd30-5414-11eb-b767-3f1a8f1211ba"; char mqtt_password[] = "f2ce829d98df3a768328ac6936eae9fd47d28289"; char client_id[] = "b15f5e30-5ba9-11eb-b767-3f1a8f1211ba"; void setup() { Serial.begin(9600); Serial.print("Setup"); Cayenne.begin(username,mqtt_password,client_id,ssid,password); pinMode(NormalLED, OUTPUT); pinMode(AlertLED, OUTPUT); digitalWrite(NormalLED, LOW); digitalWrite(AlertLED, LOW); } void loop() { //Run Cayenne Functions Cayenne.loop(); } CAYENNE_OUT(V0){ do { distance = ultrasonic.read(); delay(2000); } while (isnan(distance)); Serial.print("Distance in CM: "); Serial.println(distance); if (distance <= 3) { digitalWrite(D3, HIGH); digitalWrite(D4, LOW); } else { digitalWrite(D4, HIGH); digitalWrite(D3, LOW); } Cayenne.virtualWrite(V0, distance); } CAYENNE_OUT(V1){ Serial.print(digitalRead(D3)); Cayenne.virtualWrite(V1, digitalRead(D3)); } Result: Water drop in bowl raises, the flood alert RED LED to glow and Normal flood condition Green LED OFF. Hardware interfacing with Cayenne IoT platform To interface the circuit with the IoT platform, open this link on any browser. Refer previous tutorial for more deatil about cayenne https://www.dofbot.com/post/cayenne-iot-based-weather-monitor Click on Sign Up. Fill all the fields and click on Get Started 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. Distance and digital output LED state data on Cayenne. You can get a graphical representation of flood monitor data by clicking on the Graph icon. You can set Trigger alert using if and then condition, and add Mobile number and email for receiving alert message. You can set Trigger alert ON/OFF If Once sensor data gets Reached to Threshold then digital output LED state data to Cayenne. then Flood alert notify value changed to 1.00. You can get a graphical representation of flood Alert data by clicking on the Graph icon. And also Trigger send alert message to Email. And Trigger send alert message to Mobile.

  • IoT Based Home Automation using MQTT

    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 #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 refer detail: https://www.dofbot.com/post/cayenne-iot-based-weather-monitor 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

bottom of page