Sunteți pe pagina 1din 64

INDIAN INSTITUTE OF TECHNOLOGY ROORKEE

Simple Led Control


with

Blynk App
and

NodeMCU Esp8266
Experiment Brief

We want to

Switch On and Off

an LED or Buzzer or any Electronic Appliance

using BLYNK app

and NodeMCU ESP8266

2
Materials Required

• Laptop/PC
• Node MCU Esp8266
• Micro-USB cable
• Smart Phone with Blynk App installed
• Led/Buzzer
• 330 ohm resistor
• Breadboard
• Arduino IDE
• Jumper Wires
3
NodeMCU - Introduction

• NodeMCU is a Firmware with ESP8266


• ESP8266 is a low-cost, Wi-Fi Module chip that can be
configured to connect to the Internet for Internet of Things(IoT)
and similar Technology Projects.

Features:
• Programmable Wi-Fi module.
• Arduino-like (software defined)
hardware IO.
• Can be programmed with
Arduino IDE.
• USB-TTL included, plug & play.
• 10 GPIOs D0-D10

4
NodeMCU PIN Diagram

5
LED Control Process

6
Adding Blynk App

• Download Blynk App for Android or iOS


• Create Account and
• get Authentication Token on Email

7
Install Arduino IDE 1.8.8

• Download and install Arduino IDE or use MS Store


to install directly

https://www.microsoft.com/en-in/p/arduino-
ide/9nblggh4rsd8?ocid=badge&rtc=1&activetab=pivot:
overviewtab

8
Adding Blynk Library

• Download Blynk Library (v 0.5.4.zip)


https://github.com/blynkkk/blynk-library/releases/tag/v0.5.4
• Unzip Blynk Libraray
• Copy all these libraries to
your_sketchbook_folder of Arduino IDE. To find the
location of your_sketchbook_folder, go to top menu in
Arduino IDE: File -> Preferences (if you are using Mac OS -
go to Arduino → Preferences) (Picture in Next slide)

Note: libraries should go to libraries and tools to tools. If you


don't have tools folder you can create it by yourself.

9
10
11
Check Blynk Board and ESP8266

12
13
14
Adding Blynk Board add-on

• Install the Blynk Board add-on.


• Open the Arduino Preferences under the File
> Preferences menu.

Then copy this URL:

https://raw.githubusercontent.com/sparkfun/Ard
uino_Boards/master/IDE_Board_Manager/pack
age_sparkfun_index.json

15
16
17
18
NodeMCU – Adding additional
board URLs
• Go to files and click on the preference in the Arduino
IDE.
• Copy the below code in the Additional boards
manager.
http://arduino.esp8266.com/versions/2.5.0-
beta2/package_esp8266com_index.json
• Click OK to close the preference Tab.
• After completing the above steps, go to Tools and
board, and then select board manager.
• Navigate to esp8266 by esp8266 community and
install the software for Arduino. Once all the above
process been completed we are read to program our
esp8266 with Arduino IDE.

19
NodeMCU – Adding additional
board URLs

20
21
22
23
Arduino/NodeMCU - Programming

After selecting the board follow settings below:


• Board : “NodeMCU 1.0 (ESP-12 Module)”
• Upload Speed : “115200"
• Flash Size : "4M (1M SPIFFS)“
• CPU Frequency: "80Mhz"
• Debug Port : "Disabled"
• Debug Level: "None"
• IWIP Variant: "V2 Lower Memory“
• VTables: “Flash”
• Erase Flash: “Only Sketch"
• Port : "COM port available" (where the device is connected
should show up)
• Compile and upload a program form basic examples – “blink”
to check if it’s working.
24
Setup Blynk App

25
26
27
Using a Breadboard

28
Setup Blynk App - Steps
• First install the Blynk app from play store and then
sign in.
• After that Press on click on New Project.
• Enter the name of your project (Eg: led).
• Then Select the Board as ESP8266
• Copy the authentication token no. If you want it in
your email you can send it through email also.

29
Setup Blynk App - Steps
• Click on to the create button
• You are on dashboard screen, now. Just click on the button "+"
on the right corner to add widgets to your project.
• Add a simple button and then configure its settings as Digital
pin.(Eg. GPIO13 for D7, refer NodeMCU Pin Diagram)
• Set button as as push type or as a switch
• Then label the Button as ON and OFF in the settings

