IoT Sensors and Actuators Lab Manual
IoT Sensors and Actuators Lab Manual
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
NodeMCU is a development board featuring the popular ESP8266 WiFi chip.
As it turns out, you can program the ESP8266 just like any other microcontroller. Its obvious
advantage over the Arduino or PIC is that it can readily connect to the Internet via WiFi
Features:
Pin Diagram:
Pin Description:
1) Power Pin: There are four power pins viz. one VIN pin & three 3.3V pins. The VIN pin can
be used to directly supply the ESP8266 and its peripherals if you have a regulated 5V voltage
source. The 3.3V pins are the output of an on-board voltage regulator. These pins can be used to
supply power to external components.
2) GND: GND is a ground pin of ESP8266 NodeMCU development board.
3) I2C Pins: I2C Pins are used to hook up all sorts of I2C sensors and peripherals in your
project. Both I2C Master and I2C Slave are supported. I2C interface functionality can be
realized programmatically, and the clock frequency is 100 kHz at a maximum. It should be noted
that I2C clock frequency should be higher than the slowest clock frequency of the slave device.
4) GPIO Pins: ESP8266 NodeMCU has 17 GPIO pins which can be assigned to various
functions such as I2C, I2S, UART, PWM, IR Remote Control, LED Light, and Button
programmatically. Each digital enabled GPIO can be configured to internal pull-up or pull-down
or set to high impedance. When configured as an input, it can also be set to edge-trigger or level-
trigger to generate CPU interrupts.
5) ADC Channel: The NodeMCU is embedded with a 10-bit precision SAR ADC. The two
functions can be implemented using ADC viz. Testing power supply voltage of VDD3P3 pin and
testing input voltage of TOUT pin. However, they cannot be implemented at the same time.
6) UART Pins: ESP8266 NodeMCU has 2 UART interfaces, i.e. UART0 and UART1, which
provide asynchronous communication (RS232 and RS485), and can communicate at up to 4.5
Mbps. UART0 (TXD0, RXD0, RST0 & CTS0 pins) can be used for communication. It supports
fluid control. However, UART1 (TXD1 pin) features only data transmit signal so, it is usually
used for printing log.
7) SPI Pins: ESP8266 features two SPIs (SPI and HSPI) in slave and master modes. These SPIs
also support the following general-purpose SPI features:
8) SDIO Pins: ESP8266 features Secure Digital Input/output Interface (SDIO) which is used to
directly interface SD cards. 4-bit 25 MHz SDIO v1.1 and 4-bit 50 MHz SDIO v2.0 are
supported.
9) PWM Pins: The board has 4 channels of Pulse Width Modulation (PWM). The PWM output
can be implemented programmatically and used for driving digital motors and LEDs. PWM
frequency range is adjustable from 1000 μs to 10000 μs, i.e., between 100 Hz and 1 kHz.
10) Control Pins: Control Pins are used to control ESP8266. These pins include Chip Enable pin
(EN), Reset pin (RST) and WAKE pin. EN pin – The ESP8266 chip is enabled when EN pin is
pulled HIGH. When pulled LOW the chip works at minimum power. RST pin – RST pin is used
to reset the ESP8266 chip. WAKE pin – Wake pin is used to wake the chip from deep-sleep.
4. Step 4 – Now choose the COM port on which the NodeMCU is connected
5. Step 5 – Your Arduino IDE is ready to program the NodeMCU
To blink the built-in LEDs, we must only connect NodeMCU to the computer using a
micro USB cable. No external component is required.
Fig: Built-in LEDs of NodeMCU
This code is to blink built-in LEDs of NodeMCU. The on-board LED of ESP8266 is connected
to GPIO2 and the LED on NodeMCU board is connected to GPIO16.The NodeMCU ESP8266
board has two of those LEDs. One on the NodeMCU PCB and another on the ESP-12 module’s
PCB. Both LEDs operate in “inverted” mode, with regard to the pin levels - when the pin is
HIGH, the LED is off; when the pin is LOW, the LED is on. The LED on GPIO2 flashes during
ESP programming, as it is connected to the U1TXD pin.
Code:
Fig: LED
Digital means either 0/1, in other words HIGH/LOW or ON/OFF. So, in the form of digital
output we shall get either +3.3V or 0V on digital pin of Arduino.
PRECAUTIONS:
1. Check the sensor is working properly.
2. Check the connections are properly connected.
3. See that there are no errors in the code.
4. Check whether Ground and VCC connections are connected properly.
RESULT: Successfully implemented & Blink an On-Board LED and external LED on
NodeMCU.
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
A potentiometer is a simple mechanical device that provides a varying amount of resistance
when its shaft is turned. By passing voltage through a potentiometer and into an analog input on
your board, it is possible to measure the amount of resistance produced by a potentiometer
(or pot for short) as an analog value. To read an analog signal through the NodeMCU, Analog to
Digital conversion is required. Analog to Digital Converter (ADC) is used to convert analog
signal into digital form. A NodeMCU has inbuilt 10-bit ADC with only one ADC channel i.e. it
has only one ADC input pin to read analog voltage from external device. NodeMCU has on
board register divider network which provide 3.3V to the ADC pin of ESP8266. Hence, we can
use 0–3.3V range for ADC input voltage. Since ADC is of 10-bit resolution, it will give 0-1023
value range for ADC input voltage 0-3.3V on development Kit.
Fig: Potentiometer
ESP8266 ADC pin on NodeMCU Kit
INTERFACING DIAGRAM
Fig: NodeMCU interface with Potentiometer
Connect the three wires from the potentiometer to your board. The first goes from one of the
outer pins of the potentiometer to ground. The second goes from the other outer pin of the
potentiometer to 3.3 volts. The third goes from the middle pin of the potentiometer to the analog
pin A0. The ADC inside the microcontroller converts the input voltage range, 0 to 3.3 volts, to a
digital value between 0 and 1023 using the command analogRead().
By turning the shaft of the potentiometer, you change the amount of resistance on either side of
the center pin (or wiper) of the potentiometer. This changes the relative resistances between the
center pin and the two outside pins, giving you a different voltage at the analog input. When the
shaft is turned all the way in one direction, there is no resistance between the center pin and the
pin connected to ground. The voltage at the center pin then is 0 volts, and analogRead() returns
0. When the shaft is turned all the way in the other direction, there is no resistance between the
center pin and the pin connected to +5 volts. The voltage at the center pin then is 5 volts, and
analogRead() returns 1023. In between, analogRead() returns a number between 0 and 1023 that
is proportional to the amount of voltage being applied to the pin.
In the sketch below, the only thing that you do in the setup function is to begin serial
communications, at 9600 (or 115200) bits of data per second (bps), between your board and your
computer with the command:
Serial.begin(115200);
Next, in the main loop of your code, you need to establish a variable to store the resistance value
(which will be between 0 and 1023, perfect for an ‘int ‘ datatype) coming in from your
potentiometer:
Finally, you need to print this information to your serial monitor window. You can do this with
the command Serial.println () in your last line of code:
Serial.println(sensorValue);
Now, when you open your Serial Monitor in the Arduino Software (IDE) (by clicking the icon
that looks like a lens, on the right, in the green top bar or using the keyboard shortcut
Ctrl+Shift+M), you should see a steady stream of numbers ranging from 0-1023, correlating to
the position of the pot. As you turn your potentiometer, these numbers will respond almost
instantly.
Code:
void setup() {
PRECAUTIONS:
1. Check the potentiometer is working properly.
RESULT: Successfully implemented and verify the digital values by varying the resistance of
the potentiometer in serial monitor through NodeMCU.
3. LDR INTERFACING WITH NODEMCU
OBJECTIVE: To read the output voltage of LDR whose resistance changes depending upon
the intensity of incident light and display the voltage values in serial monitor.
COMPONENTS REQUIRED:
1) NodeMCU – 1
2) Micro USB Cable – 1
3) PC – 1
4) Jumper Wires.
5) Bread Board.
6) Resistor- 1 (10k ohm)
7) LDR / photoresistor
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
An LDR or light dependent resistor is also known as photo resistor, photocell, photoconductor. It
is a one type of resistor whose resistance varies depending on the amount of light falling on its
surface. When the light falls on the resistor, then the resistance changes. These resistors are often
used in many circuits where it is required to sense the presence of light. These resistors have a
variety of functions and resistance. For instance, when the LDR is in darkness, then it can be
used to turn ON a light or to turn OFF a light when it is in the light. A typical light dependent
resistor has a resistance in the darkness of 1MOhm, and in the brightness a resistance of a couple
of KOhm.
Fig: LDR and its symbol
Working Principle of LDR
This resistor works on the principle of photo conductivity. It is nothing but, when the light falls
on its surface, then the material conductivity reduces and the electrons in the valence band of the
device are excited to the conduction band. These photons in the incident light must have energy
greater than the band gap of the semiconductor material. This makes the electrons to jump from
the valence band to conduction.
These devices depend on the light, when light falls on the LDR then the resistance decreases and
increases in the dark. When LDR is kept in the dark place, its resistance is high and, when the
LDR is kept in the light its resistance will decrease.
INTERFACING DIAGRAM
The connections are made as shown in the below image. One leg of LDR is connected to analog
pin (A0) and other leg is connected to 3.3v of NodeMCU. One end of the 10k resistor is
connected across the same analog leg of LDR and the other end is grounded.
In the sketch below, the only thing that you do in the setup function is to begin serial
communications, at 9600 bits of data per second (bps), between your board and your computer
with the command:
Serial.begin(9600);
Next, in the main loop of your code, you need to establish a variable to store the resistance value
(which will be between 0 and 1023, perfect for an ‘int ‘ datatype) coming in from your
potentiometer:
int sensorValue = analogRead(A0);
Finally, you need to print this information to your serial monitor window. You can do this with
the command Serial.println () in your last line of code:
Serial.println(sensorValue);
Now, when you open your Serial Monitor in the Arduino Software (IDE) (by clicking the icon
that looks like a lens, on the right, in the green top bar or using the keyboard shortcut
Ctrl+Shift+M), you should see a steady stream of numbers ranging from 0-1023, correlating to
the position of the pot. As you turn your potentiometer, these numbers will respond almost
instantly.
Code:
void setup() {
float Voltage = sensorValue* (3.3/1023.0) // convert the analog reading (0-1023) to a voltage
(0-3.3V)
PROCEDURE:
1. Make the connections as per the circuit diagram.
2. Check the ground connection precisely before switching on the power supply.
3. Connect Micro USB Cable to PC.
4. By varying the incident light on LDR, observe the voltage and note down the readings.
5. Write the Code in C/C++ accordingly.
6. Run the code through Arduino IDE and Observe the output.
PRECAUTIONS:
1. Check the potentiometer is working properly.
RESULT: Successfully implemented and verify the digital and analog voltage values in serial
monitor by varying the incident light on LDR through NodeMCU.
4. TEMPERATURE AND HUMIDITY MONITORING IN
CLOUD PLATFORM
OBJECTIVE: To read the ambient temperature and humidity by interfacing the DHT11
sensor with NodeMCU and monitor in cloud platform using esp8266.
COMPONENTS REQUIRED:
1) NodeMCU
2) DHT11 – Temperature and Humidity Sensor
3) Micro USB Cable
4) PC
5) Bread Board
6) Jumper Wires
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
DHT11 Sensor
The DHT11 detects water vapor by measuring the electrical resistance between two electrodes.
The humidity sensing component is a moisture holding substrate with electrodes applied to the
surface. When water vapor is absorbed by the substrate, ions are released by the substrate which
increases the conductivity between the electrodes. The change in resistance between the two
electrodes is proportional to the relative humidity. Higher relative humidity decreases the
resistance between the electrodes, while lower relative humidity increases the resistance between
the electrodes. It can measure relative humidity in percentage (20 to 90% RH) and temperature in
degree Celsius in the range of 0 to 50°C.
There are two different versions of the DHT11 you might come across. One type has four
pins, and the other type has three pins and is mounted to a small PCB. The PCB mounted version
is nice because it includes a surface mounted 10K Ohm pull up resistor for the signal line. Here
are the pin outs for both versions.
DHT11 Specifications:
NodeMCU
NodeMCU is an open source development board and firmware based in the widely
used ESP8266 -12E WiFi module. It allows you to program the ESP8266 WiFi module with the
simple and powerful LUA programming language or Arduino IDE. ESP8266 Wi-Fi
transceiver is one of the most popular WiFi modules for IoT based Applications. With just a few
lines of code you can establish a WiFi connection and define input/output pins according to your
needs exactly like arduino, turning your ESP8266 into a web server and a lot more. It is the WiFi
equivalent of ethernet module. Now you have internet of things (IoT) real tool. With its USB-
TTL, the NodeMCU Dev board supports directly flashing from USB port. It combines features
of WIFI access point and station + microcontroller. These features make the NodeMCU
extremely powerful tool for Wifi networking. It can be used as access point and/or station, host a
webserver or connect to internet to fetch or upload data.
Features:
Finally, programable WiFi module.
Arduino-like (software defined) hardware IO.
Can be programmed with the simple and powerful Lua programming language or Arduino
IDE.
USB-TTL included, plug & play.
10 GPIOs D0-D10, PWM functionality, IIC and SPI communication, 1-Wire and ADC A0
etc. all in one board.
Wifi networking (can be used as access point and/or station, host a web server), connect to
internet to fetch or upload data.
Event-driven API for network applications.
PCB antenna.
ThingSpeak
Thingspeak is a data platform for monitoring your data online, targeted to be used for IoT
applications. In ThingSpeak channel you can set the data as private or public according to your
choice. ThingSpeak takes minimum of 15 seconds to update your readings.
Here, we are going to send Temperature and Humidity sensor data to Thingspeak
using DHT11. By this method we can monitor our DHT11 sensor’s temperature and humidity
data over internet using Thingspeak IOT server, and we can view the logged data and graph over
time on the ThingSpeak dashboard. NodeMCU reads the current temperature and humidity from
DHT11 and sends it to ThingSpeak server for live monitoring from anywhere in the world.
INTERFACING DIAGRAM
Fig: NodeMCU interface with DHT11
Procedure
Wiring the DHT11 to the NodeMCU is easy, but the connections are different depending on
which type you have either 3-pins or 4-pins. The wiring connections are made as follows:
Signal pin of the DHT11 goes into Digital Pin D4 of the NodeMCU. (D4 is the GPIO 2
of NodeMCU)
VCC pin of the DHT11 goes into +3v of the NodeMCU.
GND pin of the DHT11 goes into Ground Pin (GND) of the NodeMCU.
Before you use the DHT11 with NodeMCU, you need to install the DHT11 library. It has all the
functions needed to get the humidity and temperature readings from the sensor.
Open up the Arduino IDE, then go to Sketch > Include Library > Manage
Libraries > Search DHT Sensor. Click on that entry, and then select Install.
Once the library has been added to the Arduino IDE, open the IDE and open the example sketch
named DHT_Test from the library added.
#include <DHT.h>
#include <ESP8266WiFi.h>
String apiKey = "Your API KEY"; // Enter your Write API key here
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
delay(550);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected");
void loop()
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
return;
}
if (client.connect(server,80))
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n")
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(h);
}
client.stop();
Serial.println("Waiting...");
delay(10000);
For creating your channel on ThingSpeak you first need to sign up on ThingSpeak. In case if you
already have account on ThingSpeak just sign in using your id and password.
Click on signup if you don’t have account and if you already have account click on sign in.
Once you Sign in after your account verification, Create a new channel by clicking “New
Channel” button
After clicking on “New Channel”, enter the Name and Description of the data you want to
upload on this channel. For example, I am sending DHT11 sensor data (temperature and
humidity), so I named it as “DHT11”.
Enter the name of your data ‘Temperature’ in Field1 and ‘Humidity’ in Field2. If you want to use
more than one Field, you can check the box next to Field option and enter the name and
description of your data.
To send data to ThingSpeak, we need an unique API key, which we will use later in our code to
upload the Temperature and Humidity to ThingSpeak Website.
Click on “API Keys” button to get your unique API key for uploading DHT11 sensor data.
Now copy your “Write API Key”. We will use this API key in our code.
After this, navigate to your Thingspeak page and open your channel in ThingSpeak and output
will be displayed.
OUTPUT
Once code uploading is done open serial monitor to see whether wifi is connected or not. Make
sure the baud rate should be 115200. If wifi is connected then you can see the temperature and
humidity values displayed and data will be sent to thingspeak.
Open thingspeak channel and select pubic/private view. Here you can see the data uploaded after
the interval of 15 seconds.
Fig: Temperature & Humidity data monitoring in ThingSpeak (Output)
PROCEDURE:
PRECAUTIONS:
RESULT: Successfully implemented & monitored temperature and humidity in cloud platform
using ESP8266.
5. GAS SENSOR DETECTION USING NODEMCU AND
MONITORING IN CLOUD PLATFORM
OBJECTIVE: To interface the MQ-2 gas sensor with NodeMCU and monitor the values in
cloud platform using esp8266.
COMPONENTS REQUIRED:
1) NodeMCU
2) MQ-2 Gas Sensor
3) Micro USB Cable
4) PC
5) Bread Board
6) Jumper Wires
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
MQ2 gas sensor is an electronic sensor used for sensing the concentration of gases in the air such
as LPG, propane, methane, hydrogen, alcohol, smoke and carbon monoxide. It is also known as
chemiresistor. It contains a sensing material whose resistance changes when it comes in contact
with the gas. This change in the value of resistance is used for the detection of gas. MQ2 is
a metal oxide semiconductor type gas sensor. Concentrations of gas in the gas is measured using
a voltage divider network present in the sensor. These voltage values are measured to know the
concentration of gas. The output voltage from the Gas sensor increases with the
concentration of gas. This sensor works on 5V DC voltage. It can detect gases in the
concentration of range 200 to 10000ppm.
Fig: MQ-2 Gas sensor
Pin Description:
1 Vcc This pin powers the module, typically the operating voltage is +5V
3 Digital You can also use this sensor to get digital output from this pin, by
Out setting a threshold value using the potentiometer
4 Analog This pin outputs 0-5V analog voltage based on the intensity of the gas
Out
Features:
Operating Voltage is +5V
Can be used to Measure or detect LPG, Alcohol, Propane, Hydrogen, CO and even
methane
Analog output voltage: 0V to 5V
Digital Output Voltage: 0V or 5V (TTL Logic)
Preheat duration 20 seconds
Can be used as a digital or analog sensor
The Sensitivity of Digital pin can be varied using the potentiometer
INTERFACING DIAGRAM
1. Connect VCC pin of MQ-2 Gas Sensor module to Vin pin of NodeMCU ESP8266-12E
Board.
2. Connect GND pin of MQ-2 Gas Sensor module to GND pin of NodeMCU pin of
ESP8266-12E Board.
3. Connect D0 pin of MQ-2 Gas Sensor module to the A0 pin of NodeMCU ESP8266-12E
board.
const char *ssid = "…………"; // replace with your wifi ssid and wpa2 key
WiFiClient client;
void setup()
Serial.begin(115200);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected");
void loop()
float h = analogRead(A0);
if (isnan(h))
postStr += "&field1=";
postStr += String(h/1023*100);
postStr += "r\n";
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.println(h/1023*100);
delay(500);
client.stop();
Serial.println("Waiting...");
2. Create a new channel by clicking on the button. Enter the basic details of the channel. Then
Scroll down and save the channel.
3. To send data to ThingSpeak, we need a unique API key. Click on “API Keys” button to get your
unique API key. Copy your API key and Paste in your Code for uploading Gas sensor data to
Thingspeak website.
4. Make sure to change the Wifi SSID, Password API key in the code.
After this, navigate to your Thingspeak page and open your channel in ThingSpeak and output
will be displayed.
OUTPUT
Once code uploading is done open serial monitor to see whether wifi is connected or not. Make
sure the baud rate should be 115200. If wifi is connected, then you can see the gas level
displayed in percentage and data will be sent to ThingSpeak.
Open ThingSpeak channel and select public/private view. Here you can see the data uploaded
after the interval of 15 seconds.
Fig: Gas Sensor data monitoring in ThingSpeak (Output)
PROCEDURE:
1. Make the connections as per the circuit diagram.
2. Check the ground connection precisely before switching on the power supply.
3. Connect Micro USB Cable to PC.
4. Introduce gas or smoke or perfume at the MQ-2 and see the changes in a rise in the
percentage value of gas level.
5. Observe the voltage and note down the readings.
6. Write the Code in C/C++ accordingly.
7. Run the code through Arduino IDE and Observe the output.
PRECAUTIONS:
RESULT:-
Hence the gas sensor senses the harmful gases present around it, by using NODEMCU
microcontroller.
COMPONENTS REQUIRED:
1) NodeMCU
4) PC
5) Bread Board
6) Jumper Wires
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
Soil moisture is basically the content of water present in soil. This can be measured using a soil
moisture sensor which consists of two conducting probes that act as a probe. It can measure the
moisture content in the soil based on the change in resistance between the two conducting plates.
The resistance between the two conducting plates varies in an inverse manner with the amount of
moisture present in the soil. When the sensor is inserted into the water, the resistance will
decrease and get better conductivity between plates.
The analog output of soil moisture sensor is processed using ADC. The moisture content in terms
of percentage is displayed on the serial monitor.
The output of the soil moisture sensor changes in the range of ADC value from 0 to 1023. This
can be represented as moisture value in terms of percentage using formula given below.
For zero moisture, we get maximum value of 10-bit ADC, i.e. 1023. This in turn gives ~0%
moisture.
NodeMCU ADC can be used to measure analog voltage from soil moisture sensor.
INTERFACING DIAGRAM
Fig: Soil Moisture Sensor FC-28 Interface with NodeMCU
The wiring connections are made as follows:
1. Connect the two pins of the moisture sensor to the two pins on the Amplifier circuit
using jumper wires.
2. Connect the Vcc from the Amplifier to the 3.3V pin on the NodeMCU.
3. Connect the GND pin to the ground (GND) pin on the NodeMCU.
4. Connect the Analog pin to the A0 pin on the NodeMCU.
5. Connect NodeMCU to PC via a USB cable.
After your completed with wiring connections, then insert the sensor into the soil or place it in
anywhere you want.
const int sensor_pin = A0; // Connect Soil moisture analog sensor pin
to A0 of NodeMCU
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi connected");
void loop()
int moisture_percentage;
Serial.print(moisture_percentage);
Serial.println("%");
postStr += "&field1=";
postStr += String(moisture_percentage);
postStr += "r\n";
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
client.stop();
Serial.println("Waiting...");
delay(2000); // ThingSpeak needs minimum 15 sec delay
between updates.
}
After this, navigate to your Thingspeak page and open your channel in ThingSpeak and output
will be displayed.
OUTPUT
Once code uploading is done open serial monitor to see whether wifi is connected or not. Make
sure the baud rate should be 115200. If wifi is connected, then you can see the moisture level
displayed in percentage and data will be sent to ThingSpeak.
Open ThingSpeak channel and select public/private view. Here you can see the data uploaded
after the interval of 15 seconds.
RESULT:-
Successfully implemented and verify the moisture values of sensor placed in various soil
contents and monitor the values in cloud platform.
SERVO MOTOR INTERFACING TO NODEMCU
OBJECTIVE: To read the analog input from the physical world using potentiometer and
display the voltage values in serial monitor.
COMPONENTS REQUIRED: 1) NodeMCU – 1
2) Micro USB Cable – 1
3) PC – 1
4) Jumper Wires.
5) Bread Board.
6) Potentiometer- 1 (10k ohm)
SOFTWARE REQUIREMENTS:
1) Arduino IDE (with ESP8266 Library installed)
INTRODUCTION:
A servo motor is an electric device used for precise control of angular rotation. It is used in
applications that demand precise control over motion, like in case of control of robotic arm. It
works on PWM principle. The rotation angle of the servo motor is controlled by applying a
PWM signal to it. By varying the width of the PWM signal, we can change the rotation angle and
direction of the motor. Mostly 50Hz PWM is used to control the shaft position of servo motor.
To control servo motor shaft position within 180 degree it is required to control its PWM duty
cycle within 5% to 10%.
INTERFACING DIGRAM
Input of Servo (Yellow Wire) ---------- Digital Input Pin NodeMCU (D5)
Vcc of Servomotor (Red Wire) ------------ Vcc Of Esp32
Gnd of Servo (Black Wire)----------------- Gnd Of Esp32
void loop(){
delay (1000);
delay (1000);
Servo_1.write(135); //servo will move to 135 degree angle.
Delay(1000);
PROCEDURE:
PRECAUTIONS: