0% found this document useful (0 votes)
57 views84 pages

3 NODEMCU 1st Lecture

NodeMCU is an open source IoT platform that allows developers to build connected projects using ESP8266 WiFi chip and Lua scripting. Key features of NodeMCU include 16 GPIO pins for sensor input/output, WiFi connectivity for internet access, and support for common communication protocols like I2C, SPI and UART. Using the Arduino IDE, developers can write code for NodeMCU in a similar way as Arduino, making it easy to get started with IoT projects.

Uploaded by

Sukhpreet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views84 pages

3 NODEMCU 1st Lecture

NodeMCU is an open source IoT platform that allows developers to build connected projects using ESP8266 WiFi chip and Lua scripting. Key features of NodeMCU include 16 GPIO pins for sensor input/output, WiFi connectivity for internet access, and support for common communication protocols like I2C, SPI and UART. Using the Arduino IDE, developers can write code for NodeMCU in a similar way as Arduino, making it easy to get started with IoT projects.

Uploaded by

Sukhpreet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 84

ECE282

IOT WITH NODEMCU


• NodeMCU is an open-source firmware and
hardware development environment for the
ESP8266 Wi-Fi SoC from Espressif Systems. It
includes firmware which runs on the ESP8266
chip, and hardware which is based on the ESP-
12 module. The firmware uses the Lua scripting
language, and is based on the eLua project. The
hardware design is open source, and there are
many different NodeMCU development boards
available.
• NodeMCU is a popular platform for Internet of Things
(IoT) projects. It is easy to use, and has a wide range of
features. Some of the things that you can do with
NodeMCU include:

• Control electronic devices remotely


• Collect data from sensors
• Connect to the internet
• Build web servers
• Create mobile apps
Node MCU Pin Configuration
Getting Started with Node MCU using Arduino IDE

Introduction
# NodeMCU is Lua based firmware of ESP8266. Generally, ESPlorer IDE is
referred for writing Lua scripts for NodeMCU. It requires to get familiar with
ESPlorer IDE and Lua scripting language.

#There is another way of developing NodeMCU with a well-known IDE i.e.


Arduino IDE. We can also develop NodeMCU applications using Arduino
development environment. This makes things easy for Arduino developers
than learning new language and IDE for NodeMCU.
Let’s see about setting up Arduino IDE with
NodeMCU.
• First Download Arduino IDE (version 1.6+) 
https://www.arduino.cc/en/Main/Software
• Open Arduino IDE and Go to
File -> Preference.
• Now on Preference window, Enter below link
in Additional Boards Manager URLs
• Now close Preference window and go to Tools
-> Board -> Boards Manager
• In Boards Manager window, Type esp in the
search box, esp8266 will be listed there
below. Now select latest version of board and
click on install.
• After installation of the board is complete, open Tools-
>Board->and select NodeMCU 1.0(ESP-12E Module).
• http://arduino.esp8266.com/stable/
package_esp8266com_index.json
The Breadboard
This presentation will
• Explain what a breadboard is.
• Identify reasons for using a breadboard.
• Review the guidelines and tips for proper
breadboarding.

12
What is a Breadboard?
A breadboard, sometimes called a proto-
board, is a reusable platform for temporarily
built electronic circuits.

13
How A Breadboard Works
• Electric component Top View
leads and the wire used
to connect them are
inserted into holes that
are arranged in a grid
pattern on the surface of
the breadboard. Cut-Away View
• A series of internal metal
strips serve as jumper
wires. They connect
specific rows of holes.
14
Breadboard Connections

15
16
17
18
19
20
21
What is the primary purpose of a breadboard in electronics prototyping?
A) To provide a stable base for the electronic components.
B) To supply power to the electronic circuit.
C) To interconnect and test electronic components without soldering.
D) To increase the circuit's resistance.

22
Why Breadboard?
1) It takes less time (and money) to
breadboard a circuit than to design and
fabricate a printed circuit board (PCB).
Because of the cost, a PCB should be
reserved for the final working design.
2) As a complement to circuit simulation,
breadboarding allows the designer to see
how, and if, the actual circuit functions.