Note that since Blynk is free only to an extend, you have to


choose your widgets wisely

30
Circuit Diagram

31
NodeMCU PIN Diagram

32
Circuit Setup

• Now According to the Pin mapping diagram of Esp8266


board, D7 pin is the 13th pin. So we would program the
pin as 13 in the arduino code which we will shortly upload
to the board.
• The connection is pretty simple just connect the One leg
of Led to D7 pin via 330/220 Ohm resistor. (refer the
diagram)
• Connect One leg of LED with GND
• Connect NodeMCU with Laptop/PC with Micro-USB cable.

33
Code

• Open Arduino IDE


• Select the correct board (NodeMCU 1.0) and the com port
from the Tools Menu
• File -> New
• and Start Coding

34
Code

/* Multiline Comment */
// Defines the object that is used for printing
#define BLYNK_PRINT Serial

//Header files included


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

35
Code

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon) or to your EMail
char auth[] = "YourAuthToken";

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

36
Code

//For the initial setup in the code


void setup()
{
// Debug console
Serial.begin(115200);

Blynk.begin(auth , ssid , pass);


}

37
Code

//The part of code which should keep on happening in loop

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

38
Burn the Sketch in NodeMCU

39
Execution
• After uploading the code
• Open the Blynk app in the Phone
• Let it connect to the internet
• Then you would see your dashboard with a button
• Press Play button on the top most right corner of
the app
• Then Press the Button and you would see the LED
Turn ON.

40
Execution

41
Execution

42
IoT Motion Detector
with

Blynk App
and

NodeMCU Esp8266

43
Experiment Brief

We want to

Switch On and Off

an LED or Buzzer or any Electronic Appliance


using Relay

if there is any motion in front of PIR Sensor

connected to NodeMCU ESP8266

and get notification on BLYNK app

44
Materials Required
• Laptop/PC
• Node MCU Esp8266
• Micro-USB cable
• Smart Phone with Blynk App installed
• Led/Buzzer and Electronic appliance
• 330 ohm, 1 k and 2 k resistor
• Breadboard
• Arduino IDE
• Jumper Wires
• Relay
45
NodeMCU PIN Diagram

46
Passive Infrared (PIR) Motion Sensor

47
Hardware Setup
• The sensor has 3 pins (+5V, GND and Output).
• PIR sensor generates a logic signal of + 3.3V (HIGH)
or 0V (LOW), which is COMPATIBLE with the input
levels of the NodeMCU, which also works with the
3.3V level. The circuit with a level converter is used
to ensure if any other sensor with 5V output is used.
If the sensor generates 3.3V and not 5V as output
you can eliminate the level converter, connecting
NodeMCU Pin (Eg. D1 (GPIO 5)) directly to PIR
Output.
• We have also included a LED at pin (Eg. D7
(GPIO13)), for a local visualization.
48
49
Testing Sensor
/* PIR Motion Detector */
#define ledPin D2 // Input for HC-SR501
#define pirPin D7 // Red LED

int pirValue; // variable to store read PIR Value

50
Testing Sensor
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
digitalWrite(ledPin, LOW);
}

51
Testing Sensor
void loop()
{
pirValue = digitalRead(pirPin);
Serial.println(pirValue);
digitalWrite(ledPin, pirValue);
delay(1); // delay in between reads for stability
}

52
Compile and Burn Code

53
Check Serial Monitor

54
Add Relay and Electronic Appliance
• Attach Relay with NodeMCU
• One connection to VCC
• One connection to GND
• One Output Pin of NodeMCU to IN Pin of Relay
• Attach Relay to Electronic Appliance (Eg. Fan) and
Power Socket
• Connect one wire of Electronic Appliance to
Socket
• Break 2nd wire into 2 pieces and connect 1st
piece from Fan to Relay and 2nd piece from
Relay to Socket
55
56
Update Blynk App

57
Update Blynk App

58
Code
#include <ESP8266WiFi.h>

#define BLYNK_PRINT Serial


#include <BlynkSimpleEsp8266.h>
char auth[] = "YOUR AUTH CODE HERE";

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

59
Code

/* PIR Motion Detector */


#define ledPin D1
#define pirPin D7 // Input for PIR

int pirValue; // Place to store read PIR Value

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

61
Code

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

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

63
THANK YOU

64

S-ar putea să vă placă și