IoT unit 2 vips
IoT unit 2 vips
(AIDS/AIML309)
Course Overview:
• This course is foundation course around the Internet of Things (IoT). It overviews about the
technology used to build these kinds of devices, how they communicate, how they store
data, and the kinds of distributed systems needed to support them. Divided into four
modules, the first unit explores about theoretical concepts of IoT while second unit is
completely programming based to explore IoT sensors and actuators with Arduino. The rest
of the syllabus is application oriented based on learning. In general, through this course
students will be explored to the interconnection and integration of the physical world and
the cyber space. They will be able to design and develop IOT Devices
Course Objective:
Determines how packet are coded and signaled by hardware device over medium
to which host is attached.
Network Point to point Star topology, peer-to- Low power, mesh or peer-to peer LAN topology IBSS,
between active peer piconet expended by star networks BSS and distributed BSSs for
and Passive interpiconets data using end devices, coordinator, WWLAN widely used for
Devices transactions and router, ZigBee IP border router Internet connectivity of
Synchronisation mobiles, tablets, Desktops
• DISADVANTAGES
• Size of data frame is limited to a maximum of 9 bits
• Doesn’t support multiple slave or multiple master systems
• Baud rates of each UART must be within 10% of each other
Examples of
UARTs
FT232r USB UART / USB to
USB CP2102
UART 5V
Serial Converter
2. Master switches SS/CS pin to a low voltage state, which activates slave
Steps of SPI Data
Transmission
3. Master sends data one bit at a time to slave along MOSI line. Slave reads bits as they are
received
4. If response is needed, slave returns data one bit at a time to master along MISO line. Master
reads bits as they are received
Advantages and
•Disadvantages
ADVANTAGES of SPI
No start and stop bits, so data can be streamed continuously without interruption
No complicated slave addressing system like I2C
Higher data transfer rate than I2C (almost twice as fast)
Separate MISO and MOSI lines, so data can be sent and received at same time
• DISADVANTAGES
Uses four wires (I2C and UARTs use two)
No acknowledgement that data has been successfully received (I2C has this)
No form of error checking like parity bit in UART
Only allows for a single master.
Examples of SPIs in
Microcontrollers
MCP 3008 / Grove I2C ADC
SPI Seeeduino
V4.2
• Read/Write Bit : High Read/Write bit indicates that master is sending data to slave, whereas
low Read/Write bit indicates that master is receiving data from slave.
• ACK/NACK Bit : After every data frame, follows an ACK/NACK bit. If data frame is received
successfully then ACK bit is sent to sender by receiver.
• Addressing : Address frame is first frame after start bit. Slave address with which master
wants to communicate is sent by master to every slave connected with it. Slave then
compares its own address with this address and sends ACK.
STEPS OF I2C DATA
TRANSMISSION
1. Master sends start condition to every
connected slave by switching SDA line
from high voltage to low voltage level
before switching SCL line from high to
low:
2. Master sends each slave 7 or 10 bit
address of slave wants
communicate it with,
read/write to
3. bit
Each slave address sent
along with
compares
from master to its own address. If
address matches, slave returns an
ACK bit by pulling SDA line low for
one bit else sets SDA line high.
STEPS OF I2C DATA
TRANSMISSION
4. Master sends or receives data frame
5. After each data frame been
has
transferred, receiving device
returns ACK bit to sender to acknowledge
another
successful receipt of frame
6. To stop data transmission, master sends a
stop condition to slave by switching SCL
high before switching SDA high
Advantages and
•Disadvantages
ADVANTAGES of I2C
Only uses two wires
Supports multiple masters and multiple slaves
ACK/NACK bit gives confirmation that each frame is transferred successfully
Hardware is less complicated than with UARTs
Well known and widely used protocol
• DISADVANTAGES
Slower data transfer rate than SPI
The size of the data frame is limited to 8 bits
More complicated hardware neededDr.tDoivyaiAmgarpwall ement than SPI
ARDINO IDE
•OVERVIEW:
Program coded in Arduino IDE is called a SKETCH
1. To create a new sketch File -> New
2. To open an existing sketch File -> open ->
3. To open ready-to-use sketches File -> Examples -> select any program
4. Verify: Checks code for compilation errors
5. Upload: Uploads final code to controller board
6. New: Creates a new blank sketch with basic structure
7. Open: Opens an existing sketch
8. Save: Saves current sketch
9. Serial Monitor: Opens serial console
ARDINO IDE
OVERVIEW:
ARDINO IDE
OVERVIEW:
Structure of
SKETCH
Sketch can be divided
into two parts:
1. Setup ()
2. Loop()
Structure of
SKETCH
A sketch can be divided into two parts:
1. Setup ()
• Here, code starts, like main() function in C and C++
• I/O Variables, pin modes are initialized in Setup() function
2. Loop()
• Loop() function, iterates specified task in program
DATA
TYPES
• Void, • Word
• Long, • Unsigned long,
• Int, • Float,
• Char, • Double,
• Boolean, • Array,
• Unsigned char, • String-char array,
• Byte, • String-object,
• Unsigned int, • Short
Arduino Function
Libraries
1. Input/Output Functions:
• Arduino pins can be configured to act as input or output pins using pinMode() function
2. Example
Void setup ()
{
pinMode (pin , mode);
}
• Pin- pin number on Arduino board
• Mode- INPUT/OUTPUT
3. digitalWrite(): Writes a HIGH or LOW value to a digital pin
4. analogRead(): Reads from analog input pin i.e., voltage applied across pin
5. Character functions: isdigit(), isalpha(), isalnum(), isxdigit(), islower(), isupper(), isspace()
return 1(true) or 0(false)
6. Delay() function: Most common time manipulation function used to provide a delay of
specified time. It accepts integer value (Dt.ir DmayvieAgianwar ml iliseconds)
EXAMPLE
BLINKING
1. Requirement: LED
• Arduino controller board,
• USB connector,
• Bread board,
• LED,
• 1.4Kohm resistor,
• connecting wires,
2. Arduino IDE
• Connect LED to Arduino using Bread board and connecting wires
• Connect Arduino board to PC using USB connector
• Select board type and port
• Write sketch in editor, verify and upload
• Connect positive terminal of LED to digital pin …… and negative terminal to ground pin
(GND) of Arduino Board
EXAMPLE
BLINKING
void setup()
LED
{
pinMode(3, OUTPUT); // set the pin mode
}
void loop()
{
digitalWrite(3, HIGH); // Turn on the LED
delay(1000);
digitalWrite(3, LOW); //Turn of the LED
delay(1000);
}
Light Dependent
•Resistor
LDR is a type-ofLDR
resistor that changes
resistance as light on its surface
changes.
• i.e., less light or more darkness on
LDR surface causes its resistance to
increase.
• LDR connected in series with a 10k
resistor.
• To detect light levels and switch an
LED on or off.
Connection
Diagram
• Here, 10k resistor R1 and LDR R2
form a voltage divider.
• i.e, voltage at junction of R1 and
R2 is divided voltage from 5V that
is across them.
• As light varies on LDR surface, so
does its resistance which causes
voltage between GND and A0 to
vary as well.
Arduino Uno LDR
Breadboard Circuit
Cod Switch on an LED when Light Levels are Low
evoid setup()
{
pinMode(LED_BUILTIN,
OUTPUT);
}
void loop()
{
int sensorValue =
analogRead(A0); if
(sensorValue > 700)
{
digitalWrite(LED_BUILTIN,
HIGH);
}
else
{
digitalWrite(LED_BUILTIN,
LOW);
LDR Module Pin
Description
Pins on sensor,
• VCC - Positive power supply,
• GND - Ground
• DO - Digital output
• AO - Analog output
LDR -
•Operation
Photoresistor sensor module includes LDR in series with 10K resistor.
• AO pin is connected between LDR and 10K resistor.
• Voltage on AO pin depends on illumination.
• Read this voltage by connecting AO pin of photoresistor sensor to an analog input pin and
then using analogRead() function.
• Parameters that control sensitivity of LDR: rl10 and gamma.
• rl10 – LDR Resistance at illumination level of 10 lux.
• Gamma – determines slope of log(R) / log(lux) graph.
Connect a LDR to an
Arduino Uno
Step 1: Read analog value from LDR circuit. Watch analog value change as light on sensor
increases or decreases.
Step 2: Load sketch code that turns on an LED when LDR is darkened. Also switch off LED
when LDR is exposed to enough light.
Working of LDR with
•Arduino Uno
LDR gives out analog voltage when connected to
VCC (5V), which varies with input light intensity.
• i.e., greater the intensity of light, greater will be
corresponding voltage from LDR.
• LDR gives out an analog voltage, as it is
connected to analog input pin on Arduino.
• Arduino, with its built-in ADC (analog-to-digital
converter), converts analog voltage (from 0-5V)
into a digital value in range of (0-1023).
• When there is sufficient light in its environment
or on its surface, converted digital values read
from LDR through Arduino will be in range of
800-1023.
Simple IF statement
code
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
int sensorValue =
analogRead(A0); if
(sensorValue > 700) {
digitalWrite(LED_BUILTIN,
HIGH);
}
delay(10);
}
IF-else statement
code
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
int sensorValue =
analogRead(A0); if
(sensorValue > 700) {
digitalWrite(LED_BUILTIN,
HIGH);
}
else {
digitalWrite(LED_BUILTIN,
LOW);
}
While Statement to blink two LEDs for
two different conditions
int sensorPin = A0;
int light_1 = 13; while (analogRead (sensorPin <
100))
int light_2 = 12; {
void setup() { digitalWrite(light_ LOW);
1,
pinMode(sensorPin, delay(500);
INPUT);
pinMode(light_1, digitalWrite(light_ LOW);
OUTPUT); 1,
pinMode(light_2, delay(500);
OUTPUT);
{
} digitalWrite(light_1, }
voidHIGH);
loop() delay(500);
{ }
while (analogRead
digitalWrite(light_1, >100))
(sensorPin
HIGH); delay(500);
}
Do while statement used to
blink an LED
int sensorPin =
A1; int light_1
= 2; void
setup() {
pinMode(sensorPin,
INPUT);
pinMode(light_1,
OUTPUT);
}
void loop() {
do
{
digitalWrite(light_1,
HIGH); delay(500);
digitalWrite(light_1,
HIGH); delay(500);
}
while (analogRead (sensorPin
Temperature
Sensor
• Simple temperature sensor is a device, to measure temperature through an
electrical signal it requires a thermocouple or RTD (Resistance Temperature
Detectors).
• Thermocouple is prepared by two dissimilar metals which generate electrical
voltage indirectly proportional to change temperature.
• RTD is a variable resistor, it will change electrical resistance indirectly proportional
to changes in temperature in a precise, and nearly linear manner.
Digital Humidity and Temperature
Sensor (DHT)
• DHT11 -Low-cost digital sensor for sensing temperature and humidity.
• Easily interface with any microcontroller such as Arduino, Raspberry Pi,
etc… to measure humidity and temperature instantaneously.
• Available as a sensor and as a module.
• Difference: Pull-up resistor and a power-on LED.
• Has resistive humidity sensing and negative temperature coefficient (NTC).
• 8 bit MCU is connected in it which is responsible for its fast response.
Working of DHT
sensor
• Working simple.
• DHT11 sensor consists of a capacitive humidity sensing element and a thermistor for
sensing temperature.
• Humidity sensing capacitor has two electrodes with a moisture-holding substrate as
a dielectric between them.
• Change in capacitance value occurs with change in humidity levels.
• IC measure, process this changed resistance values and change them into digital
form.
• For measuring temperature this sensor uses Negative Temperature coefficient
thermistor, which causes a decrease in its resistance value with an increase in
temperature.
• To get a larger resistance value even for smallest change in temperature, this sensor
is usually made up of semiconductor ceramics or polymers.
Specification :
DHT22
• Humidity range from 20 to 90% RH
• Temperature range from 0 – 50 C
• Signal transmission range of 20 m
• Inexpensive
• Fast response and durable
DHT22 Pin
out
PIN 1,2,3,4 (from left to right)
• PIN 1- 3.3V-5V Power supply
• PIN 2- Data
• PIN 3- Null
• PIN 4- Ground
DHT Sensor
Library
• Arduino supports a special library for DHT11 and DHT22 sensors
• Provides function to read temperature and humidity values from data pin
1. dht.readHumidity()
2. dht.readTemperature()
• Install DHT Sensor Library
• Go to sketch -> Include Library -> Manage Library
DHT Sensor
Library
Arduino DHT22Sensor Circuit
Diagram
Arduino DHT22 Sensor Circuit
Diagram
DHT
22Code
#include <DHT.h>
DHT dht(2, DHT22);
void setup()
{ Serial.begin(9
600);
dht.begin();
}
void loop() {
float temperature =
dht.readTemperature(); float humidity
= dht.readHumidity();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature:
");
} Serial.print(temperature);
DHT
11Code
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE
Serial.print("Humidity: ");
DHT11
Serial.print(humidity);
// DHT dht(2,DHT11)
Serial.print("% Temperature:
DHT dht(DHTPIN,
");
DHTTYPE);
Serial.print(temperature);
void setup()
Serial.print("°C ");
{ Serial.begin(9600);
}
Serial.println("DHT11
test!"); dht.begin();
}
void loop()
{ delay(200
float temperature =
0);
dht.readTemperature(); if
float
(isnan(humidity) ||
humidity =
isnan(temperature) )
dht.readHumi
//isnan = is NOT A NUMBER which return
dity();
true
returnwhen it is not a number
Difference between DHT 11
and DHT 22
• DHT11 has a humidity range that falls between 5 and 95%
• DHT11 has a temperature range that falls between -20 and 60℃.
• DHT22 features a temperature sensor with high precision, as well as a
humidity sensor.
• DHT 22 is highly reliable and has great long-term stability.
• DHT22 has a humidity range that falls between 0 and 100%
• DHT22 has a temperature range that falls between -40 and 80℃.
Blink a RGB
•LED
RGB - Stands for "Red Green Blue."
• RGB refers to three hues of light that can be mixed together to create
different colors.
• Combining red, green, and blue light is standard method of producing color images
on screens, such as TVs, computer monitors, and smartphone screens.
• Types of RGB led’s: Common cathode and Common anode.
In common cathode RGB led, cathode of all led’s is common and PWM signals is
given to anode of led’s
In common anode RGB led, anode of all led’s is common and PWM signals is given
to cathode of led’s.
How does an RGB LED
work?
• RGB LED can emit different colors by mixing 3 basic colors red, green and blue.
• Consists of 3 separate LEDs red, green and blue packed in a single case.
• Comprises of 4 leads, one lead for each of 3 colors and one common cathode or
anode depending on RGB LED type.
• Cathode will be connected to ground and 3 anodes will be connected through 220
Ohms resistors to 3 digital pins on Arduino Board that can provide PWM signal.
• Using PWM for simulating analog output will provide different voltage levels to LEDs
to get desired colors
How does an RGB LED
•work?
Using PWM for simulating analog output will provide different voltage levels to LEDs
to get desired colors
RGB LED Pin
out
PIN 1,2,3,4 (from left to right)
• Pin D5 - R
• Pin D4 - G
• Pin D3 - B
Arduino RGB LED wiring
diagram
Connection
steps
• Use wiring diagram to connect RGB LED to your Arduino
• Plug Arduino board into your PC
• Check COM ports in Windows device list
• Open Arduino application on your computer
• Upload code to Arduino
• Verify and run
RGB LED
Code LED1RED
#define 5
#define LED1BLUE 3 digitalWrite(LED1BLUE,
#define LED1GREEN 4 HIGH);
void setup() Serial.println("LED1BLUE");
{ pinMode(LED1RED, delay(1000);
OUTPUT); digitalWrite(LED1BLUE,
pinMode(LED1BLUE, LOW);
OUTPUT); Serial.println("LED1BLUE");
pinMode(LED1GREEN, delay(1000);
OUTPUT); digitalWrite(LED1GREEN,
Serial.begin(9600); HIGH);
} Serial.println("LED1GREEN")
void loop() ; delay(1000);
{ digitalWrite(LED1RED, digitalWrite(LED1GREEN,
HIGH); LOW);
Serial.println("LED1RED Serial.println("LED1GREEN")
"); delay(1000); ; delay(1000);
RGB LED
Code
int redPin= 7;
int greenPin = setColor(170, 0, 255); // Purple
6; int bluePin Color delay(1000);
= 5; void }
setup() {
pinMode(redPin, void setColor(int redValue, int
OUTPUT); greenValue, int blueValue)
pinMode(greenPin, { analogWrite(redPin,
OUTPUT); redValue);
pinMode(bluePin, analogWrite(greenPin,
OUTPUT); greenValue);
} analogWrite(bluePin,
void loop() { blueValue);
setColor(255, 0, 0); // Red }
Color delay(1000);
setColor(0, 255, 0); // Green
Color
delay(1000);
Use RGB as Traffic Signal
Generator
int ledDelay = 10000;
int red = 11; digitalWrite(green,HIGH
int yellow = );
13; int green digitalWrite(red,LOW);
= 12; digitalWrite(yellow,LOW
); delay(ledDelay);
void setup() digitalWrite(yellow,HIG
{ pinMode(red,OUTPU H);
T); digitalWrite(green,LOW)
pinMode(yellow,OUTPUT ; delay(2000);
); digitalWrite(yellow,LOW
pinMode(green,OUTPUT) );
; }
}
void loop()
{ digitalWrite(red,HIG
H); delay(ledDelay);
Ultrasonic
•Sensor
Ultrasonic sensors measure distance by using ultrasonic waves.
• Sensor head emits an ultrasonic wave and
receives wave reflected back from target.
• Ultrasonic Sensors measure distance to target
by measuring time between emission and
reception.
• Optical sensor has a Tx and Rx, whereas an ultrasonic sensor uses a single ultrasonic
element for both emission and reception.
• In a reflective model ultrasonic sensor, a single oscillator emits and receives
ultrasonic
waves alternately. This enables miniaturization of the sensor head.
Ultrasonic
Sensor
• HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo.
• Ground and VCC pins of module needs to be connected to Ground and 5 volts pins
on Arduino Board respectively and trig and echo pins to any Digital I/O pin on
Arduino Board.
• To generate ultrasound, set Trig on a High State for 10 us to send out an 8 cycle
sonic burst which will travel at speed sound and will be received in Echo pin.
• Echo pin will output time in microseconds sound wave traveled.
Ultrasonic
Sensor
• For example, if object is
10 cm away from sensor,
and speed of sound is
340 m/s or 0.034 cm/us
sound wave will travel
about 294 microseconds.
• Echo pin output will be
twice because sound
needs to travel
wave
forward bounce
and
backward.
Steps to write Source code for
Ultrasonic Sensor
• Define Trig (pin 9) and Echo pins (pin 10) as trigPin and echoPin.
• Initialize long variable, named "duration" for travel time from sensor and an integer variable
for distance.
• In setup() define trigPin as output and echoPin as Input and also start serial communication
for showing results on serial monitor.
• In loop() set trigPin to LOW State for just 2 us; to generate Ultra sound wave set trigPin to
HIGH State for 10 us.
• Use pulseIn() function to read travel time and put this value into variable "duration".
• This function has 2 parameters, echo pin and HIGH or LOW.
Steps to write Source code for
•Ultrasonic
This function hasSensor
2 parameters, echo pin and HIGH or LOW.
• HIGH means pulsIn() function will wait for pin to go HIGH caused by bounced sound wave
and it will start timing, then it will wait for pin to go LOW when sound wave will end which
will stop timing.
• At the end function will return length of the pulse in microseconds.
• For getting distance, multiply duration by 0.034 and divide it by 2.
• At end, print the value of the distance on the Serial Monitor.
Wiring
Connection
Ultrasonic Sensor
Code
#define trigPin
11 duration =
#define echoPin pulseIn(echoPin,HIGH);
12 distance = (duration/2) /
#define ledPin
void setup() 29.1; if(distance<10)
13
{ Serial.begin(9600); {
digitalWrite(ledPin,HIGH);
pinMode(trigPin,OUTPUT }else{ digitalWrite(le
); dPin,LOW);
pinMode(echoPin,INPUT) }
; Serial.print(distance
pinMode(ledPin,OUTPUT)
void loop() { );
;
long duration , Serial.println("cm");
}
distance; delay(1500);
digitalWrite(trigPin,LOW }
);
delayMicroseconds(2);
digitalWrite(trigPin,HIG
digitalWrite(trigPin,LOW
Servo
Motor
• A servo motor is a self-contained electrical device, that rotate parts of a machine with high
efficiency and with great precision.
• Output shaft of this motor can be moved to a particular angle, position and velocity that a
regular motor does not have.
• Servo Motor utilizes a regular motor and couples it with a sensor for positional feedback.
• Servo motor is a closed-loop mechanism that incorporates positional feedback in order to
control the rotational or linear speed and position
• Motor is controlled with an electric signal, either analog or digital, which determines the
amount of movement which represents the final command position for the shaft.
Servo Motor:
Circuit
• Servo motors have three wires: power,
ground, and signal.
• Power wire is typically red, and connected to
5V pin on Arduino board.
• Ground wire is typically black or brown and
connected to ground pin on board.
• Signal pin is typically yellow or orange and
should be connected to PWM pin on board.
In
Circuit
Diagram
Servo Motor
Code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
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)
{
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)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Micro Servo
Code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup()
{ Serial.begin(960
0);
myservo.attach(9);
// attaches the
servoloop()
void on pin{9 to
the
intservo
val; object
}
while
(Serial.avail
able()>0)
{
val =
Serial.parseI
nt();
if(val!=0)
{
Serial.println(val);
}
LCD 16*2 Pin
Connections
Name Description Arduino Pin*
VSS Ground GND.1
VDD Supply voltage 5V
Contrast adjustment (not
V0 simulated)
RS Command/Data select 12
RW Read/Write. Connect to Ground. GND.1
E Enable 11
D0 – D3 Parallel data 0 - 3 (optional) †
D4 Parallel data 4 10
D5 Parallel data 5 9
D6 Parallel data 6 8
D7 Parallel data 7 7
A Backlight anode 5V / 6‡
K Backlight cathode Dr. Divya Agar
G ND.1
wa l
LCD 16*2 Pin
Connections
Name Description Arduino Pin*
VSS Ground GND.1
VDD Supply voltage 5V
Contrast adjustment (not
V0 simulated)
RS Command/Data select 12
RW Read/Write. Connect to Ground. GND.1
E Enable 11
D0 – D3 Parallel data 0 - 3 (optional) †
D4 Parallel data 4 10
D5 Parallel data 5 9
D6 Parallel data 6 8
D7 Parallel data 7 7
A Backlight anode 5V / 6‡
K Backlight cathode Dr. Divya Agar
G ND.1
wa l
LCD wiring
Connections
LCD16*02 to Arduino
Uno Code
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2);
// you can now interact with the LCD,
e.g.: lcd.print("Hello World!");
}
void loop() {
// ...
}
ESP8266
•
NodeMCU
NodeMCU is an open-source firmware and
development kit that helps to prototype or
build IoT products.
• Includes firmware that runs on ESP8266 Wi-Fi
SoC from Espressif Systems, and hardware
which is based on ESP-12 module.
• Firmware uses Lua scripting language.
• Based on eLua project and built on Espressif
Non-OS SDK for ESP8266.
ESP8266
•
NodeMCU
MCU stands for MicroController Unit - which
means it is a computer on a single chip.
• Microcontroller contains one or more CPUs
(processor cores) along with memory and
programmable input/output peripherals.
• They are used to automate automobile
engine control, implantable medical devices,
remote controls, office machines, appliances,
power tools, toys etc.
ESP8266
NodeMCU
Pin Description
ESP8266 NodeMCU Pin Description and
Specifications
• NodeMCU_ESP8266 has 30 pins in total out of which there are 17 GPIO pins.
• GPIO stands for General Purpose Input Output.
• 9 digital pins ranging from D0-D8
• One analog pin A0, which is a 10 bit ADC.
• D0 pin can only be used to read or write data and can’t perform other options.
• ESP8266 chip is enabled when EN pin is pulled HIGH and is disabled when EN pin is pulled LOW.
• Board has a 2.4 GHz antenna for a long-range of network
• CP2102 is USB to TTL converter.
• ESP-12E module containing ESP8266 chip having Tensilica Xtensa® 32-bit LX106 RISC microprocessor
which operates at 80 to 160 MHz adjustable clock frequency and supports RTOS.
ESP8266 NodeMCU Pin Description and
Specifications
• 128 KB RAM and 4MB of Flash memory
• ESP8266 Integrates 802.11b/g/n HT40 Wi-Fi transceiver, so it can connect to WiFi network for
interacting with Internet and can also set up a network of its own, allowing other devices to connect
directly to it which makes it even more versatile.
• ESP8266 has 2 onboard buttons along with an on-board LED which connects with D0 PIN.
• Two buttons are FLASH and RST.
• FLASH pin– It is to download new programs to the board
• RST pin – It is to reset the ESP8266 chip
• ESP8266 can be used are:
• Making a web server using ESP8266; Controlling DHT11 using the NodeMCU; ESP8266 weather
station-using BMP280; ESP8266 NTP serDvr.eDrivyfaoAgrarfwealtching time
Lua
•
Programming
Lua is a powerful, efficient, lightweight, embeddable scripting language.
• Supports procedural programming, object-oriented programming,
functional
programming, data-driven programming, and data description.
• Lua combines simple procedural syntax with powerful data description constructs based on
associative arrays and extensible semantics.
• Lua is dynamically typed, runs by interpreting bytecode with a register-based
virtual
machine, and has automatic memory management with incremental garbage collection,
making it ideal for configuration, scripting, and rapid prototyping.
• Lua is a proven, robust language which is powerful and available for free.
Programming
Model
• NodeMCU programming model is similar to that of Node.js, only in Lua.
• It is asynchronous and event-driven.
• Includes callback functions.
Interface DHT11 (Humidity
Sensor) Using NodeMCU
Components Required
• Breadboard
• Micro USB Cable
• ESP8266 NodeMCU
• DHT11 Humidity and Temperature sensor
• Jumper Wires
• Arduino IDE
Interface DHT11 (Humidity
Sensor) Using NodeMCU
Connection between Node MCU
and DHT11
Node MCU and DHT
sensor Code
#include "DHT.h"
DHT dht2(2,DHT11);
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Temperature in C:");
Serial.println((dht2.readTemperature( )));
Serial.println("Humidity in C:");
Serial.println((dht2.readHumidity()));
delay(1000);
}
Connection between Node MCU and
RGB Led
• GND pin of module – GND pin of
nodemcu.
• R pin (red light) of module –
digital-
2 pin of nodemcu.
• G pin (green light) of module –
digital-1 pin of nodemcu.
• B pin (blue color) of module –
digital-0 pin of nodemcu.
Connection between Node MCU and
RGB Led
• GND pin of module – GND pin of nodemcu.
• R pin (red light) of module – digital-2 pin of nodemcu.
• G pin (green light) of module – digital-1 pin of nodemcu.
• B pin (blue color) of module – digital-0 pin of nodemcu.
Node MCU and RGB LED
Module
void setup() Code
{ // GREEN LED ON
pinMode(16,HIGH); // Blue - D0 Pin digitalWrite(16,LOW);
pinMode(5,HIGH); // Green - D1 Pin digitalWrite(5,HIGH);
pinMode(4,HIGH); // Red - D2 Pin digitalWrite(4,LOW);
} delay(1000);
void loop() // RED LED ON
{ digitalWrite(16,LOW);
// BLUE LED ON digitalWrite(5,LOW);
digitalWrite(16,HIGH); digitalWrite(4,HIGH);
digitalWrite(5,LOW); delay(1000);
digitalWrite(4,LOW); }
delay(1000);
Node MCU and RGB LED
Module
const int RED =Code
5;
const int GREEN = 4; void loop()
const int BLUE = 0; { analogWrite(RED,
50);
void setup() analogWrite(GREEN,
{ pinMode(RED, 50);
OUTPUT); analogWrite(BLUE,
pinMode(GREEN, OUTPUT); 200);
pinMode(BLUE, OUTPUT); delay (1000);
} analogWrite(RED, 100);
analogWrite(GREEN,
100);
analogWrite(BLUE,
100);
delay (1000);
}
Connection between Node MCU and
LDR Module
• GND pin of module – GND pin of
nodemcu.
• R pin (red light) of module –
digital-
2 pin of nodemcu.
•
G pin (green light) of module –
digital-1 pin of nodemcu.
•
B pin (blue color) of module –
digital-0 pin of nodemcu.
Node MCU and LDR
Module
void setup() Code
{
Serial.begin(9600); // initialize serial communication at 9600 BPS
}
void loop()
{
float voltage = sensorValue * (5.0 / 1023.0); // Convert the analog reading (which
goes from 0 - 1023) to a voltage (0 - 5V)
THANKS