NODE MCU ESP8266 Document
NODE MCU ESP8266 Document
ESP8266
Learn-Practice-Grow
www.pantechsolutions.net
8/19/2021
Contents
NODE MCU ESP8266 Starter Kit .................................................................................................................... 2
LED circuit ..................................................................................................................................................... 3
LDR Sensor .................................................................................................................................................... 4
Water Level Sensor ....................................................................................................................................... 5
PIR Sensor ..................................................................................................................................................... 6
IR Sensor ....................................................................................................................................................... 7
DHT 11 Sensor ............................................................................................................................................... 8
Relay with motor........................................................................................................................................... 9
Servo motor ................................................................................................................................................ 10
Hardware tools............................................................................................................................................ 11
Software Tools ............................................................................................................................................ 11
NODE MCU ESP8266 Starter Kit
Introduction
• In this circuit diagram, we have connected five LEDs in a breadboard. We can’t connect
the led directly into nodemcu esp8266. So that we are connecting with 330-ohm resistor
in between nodemcu esp8266 to LEDs.
• The LEDs are work with both analog pins and digital pins in nodemcu esp8266
microcontroller.
• If we are connected with analog means in programming we have to write
( analogWrite(pin number, analog value); ) or we connected in digital means
( digitalWrite(pin number, HIGH or LOW); )
Program:
• The LDR sensor (Light Dependent Resistor ) is also called a photoresistor or a cadmium
sulfide (CdS) cell. This optoelectronic device is mostly used to find the light intensity,
and light and dark activated switching sensor.
• An LDR or a photoresistor is a device whose resistivity is a function of the incident
electromagnetic radiation. Hence, they are light-sensitive devices. They are also called as
photoconductors, photoconductive cells or simply photocells
• LDR sensor output is analog values. So that we are connecting with A0 pin in nodemcu.
Program
• The Water Level Depth Detection sensing element for Arduino has operational voltage
DC3-5V and operational current less than 20mA.
• The sensing element is that the Analog type that produces analog output signals
according to the water pressure with its Detection space of 40x16mm.
• The Water Level sensor is easy to find the values and cost-effective with a high-level
drop recognition sensor by having a series of parallel wires exposed traces measured
droplets/water volume therefore on see the water level. Easy to finish water to analog
signal conversion and output analog values may directly browse the Arduino
development board to achieve the level alarm result.
• Water level sensor output is analog values. So that we are connecting with A0 pin in
nodemcu microcontroller.
Program
• The PIR sensor ( passive infrared sensor ) is using to measures infrared light radiating
from objects in its field of view. PIR sensor is mostly used to find the motion of objects.
• The PIR sensor output is a digital signal. So we are connecting with digital pins in
nodemcu esp8266 microcontroller. But we can connect in any digital pins in controller
• All most the sensor are given some voltage only in the output side that we are converting
into digital or analog value to the microcontroller
• Using this sensor we can do any type of controlling the electronics devices or electronic
drives
Program
• The IR sensor is using to find the obstacle and IR sensor is working transmitter and receiver. the
infrared led is emitting the light energy when the light energy is getting interrupt the means the
photodiode receives the light energy and the input energy is converting into digital values using
LM358 IC.
• In the market the analog type sensor also available. So the connection depends upon the sensor
type if it’s analog means in nodemcu esp8266 we have only one analog pin that is A0 pin.
• If the sensor is digital means we have 0 to 8 digital pins so that we connect with any digital pins.
Program
int IR = D2;
void setup() {
Serial.begin(9600);
pinMode(IR,INPUT);
}
void loop() {
int ir = digitalRead(IR);
Serial.print("PIR:");
Serial.println(ir);
if(ir == 1)
{
Serial.println("yes");
}
else
{
Serial.println("no");
}
delay(1000);
}
DHT 11 Sensor
• This is the connection of the DHT 11 sensor with nodemcu esp8266. We can connect the
data pin in any digital pins in nodemcu microcontroller.
• The DHT 11 sensor is working with library only #include "DHT.h" this is the header
file for DHT 11 sensor.
• From this sensor, we get the two digital value one is temperature and another one
humidity
Program
#include<dht.h>
dht DHT;
#define DHT11_PIN D0
void setup() {
Serial.begin(9600);
Serial.println("welcome to TechPonder Humidity and temperature Detector"); }
void loop() { // READ DATA
int chk = DHT.read11(DHT11_PIN);
Serial.println(" Humidity " );
Serial.println(DHT.humidity, 1);
Serial.println(" Temparature ");
Serial.println(DHT.temperature, 1);
delay(2000);
}
Relay with motor
• The relay is called an electronic switch using this switch we can make on and off
conditions of electrical devices.
• In this circuit diagram, we are connecting 5v DC motor in the relay board the motor
power supply is given by 9V battery form in this circuit.
• Relay is working with digital input only. So we can connect the relay in any digital pins
in nodemcu esp8266.
Program
const int LED1 = D3;
char inchar;
void setup()
{
Serial.begin(115200);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
}
void loop()
{
if (Serial.available())
{
inchar = Serial.read();
if (inchar == 'A')
{
Serial.println("ON State");
digitalWrite(LED1, HIGH);
}
else if (inchar == 'B')
{
Serial.println("OFF State");
digitalWrite(LED1, LOW);
}
delay(100);
}
}
Servo motor
• The Servo motor SG90. light-weight with high output. The servo will rotate just about a
hundred and eighty degrees (90 in each direction) and works rather like the standard
types however smaller. you'll use any servo code, hardware or library to control these
servos.
• Servo motor is controlled by sending an electrical pulse of variable width or pulse width
modulation (PWM), through the control wire. The servo motor expects to check a pulse
every twenty milliseconds (ms) and also the length of the pulse can determine however
far the motor turns.
Program
#include <Servo.h>
Servo myservo; // create servo object to control a servo // twelve servo objects can be
created on most boards
int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Hardware tools
• Nodemcu ESP8266
• Breadboard
• DHT 11
• LDR sensor
• Servo motor SG90
• water level sensor
• PIR sensor
• IR sensor
• relay board with dc motor
• buzzer circuit
• LED circuit
• jumper wires
Software Tools
• Arduino IDE