23
Why Breadboard?
3) Breadboards give the designer the ability
to quickly change components during
development and testing, such as
swapping resistors or capacitors of
different values.
4) A breadboard allows the designer to
easily modify a circuit to facilitate
measurements of voltage, current, or
resistance.
24
Breadboard: Guidelines and Tips
• Use as few jumper wires as possible. The
breadboard should be used to make the
majority of the connections between the
components.
• Keep jumper wires as short as possible. A
jumble of wires is difficult to troubleshoot.
• Breadboard a circuit so that it looks as close as
possible to the layout of the schematic circuit.
This makes troubleshooting easier.

25
Breadboard: Guidelines and Tips
• Place IC chips in the middle of the breadboard.
• Work from a schematic and check off the
component and wires as they are implemented
on the breadboard.
• Cut component leads to manageable lengths.
Component leads that are too long may touch
and short each other out.
• Have someone check your circuit for errors.

26
• Now Your Arduino IDE is ready for NodeMCU
• Example
• Let’s see how to write simple serial print
sketch using Arduino IDE for NodeMCU.
• First connect NodeMCU Development Kit with
PC as shown in below figure.
Node-MCU pin details
• The NodeMCU ESP8266 development board comes with the
ESP-12E module containing ESP8266 chip having Tensilica
Xtensa 32-bit LX106 RISC microcontroller.
• This microcontroller supports RTOS and operates at 80MHz to
160 MHz adjustable clock frequency.
• NodeMCU has 128 KB RAM and 4MB of Flash memory to
store data and programs.
• Its high processing power with in-built Wi-Fi / Bluetooth and
Deep Sleep Operating features make it ideal for IoT projects.
• NodeMCU can be powered using Micro USB jack and VIN pin
(External Supply Pin). It supports UART, SPI, and I2C interface.
NodeMCU ESP8266 Specifications & Features
• Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106
• Operating Voltage: 3.3V
• Input Voltage: 7-12V
• Digital I/O Pins (DIO): 16
• Analog Input Pins (ADC): 1
• UARTs: 1
• SPIs (Serial Peripheral Interface): 1
• I2Cs (inter-integrated controller): 1
• Flash Memory: 4 MB
• SRAM: 64 KB
• Clock Speed: 80 MHz
• USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
• PCB Antenna
• Small Sized module to fit smartly inside your IoT projects
NodeMCU Development Board Pinout Configuration

Pin Category Name Description


Power Micro-USB, 3.3V, GND, Micro-USB: NodeMCU can be
Vin powered through the USB port
 3.3V: Regulated 3.3V can be
supplied to this pin to power the
board
 GND: Ground pins
 Vin: External Power Supply

Control Pins EN, RST The pin and the button resets the
microcontroller
Analog Pin A0 Used to measure analog voltage in
the range of 0-3.3V
GPIO Pins GPIO1 to GPIO16 NodeMCU has 16 general purpose
input-output pins on its board
SPI Pins SD1, CMD, SD0, CLK NodeMCU has four pins available for
SPI communication.
UART Pins TXD0, RXD0, TXD2, RXD2 NodeMCU has two UART
interfaces, UART0 (RXD0 &
TXD0) and UART1 (RXD1 &
TXD1). UART1 is used to upload
the firmware/program.
I2C Pins NodeMCU has I2C functionality
support but due to the internal
functionality of these pins, you
have to find which pin is I2C.
PIN Mapping
On-board Switches & LED Indicator
Serial Communication
Serial Communication
• You can use the Arduino IDE environment’s
built-in serial monitor to communicate with an
ESP board.
•  Click the Tools>>Serial monitor button in the
toolbar and select the same baud rate used in
the call to begin().
commonly used serial commands
• Serial.begin(9600);
• Serial.print(); and Serial.println(): Serial.print
prints text on same line. Seial.println puts
carriage return at the end of line.
• Serial.write();
• Serial.available();
• Serial.read();
• ESP8266 Wi-Fi Module:
• The NodeMCU board is centered around the
ESP8266 Wi-Fi module, which provides Wi-Fi
connectivity to your projects.
• You can connect to Wi-Fi networks, create a
web server, and communicate with cloud
services.
• GPIO Pins:

