Back to Course

Internet of Things

0% Complete
0/0 Steps
  1. Lesson-1-> Introduction to IOT
    4 Topics
    |
    1 Quiz
  2. Lesson-2-> Introduction to Node MCU & Arduino IDE
    6 Topics
    |
    1 Quiz
  3. Activity-1-> LED blink using Node MCU & Arduino IDE
    4 Topics
    |
    1 Quiz
  4. Activity-2-> Controlling of LED using Web Server
    5 Topics
    |
    1 Quiz
  5. Activity-3-> Interfacing of Ultrasonic sensor with Node MCU
    4 Topics
    |
    1 Quiz
  6. Activity-4-> LED ON/OFF using Google Assistance
    8 Topics
    |
    1 Quiz
  7. Chapter-3->Introduction to ThingSpeak
    4 Topics
  8. Activity-5 –> Air quality Monitoring using NODE MCU
    6 Topics
    |
    1 Quiz
  9. Activity-6 –> IOT based car parking system
    6 Topics
    |
    1 Quiz
  10. Activity-7 –> IOT based motion detector using Node MCU
    6 Topics
    |
    1 Quiz
  11. Activity-8-> IOT based Automatic gardening System
    5 Topics
    |
    1 Quiz
Lesson 10, Topic 5
In Progress

7.5 Code

22/09/2021
Lesson Progress
0% Complete

 


Steps to do coding in Arduino IDE

1. Open Arduino IDE.

2. For writing this code, we have to add blynk library.

How to add a library:

  1. Download the blynk library from the github or you can use https://github.com/blynkkk/blynk-library this link.
  2. Now,Go to Sketch in the menu bar of Arduino IDE,then to Include library< Add Zip library.
  3. Next, select the blynk library you downloaded from the above link and after this your library will be added.

Note: If it is showing error in adding  the library,then first extract the folder and then add the library.

Complete Code:


#include <ESP8266WiFi.h>

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <BlynkSimpleEsp8266.h>
char auth[] = “YOUR AUTH CODE HERE”;

/* WiFi credentials */
char ssid[] = “YOUR SSID”;
char pass[] = “YOUR PASSWORD”;

/* Motion Detector */
#define ledPin D1
#define pirPin D5 // Input for HC-S501
int pirValue; // Place to store read PIR Value

void setup()
{
Serial.begin(115200);
delay(10);
Blynk.begin(auth, ssid, pass);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
digitalWrite(ledPin, LOW);
}

void loop()
{
getPirValue();
Blynk.run();
}

/***************************************************
* Get PIR data
**************************************************/
void getPirValue(void)
{
pirValue = digitalRead(pirPin);
if (pirValue)
{
Serial.println(“==> Motion detected”);
Blynk.notify(“T==> Motion detected”);
}
digitalWrite(ledPin, pirValue);
}