Iotlab Manual
Iotlab Manual
Department of Aeronautical
Engineering
IOT Lab Manual
IOT
I B. TECH- I SEMESTER
Contact Classes: Nil Tutorial Classes: Nil Practical Classes: 36 Total Classes:36
COURSE OBJECTIVES:
1. To develop basic programming skills through graphical programming
2. To learn hardware interfacing and debugging techniques
3. To design and develop android apps
COURSE OUTCOMES:
At the end of the course, student will be able to the algorithms for simple problems
1. CO 1: Able to demonstrate various sensor interfacing using Visual Programming Language.
2. CO 2: Able to analyze various Physical Components.
3. CO 3: Able to demonstrate Wireless Control of Remote Devices.
4. CO 4: Able to design and develop Mobile Application which can interact with Sensors
INTRODUCTION TO IOT
1. Introduction to basic electronic components and digital electronic
2. Introduction to sensors and Actuators
3. Introduction to microcontroller
4. Introduction to Arduino IDE
LIST OF
EXPERIMENTS
WEEK - 1 Blinking of LED with different delays
WEEK - 4 Motor speed And Direction control and servo motor Interface
REFERENCES
1. Sylvia Libow Martinez, Gary S Stager, Invent To Learn: Making, Tinkering, and
Engineering in the Classroom, Constructing Modern Knowledge Press, 2016
2. Michael Margolis, Arduino Cookbook, Oreilly, 2011
1. INTRODUCTION TO IOT
Internet of Things (IoT) is a network of physical objects or people called “things” that are
embedded with software, electronics, network, and sensors that allow these objects to collect
and exchange data. The goal of IoT is to extend to internet connectivity from standard devices
like computer, mobile, tablet to relatively dumb devices like a toaster.
Sensors/Devices: Sensors or devices are a key component that helps you to collect live
data from the surrounding environment. All this data may have various levels of
complexities. It could be a simple temperature monitoring sensor, or it may be in the
form of the video feed.
Connectivity: All the collected data is sent to a cloud infrastructure. The sensors should
be connected to the cloud using various mediums of communications. These
communication mediums include mobile or satellite networks, Bluetooth, WI-FI, WAN,
etc.
Data Processing: Once that data is collected, and it gets to the cloud, the software
product performs processing on the gathered data. This process can be just checking
the temperature, reading on devices like AC or heaters. However, it can sometimes also
be very complex, like identifying objects, using computer vision on video.
User Interface: The information needs to be available to the end-user in some way,
which can be achieved by triggering alarms on their phones or sending them
IOT
notification through email or text message. The user sometimes might need an
interface which actively checks their IoT system
Smart Thermostats Helps you to save resource on heating bills by knowing your usage patterns.
IoT helps automobile companies handle billing, parking, insurance, and other
Connected Cars
related stuff automatically.
Helps you to capture heart rate pattern, calorie expenditure, activity levels,
Activity Trackers
and skin temperature on your wrist.
Remotely turn any device on or off. It also allows you to track a device’s energy
Smart Outlets
level and get custom notifications directly into your smartphone.
Smart city offers all types of use cases which include traffic management to
Smart City
water distribution, waste management, etc.
Helps you in real time tracking of goods while they are on the road, or getting
Smart supply chain
suppliers to exchange inventory information.
Arduino is an open source platform based around programmable development boards that
can be integrated into a range of simple and complex projects. The Arduino family consists
of different types of development boards, with the most common being the Arduino UNO.
An Arduino board contains a microcontroller which can be programmed to sense and
control devices in the physical world. The microcontroller is able to interact with a large
variety of components such as LEDs, motors and displays. Because of its flexibility and
sustainability, Arduino has become a popular prototyping development board which is
widely used across the world.
No
Parameter Name Parameter Value
.
1 Microcontroller Atmega328
3 Operating Voltage 5V
11 SRAM 2 KB
12 EEPROM 1 KB
The Arduino IDE is used to write programs and compile them to be loaded on the
board. This supports a common programming language, C++.
1.3. SOFTWARE
The Arduino IDE is an open-source software, which is used to write and upload code to
the Arduino boards. The IDE application is suitable for different operating systems such
as Windows, Mac OS X, and Linux. It supports the programming languages C and C++.
The program or code written in the Arduino IDE is often called as sketching. We need to
connect the Genuino and Arduino board with the IDE to upload the sketch written in the
Arduino IDE software. The sketch is saved with the extension '.ino.'
TOOLBAR BUTTON
It is shown below:
1. Upload
The Upload button compiles and runs our code written on the screen. It further uploads the code
to the connected board. Before uploading the sketch, we need to make sure that the correct
board and ports are selected.
We also need a USB connection to connect the board and the computer. Once all the above
measures are done, click on the Upload button present on the toolbar.
2. Verify
The Verify button is used to check the compilation error of the sketch or the written code.
3. Serial Monitor
The serial monitor button is present on the right corner of the toolbar. It opens the serial monitor.
It is shown below:
When we connect the serial monitor, the board will reset on the operating system Windows,
Linux, and Mac OS X. If we want to process the control characters in our sketch, we need to use
IOT
an external terminal program. The terminal program should be connected to the COM port,
which will be assigned when we connect the board to the computer.
TOOLS
When we click on the Tools button on the Menu bar, a drop-down list appears. It is shown
below:
void setup()
{
// put your setup code here, to run once:
}
void loop()
{
// put your main code here, to run repeatedly:
}
IOT
Experiments
Exp-1
COMPONENTS
Circuit diagram
IOT
Theory:
1. Cathode
2. Anode
The Anode (positive side) will have the small plate, round edge and longer leg while the
cathode (Negative side) will have the larger plate, flat edge and small leg. The schematic
view of the LED is also shown in the below image.
IOT
It is necessary to use the resistor with the LED. The resistor limits the current flowing
through the LED.
Normally, the 5mm RED LED has forward voltage (VF) of 2V and forward
current (IF) of 20mA.
We know the supply voltage (Vs) is 5V that is coming from the Arduino so we
can use the ohm’s law to calculate the value of resistor.
R = (Vs-Vf) / If
R = (5-2) / 0.020
R=150 ohm
Program sketch
{
pinMode(led1,
OUTPUT);
pinMode(led2,
OUTPUT);
}
void loop()
{
digitalWrite(led1,HIGH);
digitalWrite(led2, LOW);
}
delay(500
0);
digitalWrit
e(led2,
HIGH);
digitalWrit
e( led1,
LOW);
delay(5000
);
Results
Tasks
1. Connect three LEDs with arduino and blink them in a sequence and repeat.
2. Construct circuit with different color LED and Blink
IOT
1. Connect three LEDs with Arduino and blink them in a sequence and repeat.
int led1=4;
int led2=5;
int led3=6;
void setup()
{
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
delay (1000);
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
delay (1000);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
delay (1000);
}
2. Construct circuit with different color LED and Blink Same color LEDs, Random color LEDs
with delay and repeat.
int ledr1=4;
int ledr2=5;
int ledg1=6;
int ledg2=7;
void setup()
{
IOT
pinMode(ledr1, OUTPUT);
pinMode(ledr2, OUTPUT);
pinMode(ledg1, OUTPUT);
pinMode(ledg2, OUTPUT);
}
void loop()
{
digitalWrite(ledr1, HIGH);
digitalWrite(ledr2, HIGH);
digitalWrite(ledg1, LOW);
digitalWrite(ledg2, LOW);
delay (1000);
digitalWrite(ledg1, HIGH);
digitalWrite(ledg2, HIGH);
digitalWrite(ledr1, LOW);
digitalWrite(ledr2, LOW);
delay (1000);
digitalWrite(ledr1, HIGH);
delay (1000);
digitalWrite(ledg1, HIGH);
delay (1000);
digitalWrite(ledr2, LOW);
delay (1000);
digitalWrite(ledg2, LOW);
delay (1000);
digitalWrite(ledg1, LOW);
digitalWrite(ledg2, LOW);
digitalWrite(ledr1, LOW);
digitalWrite(ledr2, LOW);
delay (1000);
3.Construct circuit with three different color LED and Blink them with delay of red=2sec, blue
=3sec, yellow = 4sec.
int led_red=4;
IOT
void setup()
{
pinMode(led_red, OUTPUT);
pinMode(led_yellow, OUTPUT);
pinMode(led_blue, OUTPUT);
}
void loop()
{
digitalWrite(led_red, HIGH);
digitalWrite(led_yellow, LOW);
digitalWrite(led_blue, LOW);
delay (2000);
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, LOW);
digitalWrite(led_blue, HIGH);
delay (3000);
digitalWrite(led_red, LOW);
digitalWrite(led_yellow, HIGH);
digitalWrite(led_blue, LOW);
delay (4000);
int led_red1=4;
int led_yellow1 =5;
int led_green1=6;
int led_red2=7;
int led_yellow2 =8;
int led_green2=9;
void setup()
IOT
{
pinMode(led_red1, OUTPUT);
pinMode(led_yellow1, OUTPUT);
pinMode(led_green1, OUTPUT);
pinMode(led_red2, OUTPUT);
pinMode(led_yellow2, OUTPUT);
pinMode(led_green2, OUTPUT);
}
void loop()
{
digitalWrite(led_red1, HIGH);// signal1 red is on
digitalWrite(led_green2, HIGH);//signa2 green is on
digitalWrite(led_red2, LOW);
digitalWrite(led_green1, LOW);
digitalWrite(led_yellow2, LOW);
digitalWrite(led_ yellow1, LOW);
delay (2000);
digitalWrite(led_red1, LOW);//
digitalWrite(led_green2, LOW);
digitalWrite(led_yellow2, LOW);
digitalWrite(led_ yellow1, LOW);
delay (2000);
}
IOT
Exp-2
AIM: To develop the program determines the distance of an object using IR sensor.
COMPONENTS
Cable Circuit
diagram
Theory:
IOT
An infrared sensor is an electronic module which is used to sense certain physical appearance
of its surroundings by either emitting and/or detecting infrared radiation. IR sensors are also
capable of determining the heat being emitted by an object and detecting motion
IR sensor working:
IR transmitter transmits IR signal, as that signal detects any obstacle in its path, the transmitted
IR signal reflects back from the obstacle and received by the receiver.
Program sketch
void setup()
{
pinMode(led,OUTPUT);
pinMode(irsensor, INPUT);
}
void loop()
{
if(digitalRead(irsensor)==0)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
}
Rueslts
IOT
Tasks
1. Develop a circuit to count number of visitors in to a room using IR sensors.
2. Develop a circuit to alert the buzzer when a visitor enters the room.
3. Develop a circuit to switch on the lights automatically when a person enters the
room using PIR sensor
int count=0;
void setup()
pinMode(in, INPUT);
pinMode(out, INPUT);
pinMode(led, OUTPUT);
Serial.println("Visitor Counter");
Serial.print("Person In Room:");
Serial.begin(9600);
void loop()
IOT
if(digitalRead(in))
count++;
Serial.println("Person In Room:");
Serial.print(count);
delay(1000);
if(digitalRead(out))
count--;
Serial.println("Person In Room:");
Serial.print(count);
delay(1000);
if(count<=0)
digitalWrite(led, LOW);
Serial.println("Nobody In Room");
Serial.println("Light Is Off");
delay(200);
else if(count>6)
digitalWrite(led, HIGH);
IOT
else
digitalWrite(led, LOW);
2. Develop a circuit to alert the buzzer when a visitor enters the room.
void setup()
pinMode(pir, INPUT);
pinMode(buzzer, OUTPUT);
Serial.print("Person In Room:");
Serial.begin(9600);
void loop()
if(digitalRead(pir)==1)
digitalWrite(buzzer, HIGH);
Serial.println("Person In Room");
Serial.println("Buzzer Is ON");
IOT
delay(200);
else
digitalWrite(buzzer, LOW);
Serial.println("Nobody In Room");
3. Develop a circuit to switch on the lights automatically when a person enters the room using PIR
sensor
void setup()
pinMode(pir, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
Serial.print("Person In Room:");
Serial.begin(9600);
void loop()
if(digitalRead(pir)==1)
{
IOT
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
Serial.println("Person In Room");
delay(200);
else
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
Serial.println("Nobody In Room");
Serial.print("lights Is off");
}
IOT
Exp-3
AIM: To develop the program determines the distance of an object using ultrasonic sensor.
COMPONENTS
Circuit diagram
IOT
Theory:
Ultrasonic sensors works on the principle of SONAR and RADAR system. It can be
used to determine the distance of an object in the range of 2 cm – 400 cm.
VCC
GND
Trig
IOT
Echo
When a pulse of 10µsec or more is given to the Trig pin, 8 pulses of 40 kHz are
generated. After this, the Echo pin is made high by the control circuit in the module.
Echo pin remains high till it gets echo signal of the transmitted pulses back.
The time, for which the echo pin remains high, i.e. the width of the Echo pin gives the
time taken for generated ultrasonic sound to travel to the object and back.
Using this time and the speed of sound in air, we can find the distance of the object using
a simple formula for distance using speed and time.
We divide the distance formula by 2 because the sound waves travel a round trip i.e from
the sensor and back to the sensor which doubles the actual distance.
Program sketch
pinMode(echopin,
INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(tripin, LOW);
delay(2);
IOT
digitalWrite(tripin, HIGH);
delay(10);
duration=pulesIn(echo,
HIGH);
distance=duration*0.034/2;
Serial.println(“distance: “);
Serial.println(distance);
Serial.println(“CM “);
if(distance<20)
{
digitalWrite(led, HIGH); // digitalWrite(buz,
HIGH); Serial.println(“ “);
}
else
{
digitalWrite(led, LOW);// digitalWrite(buz, LOW);
Serial.println(“ “);
}
}
Results
Tasks
1. Develop a circuit to Water Level Alerting using Ultrasonic Sensor and display the Levels in serial
monitor. (Water Level is <20% then red led ON, Water Level is >90% green led ON).
int echoPin=2;
int trigPin =3;
long duration;
int distance;
void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(LedGreen,OUTPUT);
pinMode(LedRed,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin,LOW);
delay(2);// or delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delay(10);// or delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration*0.034/2);
Serial.print("Distance : " );
Serial.print(distance);
Serial.println(" cm ");
if(distance <20)
{
digitalWrite(LedRed, HIGH);
Serial.print("Water Level is below 20%" );
}
else if(distance >90)
{
digitalWrite(LedGreen, HIGH);
Serial.print("Water Level is above 90%" );
else
IOT
{
digitalWrite(LedGreen, LOW);
digitalWrite(LedRed, LOW);
}
}
2. Develop a circuit to Door Alarm with Ultrasonic Sensor and print the message in serial
monitor.
int echoPin=2;
int trigPin =3;
long duration;
int distance;
void setup()
{
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin,LOW);
delay(2);// or delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delay(10);// or delayMicroseconds(10);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration*0.034/2);
Serial.print("Distance : " );
Serial.print(distance);
Serial.println(" cm ");
if(distance >20)
{
digitalWrite(buzzer, HIGH);
Serial.print("person can enter the room" );
else
{
digitalWrite(buzzer, LOW);
IOT
Serial.print("No object" );
}
}
IOT
AIM:
COMPONENTS
Circuit diagram
IOT
Theory:
LDR ( light dependent resistor ) also called photoresistors are responsive to light.
Photoresistors are used to indicate the intensity or the presence or the absence of light. When there
is darkness the resistance of photoresistor increases and when there is sufficient light it
dramatically decreases.
Program sketch
A5;
int sensorValor =
0; void setup()
{
Serial.begin(9600);
pinMode(LedPin,
OUTPUT);
}
void loop()
{
int sensorValor =
analogRead(sensorPin);
Serial.println(sensorValor);
if(sensorValor > 800)
{
digitalWrite(LedPin, HIGH);
}
else
{
digitalWrite(LedPin, LOW);
}
}
Task
1. Develop a circuit to control the Street Light using LDR and print the message in serial
monitor.
int Street_Light = 10;
int Street_Light1 = 11;
int Street_Light2 = 12;
digitalWrite(Street_Light2, HIGH);
}
else
{
digitalWrite(Street_Light, HIGH);
digitalWrite(Street_Light1, HIGH);
digitalWrite(Street_Light2, HIGH);
}
LM35 Arduino
Pin 1 (+VS) 5V
To convert the output voltage of the sensor into the temperature in degree Celsius, use the following
formula:-
The output of the LM35 is connected to one of the analog inputs of the Arduino. The value
of this analog input can be read with the function analogRead().
10- bit analog to digital converter (ADC), which will map input voltages between 0 and
the operating voltage (5 V or 3.3 V) into integer values between 0 and 1023.
On an Arduino Uno, for example, this yields a resolution between readings of 5 volts / 1024
units or, 0.0049 volts (4.9 mV) per unit.
use analogRead() to read the voltage at one of the analog inputs of the Arduino, you will get a
value between 0 and 1023.
To convert this value back into the output voltage of the sensor, you can use:
Program sketch
IOT
void loop()
{
int
temp_ad
c_val;
float
temp_val
;
Task
void setup()
{
IOT
Serial.begin(9600);
pinMode(fan,OUTPUT);
pinMode(lm35_pin ,INPUT);
void loop()
int temp_adc_val;
float temp_val;
Serial.print("Temperature = ");
Serial.print(temp_val);
delay(1000);
digitalWrite(fan, HIGH);
else
digitalWrite(fan, LOW);
}
IOT
EXP
AIM: Measure the temperature using LM35 Sensor with Arduino microcontroller
Component Requirement:
1) LM35 Sensor
2) Arduino Micro-controller
3) Jumper Wire
4) USB Cable
Software:
1) Arduino IDE
2) tinkercad
3) wokwi
Program
int temp_adc_val;
float temp_val;
void setup()
{
IOT
Serial.begin(9600);
void loop()
Serial.print("Temperature = ");
Serial.print(temp_val);
delay(1000);
void setup()
Serial.begin(9600);
pinMode(fan,OUTPUT);
pinMode(lm35_pin ,INPUT);
void loop()
IOT
int temp_adc_val;
float temp_val;
Serial.print("Temperature = ");
Serial.print(temp_val);
delay(1000);
digitalWrite(fan, HIGH);
else
digitalWrite(fan, LOW);
}
IOT
Circuit Diagram
IOT
Result:
EXP
Component Requirement:
1) 16x2 LCD
2) Arduino Micro-controller
3) Jumper Wire
4) USB Cable
IOT
Software:
5) Arduino IDE
6) tinkercad
7) wokwi
Program
#include<LiquidCrystal.h>
void setup()
void loop()
2) Develop a circuit to print the Temperature in 16x2 LCD using LM35 and Ardunio
uno
#include<LiquidCrystal.h>
IOT
void setup()
lcd.begin(16, 2);
pinMode(fan,OUTPUT);
pinMode(lm35_pin ,INPUT);
void loop()
int temp_adc_val;
float temp_val;
}
IOT
Circuit Diagram
IOT
Result:
EXP
AIM:
Component Requirement:
8) Motor
9) Arduino Micro-controller
10) Jumper Wire
11) USB Cable
Software:
Program
1. Connect a motor with Arduino and rotate motor anti clockwise direction with 2sec
delay and stop1sec delay.
int m1_1=4;
int m1_2=5;
void setup()
pinMode(m1_1, OUTPUT);
IOT
pinMode(m1_2, OUTPUT);
void loop()
digitalWrite(m1_1, LOW);
digitalWrite(m1_2, HIGH);
delay (1000);
2.Connect a motor with Arduino and rotate motor clockwise and anti-clockwise direction
with 500msec delay.
int m1_1=4;
int m1_2=5;
void setup()
pinMode(m1_1, OUTPUT);
pinMode(m1_2, OUTPUT);
void loop()
digitalWrite(m1_1, LOW);
digitalWrite(m1_2, HIGH);
delay (1000);
digitalWrite(m1_1, HIGH);
IOT
digitalWrite(m1_2, LOW);
delay (1000);
3. Connect a motor with Arduino and Move the Motor Forward, backward, and left, right
direction 1 sec delay and stop1sec delay.
int M1_1=9;
int M1_2=8;
int M2_1=7;
int M2_2=6;
void setup()
pinMode(M1_1,OUTPUT);
pinMode(M1_2,OUTPUT);
pinMode(M2_1,OUTPUT);
pinMode(M2_2,OUTPUT);
void loop()
digitalWrite(M1_1,HIGH);
digitalWrite(M1_2,LOW);
digitalWrite(M2_1,LOW);
digitalWrite(M2_2,HIGH);
IOT
delay(1000);
digitalWrite(M1_1,LOW);
digitalWrite(M1_2,HIGH);
digitalWrite(M2_1,HIGH);
digitalWrite(M2_2,LOW);
delay(1000);
digitalWrite(M1_1,LOW);
digitalWrite(M1_2,HIGH);
digitalWrite(M2_1,LOW);
digitalWrite(M2_2,HIGH);
delay(1000);
digitalWrite(M1_1,HIGH);
digitalWrite(M1_2,LOW);
digitalWrite(M2_1,HIGH);
digitalWrite(M2_2,LOW);
delay(1000);
digitalWrite(M1_1,LOW);
digitalWrite(M1_2,LOW);
digitalWrite(M2_1,LOW);
digitalWrite(M2_2,LOW);
delay(1000);
Circuit Diagram
IOT
4. Connect a motor with Arduino and control the speed of motor using PWM
int IN1 = 9;
int IN1 = 8;
int IN3 = 7;
int IN4 = 6;
int ENB = 5;
void setup( )
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
IOT
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
void loop
analogWrite(ENA, 255);
analogWrite(ENB, 255);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(5000);
analogWrite(ENA, 100);
analogWrite(ENB, 100);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(5000);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
IOT
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
delay(5000);
Result :
Exp :
Interfacing HC-05 Bluetooth Module with Arduino Uno
Aim: interfacing HC-05 Bluetooth Module arduino controller
Components Required
Arduino Uno
LED
Jumper Wires
Bread Board
Software Required
IOT
Arduino IDE
Operating Voltage : 4 V to 6V
(have internal 3.3V regulator).
Program
void setup()
Serial.begin(9600);
pinMode(13, OUTPUT);
void loop()
IOT
data = Serial.read(); //Read the incoming data and store it into variable data
if(data == '1')
char t;
void setup()
{
IOT
Serial.begin(9600);
void loop()
if(Serial.available()>0)
t = Serial.read();
Serial.println(t);
if(t == 'F')
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,HIGH);
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite(10,LOW);
digitalWrite(13,HIGH);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10, LOW);
digitalWrite(13,LOW);
digitalWrite(12,HIGH);
digitalWrite(11,LOW);
digitalWrite(10, LOW);
digitalWrite(13,LOW);
digitalWrite(12,LOW);
IOT
digitalWrite(11,LOW);
digitalWrite(10,LOW);
delay(100);
3. Write a Program to control home automation using Bluetooth and android Mobile
int RELAY= 4;
char data = 0;
void setup()
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, LOW);
Serial.begin(9600);
void loop()
if (Serial.available() > 0)
data = Serial.read();
Serial.print(data);
if(data == ‘1’)
IOT
digitalWrite(RELAY, HIGH);
digitalWrite(RELAY,LOW);
Circuit Diagram
IOT
Result:
IOT
Pin diagram
2. Copy and paste the following line to the Additional Boards Manage
http://arduino.esp8266.com/stable/package_esp8266com_index.json
IOT
Step3:
Go to Tools > Board > Boards Manager search ESP8266 and install
Step4:
EXP
Program
#define LED D0 // Led in NodeMCU at pin GPIO16 (D0).
void setup()
void loop()
digitalWrite(LED, HIGH
delay(1000);
digitalWrite(LED, LOW);
IOT
delay(1000);
2. Write a program to Build NodeMCU Webserver and control an LED from a Webpage
#include <ESP8266WiFi.h>
String header;
WiFiServer server(80);
void setup() {
Serial.begin(115200);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
delay(500);
Serial.print(".");
}
IOT
Serial.println("");
Serial.println("WiFi connected-->");
Serial.println(WiFi.localIP());
server.begin();
void loop()
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected())
if (client.available())
char c = client.read();
Serial.write(c);
header += c;
if (currentLine.length() == 0) {
client.println("Content-type:text/html");
IOT
client.println("Connection: close");
client.println();
Serial.println("LED1 on");
LED1State = "on";
digitalWrite(LED1, HIGH);
Serial.println("LED1 off");
LED1State = "off";
digitalWrite(LED1, LOW);
client.println("<!DOCTYPE html><html>");
if (LED1State=="off") {
client.println("<p><ahref=\"/LED1/on\"><button class=\"button\">ON</button></a></p>");
else
client.println("</body></html>");
client.println();
IOT
break;
} else {
currentLine = "";
} else if (c != '\r') {
currentLine += c;
header = "";
client.stop();
Serial.println("Client disconnected");
Serial.println("");
Write a program to Build NodeMCU Webserver and measure an LM35 from a Webpage
#include <ESP8266WiFi.h>
float temp_celsius = 0;
float temp_fahrenheit = 0;
WiFiServer server(80);
void setup()
IOT
Serial.begin(115200);
pinMode(A0, INPUT);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
delay(500);
Serial.print(".");
Serial.println("");
Serial.println("WiFi is connected");
server.begin();
Serial.println("Server started");
Serial.println(WiFi.localIP());
void loop() {
Serial.print(temp_celsius);
Serial.print(temp_fahrenheit);
Serial.println(" Fahrenheit");
client.println("Content-Type: text/html");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println(temp_celsius);
client.println(temp_fahrenheit);
client.print("</p>");
client.println("</html>");
IOT
delay(5000);