• The NodeMCU board has a number of GPIO (General Purpose


Input/Output) pins that can be used for digital input/output and
analog input.
• These pins can be used to control LEDs, read sensors, interface
with other digital components, and more.
• Analog Inputs:

• The NodeMCU board has a few analog pins that can be used to
read analog sensor values, such as light intensity or temperature.
• I2C (Inter-Integrated Circuit):

• The NodeMCU has support for I2C communication through its GPIO pins,
allowing you to connect I2C devices like sensors and displays.
• SPI (Serial Peripheral Interface):

• The NodeMCU supports SPI communication, which is useful for connecting


to devices like external flash memory, displays, and sensors.
• UART (Universal Asynchronous Receiver-Transmitter):

• The NodeMCU supports UART communication, enabling serial


communication with other devices like GPS modules, Bluetooth modules,
and more.
• PWM (Pulse Width Modulation):

• Some of the GPIO pins on the NodeMCU can be configured for PWM output, which is useful for
controlling things like motor speed or LED brightness.
• USB-to-Serial Converter:
• The NodeMCU board typically includes a USB-to-Serial converter chip, making it easy to
connect the board to your computer for programming and debugging.
• Reset and Flash Buttons:
• The board often includes buttons for resetting the board and putting it into flash mode for
uploading firmware.
• Voltage Regulator:
• The NodeMCU board usually includes a voltage regulator that allows you to power the board
using a wider range of voltage inputs.
• Integrated LEDs:

• The NodeMCU board often includes built-in LEDs that can be controlled for various purposes.
Supported Peripheral

• The NodeMCU board has a set of GPIO


(General Purpose Input/Output) pins that you
can use for various purposes. Here is a list of
some of the commonly used pins on a
NodeMCU board along with their
functionalities:
• D0 (GPIO16): General-purpose digital I/O pin. Also used for waking up the ESP8266
from deep sleep mode.

• D1 (GPIO5): General-purpose digital I/O pin.

• D2 (GPIO4): General-purpose digital I/O pin.

• D3 (GPIO0): General-purpose digital I/O pin. Also used for determining boot mode
(connected to ground for normal boot, disconnected for firmware upload).

• D4 (GPIO2): General-purpose digital I/O pin.

• D5 (GPIO14): General-purpose digital I/O pin. Also used for SPI clock when the SPI
interface is enabled.
• D6 (GPIO12): General-purpose digital I/O pin. Also used for SPI MISO (Master In Slave Out)
when the SPI interface is enabled.

• D7 (GPIO13): General-purpose digital I/O pin. Also used for SPI MOSI (Master Out Slave In)
when the SPI interface is enabled.

• D8 (GPIO15): General-purpose digital I/O pin. Also used for SPI CS (Chip Select) when the SPI
interface is enabled.

• RX (GPIO3): Serial input pin (UART receive). Used for communication with other devices using
UART.

• TX (GPIO1): Serial output pin (UART transmit). Used for communication with other devices
using UART.

• A0 (ADC0): Analog input pin. Used for reading analog sensor values
• After setting up Arduino IDE for NodeMCU, open Arduino IDE and write
simple sketch of serial print as shown in below figure.
• Ensure that you have selected the correct board as shown in below
figure. Also make sure that you have selected the appropriate COM port.
• Now compile & upload the written sketch directly to the NodeMCU Dev
Kit by clicking on upload button.
Practice programs
• P1: Print Hello Word and Your name on Serial
monitor?
• P2: Print decimal numbers in BIN, OCTAL,
DECIMAL and HEX-DECIMAL number system?
• #define LED D1 // Led in NodeMCU at pin GPIO16 (D0).
• void setup() {
• pinMode(LED, OUTPUT); // set the digital pin as output.
• }
• void loop() {
• digitalWrite(LED, HIGH);// turn the LED off.(Note that LOW is the voltage
level but actually
• //the LED is on; this is because it is acive low on the ESP8266.
• delay(1000); // wait for 1 second.
• digitalWrite(LED, LOW); // turn the LED on.
• delay(1000); // wait for 1 second.
• }
Ans:
• Serial.print(78, BIN) gives “1001110”
• Serial.print(78, OCT) gives “116”
• Serial.print(78, DEC) gives “78”
• Serial.print(78, HEX) gives “4E”
• Serial.println(1.23456, 0) gives “1”
• Serial.println(1.23456, 2) gives “1.23”
• Serial.println(1.23456, 4) gives “1.2346”
Practice Program
• 1. LED blinking without/with Switch
• 2. LED blinking rate with Potentiometer
GPIO Input Example:
• int ledpin = 5; // D1(gpio5)
int button = 4; //D2(gpio4)
• int buttonState=0;
• void setup() {
• pinMode(ledpin, OUTPUT);
• pinMode(button, INPUT);
• }
• void loop() {
• buttonState=digitalRead(button); // put your main code here, to run repeatedly:
• if (buttonState == 1)
• {
• digitalWrite (ledpin, HIGH);
• delay(200);
• }
• if (buttonState==0)
• {
• digitalWrite(ledpin, LOW);
• delay(200);
• }
• }
Video link
• https://www.youtube.com/watch?v=9VEpZlkN
0r0
• https://www.youtube.com/watch?v=HBSH_x6
J1lY
GPIO Output Example:

• void setup() {
• pinMode(LED_BUILTIN, OUTPUT);
• }
• void loop() {
• digitalWrite(LED_BUILTIN, LOW);
• delay(1000); // Wait for a second
• digitalWrite(LED_BUILTIN, HIGH); // Turn the LED off by making
the voltage HIGH
• delay(2000); // Wait for two seconds (to
demonstrate the active low LED)
• }
Code for potentiometer led blink
Experiment
• Programming NodeMCU for DHT11
DHT11

• Humidity is the measure of water vapour present in the air. The level of
humidity in air affects various physical, chemical and biological processes. 
• In industrial applications, humidity can affect the business cost of the
products, health and safety of the employees. So, in semiconductor
industries and control system industries measurement of humidity is very
important.
•  Humidity measurement determines the amount of moisture present in the
gas that can be a mixture of water vapour, nitrogen, argon or pure gas etc.
• DHT11 is a digital temperature and humidity sensor.
• DHT11 is a low-cost digital sensor for sensing temperature and humidity.  This
sensor can be easily interfaced with any micro-controller such as Arduino,
Raspberry Pi etc… to measure humidity and temperature instantaneously

• They consist of a humidity sensing


component, a NTC temperature sensor (or
thermistor) and an IC on the back side of the
sensor.
• For measuring humidity they use the humidity sensing component which has
two electrodes with moisture holding substrate between them. So as the
humidity changes, the conductivity of the substrate changes or the resistance
between these electrodes changes. This change in resistance is measured and
processed by the IC which makes it ready to be read by a microcontroller.
• On the other hand, for measuring temperature these sensors use a NTC
temperature sensor or a thermistor.
• A thermistor is actually a variable resistor that changes its resistance with change
of the temperature.
•  The term “NTC” means “Negative Temperature Coefficient”, which means that the
resistance decreases with increase of the temperature.
Features of DHT11
• Ultra-low cost
• 3 to 5V power and I/O
• 2.5mA max current
• Good for 20-80% humidity readings with 5%
accuracy
• Good for 0-50°C temperature readings ±2°C
accuracy
• Body size 15.5mm x 12mm x 5.5mm
• 4 pins with 0.1" spacing
Pin Description:
• DHT11 is a 4-pin sensor, these pins are VCC,
DATA, GND and one pin is not in use shown in
fig below.
Pin Pin
Pin Description
No. Name
Power supply
1 VCC 3.3 to 5.5 Volt
DC
Digital output
2 DATA
pin
3 NC Not in use
4 GND Ground
• dht.read(): This function is used to read data
from all kinds of DHT sensors, including
DHT11, 21, 22, 33, 44 humidity temperature
sensors.
• Syntax: dht.read(pin)
• Parameters: pin: pin number from which
output of DHT sensor is to be read.
#include <Adafruit_Sensor.h> void loop()
#include "DHT.h" {
#define DHTPIN 2 delay(2000);
#define DHTTYPE DHT11 float h = dht.readHumidity();
DHT dht(DHTPIN, DHTTYPE); float t = dht.readTemperature();
void setup() Serial.print("Humidity: \t" );
{ Serial.print(h);
Serial.begin(9600); Serial.print(" %\n");
Serial.println("DHT11 test!"); delay(500);
dht.begin(); Serial.print("Temperature: \t");
} Serial.print(t);
Serial.print(" *C \n");
}
Video links
• Interfacing of DHT11 with NodeMCU and data
shared on Blynk app
• https://www.youtube.com/watch?v=jYjuxWU
efhg
• Light Emitting Diode, is a semiconductor
device that emits light when an electric
current passes through it. LEDs are a type of
solid-state lighting technology that has gained
immense popularity due to their energy
efficiency, longevity, and versatility. They have
revolutionized the way we illuminate our
world, replacing traditional incandescent and
fluorescent lights in many applications.
• The positive side of the LED is called the "anode"
and is marked by having a longer "lead," or leg.
The other, negative side of the LED is called the
"cathode." Current flows from the anode to the
cathode and never the opposite direction. A
reversed LED can keep an entire circuit from
operating properly by blocking current flow. So
don't freak out if adding an LED breaks your
circuit. Try flipping it around.
Applications

• Indicator lights in electronic devices


• Backlights for LCD displays
• Traffic lights
• Automotive lighting
• LED light bulbs
• Smart home lighting: LEDs can be used to create smart home
lighting systems that can be controlled by a smartphone or
tablet. For example, you could use LEDs to turn on the lights
when you come home or to create a different lighting mood
for different occasions.
• IoT sensors: LEDs can be used as sensors in IoT applications.
For example, you could use an LED to measure the
temperature of a room or to detect motion.
• IoT displays: LEDs can be used to create IoT displays that can
show information such as time, weather, or traffic conditions.
LED
• const int ledPin = 2; // LED connected to digital pin 13
• void setup()
• {
• pinMode(ledPin, OUTPUT);
• }
• void loop()
• {
• digitalWrite(ledPin, HIGH); // set the LED on
• delay(2000); // wait for two seconds
• digitalWrite(ledPin, LOW); // set the LED off
• delay(2000); // wait for two seconds
• }
Ultrasonic Sensor

• An Ultrasonic sensor is a device that can measure the distance to an object


by using sound waves.
• It measures distance by sending out a sound wave at a specific frequency
and listening for that sound wave to bounce back.
• By recording the elapsed time between the sound wave being generated
and the sound wave bouncing back, it is possible to calculate the distance
between the sonar sensor and the object.
Ultrasonic Sensor (Cont..)

• Since it is known that sound travels through air at about 344 m/s
(1129 ft/s), you can take the time for the sound wave to return and
multiply it by 344 meters (or 1129 feet) to find the total round-trip
distance of the sound wave.

• Round-trip means that the sound wave traveled 2 times the distance
to the object before it was detected by the sensor; it includes the 'trip'
from the sonar sensor to the object AND the 'trip' from the object to
the Ultrasonic sensor (after the sound wave bounced off the object).

• To find the distance to the object, simply divide the round-trip


distance in half.
Working principle

The Trig pin will be used to send the signal and


the Echo pin will be used to listen for returning signal
(1) Using IO trigger for at least 10us high level signal,
(2) The Module automatically sends eight 40 kHz and detect whether there is a pulse
signal back.
(3) IF the signal back, through high level , time of high output IO duration is the time
from sending ultrasonic to returning.
const int trigPin = 4; // output
const int echoPin = 5; // Input

NodeMCU pin 4 (GPIO) is connected with Trigpin


of sensor
NodeMCU pin 5 (GPIO) is connected with Echo
pin of Sensor
Arduino Sketch

/*
* Ultrasonic Sensor HC-SR04 Tutorial
*/
// defines pins numbers
const int trigPin = 4;
const int echoPin = 5;
// defines variables
long duration;
int distance;

void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
Arduino Sketch (Cont..)
void loop()
{ // Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microsec.
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
delay(500);
}
Proteus design

You might also like