0% found this document useful (0 votes)
79 views

Iotlab Manual

The document provides an introduction to Internet of Things (IoT) and the Arduino platform. It describes the fundamental components of IoT including sensors, connectivity, data processing and user interfaces. It also lists some common IoT applications and provides an overview of the Arduino UNO board and its features.

Uploaded by

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

Iotlab Manual

The document provides an introduction to Internet of Things (IoT) and the Arduino platform. It describes the fundamental components of IoT including sensors, connectivity, data processing and user interfaces. It also lists some common IoT applications and provides an overview of the Arduino UNO board and its features.

Uploaded by

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

IOT

Department of Aeronautical
Engineering
IOT Lab Manual
IOT

Academic year: 2022-23


Compiled by: Veeranjaneyulu K Verified by: Dr.MSN Gupta

INTRODUCTION TO INTERNET OF THINGS

I B. TECH- I SEMESTER

Course Code Category Hours / Week Credits Maximum Marks

L T P C CIA SEE Total


A5EC01 ESC - - 3 1.5 30 70 100

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 - 2 Digital I/O Interface [IR Sensor, PIR Sensor, Ultrasonic]


IOT

WEEK - 3 Analog Interface [ADC, LDR, Temperature Sensor]

WEEK - 4 Motor speed And Direction control and servo motor Interface

WEEK - 5 Serial Communication and LCD Interface

WEEK - 6 Introduction to ESP8266 Module with program

WEEK - 7 Wireless Interface –Bluetooth & Wi-Fi Technologies

WEEK - 8 Smart Home Android App Development

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.

1.1.1 Fundamental components of IoT

 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

1.1.2 IoT Applications


Application type Description

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.

IoT technology helps users to identify the real-time availability of parking


Parking Sensors
spaces on their phone.

The concept of a connected health care system facilitates real-time health


Connect Health monitoring and patient care. It helps in improved medical decision-making
based on patient data.

Smart city offers all types of use cases which include traffic management to
Smart City
water distribution, waste management, etc.

Smart home encapsulates the connectivity inside your homes. It includes


Smart home
smoke detectors, home appliances, light bulbs, windows, door locks, 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.

1.2 INTRODUCTION TO ARDUINO


IOT

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.

Arduino UNO R3 Board Breakdown


IOT

Arduino UNO Features and Technical Specs

No
Parameter Name Parameter Value
.

1 Microcontroller Atmega328

2 Crystal Oscillator 16MHz

3 Operating Voltage 5V

4 Input Voltage 5-12V

5 Digital I/O Pins 14 (D0 to D13)

6 Analog I/O Pins 6 (A0 to A5)

7 PWM Pins 6 (Pin # 3, 5, 6, 9, 10 and 11)

8 Power Pins 5V, 3.3V, Vin, GND

9 Communication UART(1), SPI(1), I2C(1)

10 Flash Memory 32 KB (0.5KB is used by bootloader)

11 SRAM 2 KB

12 EEPROM 1 KB

13 ICSP Header Yes

14 Power sources DC Power Jack & USB Port


IOT

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

Arduino (IDE): Arduino Integrated Development Environment

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.'

The Arduino IDE will appear as:


IOT

TOOLBAR BUTTON

The icons displayed on the toolbar are New, Open, Save, Upload, and Verify.

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:

Selecting the right Board on Arduino


Now let’s select the proper board. It is very important to select the proper board before
compilation because the compiler will use this in the compile directives. To do that Click on
the “Tools” -> “Board” -> “Arduino AVR Boards” and select your board from it.
IOT

Select the Arduino Serial Port


It’s also important to select the proper serial port to which the Arduino board is connected.
Otherwise, you won’t be able to upload the code to the board. To do that click on “Tools” ->
“Port” And select the correct COM port. If there are multiple COM ports and you are not sure
which one to select, disconnect the Arduino board from the USB port and reopen the menu. The
COM port entry that disappeared will be the correct COM port. Reconnect the Board to the same
USB port and select that port.
IOT

THE STRUCTURE OF AN ARDUINO SKETCH (Programming)

void setup()

{
// put your setup code here, to run once:
}
void loop()
{
// put your main code here, to run repeatedly:
}
IOT

Experiments

Exp-1

1. Led Interfacing with ARDUINO

AIM: To develop the program blinks the led using ARDUINO

COMPONENTS

 ARDUINO Uno board


 5mm LED
 330 ohm or 220 ohm resistor
 Jumper wires
 Breadboard
 USB Cable

Circuit diagram
IOT

Theory:

LED (Light Emitting Diode) is a diode which have polarity.

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.

How to Know Resistor Value for LED?


The value of the resistor can be calculated by using the ohm’s law but before
calculating it.

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

i) Interface led with arduino

int led = 13;


void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led
, HIGH);
delay(5000);
digitalWrite(led
, LOW);
delay(5000);
}
IOT

ii)Interface 2led with arduino

int led1 = 13; int led2 = 12;


void setup()

{
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

Same color LEDs, Random color LEDs with delay and


repeat.
3. Construct a circuit for Traffic light controller with 1000 Sec delays

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

int led_yellow =5;


int led_blue=6;

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);

4. Construct a circuit for Traffic light controller (2way) using arduino.

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_ yellow2, HIGH);


delay (500);
digitalWrite(led_ yellow2, LOW);
delay (500);

digitalWrite(led_green1, HIGH);//signa1 green is on


digitalWrite(led_red2, HIGH); signal2 red is on

digitalWrite(led_red1, LOW);//
digitalWrite(led_green2, LOW);
digitalWrite(led_yellow2, LOW);
digitalWrite(led_ yellow1, LOW);
delay (2000);

digitalWrite(led_ yellow1, HIGH);


delay (500);
digitalWrite(led_ yellow1, LOW);
delay (500);

}
IOT

Exp-2

1. Interface led and IR (infrared) Sensor with ARDUINO

AIM: To develop the program determines the distance of an object using IR sensor.

COMPONENTS

 ARDUINO Uno board


 IR Sensor
 5mm LED
 330 ohm or 220 ohm resistor
 Jumper wires
 Breadboard
 USB

Cable Circuit

diagram

Theory:
IOT

What is an infrared sensor?

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

int led =13;


int irsensor = 10;

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

1. Develop a circuit to count number of visitors in to a room using IR sensors.

int Contrast = 100;

int in = 12; // ir sensor 1

int out = 11;// ir sensor 2

int led = 10;

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.

int pir= 12;

int buzzer = 10;

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

int pir= 12;

int relay1 = 10;//the light1 connection

int relay2 = 11;//the light2 connection

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");

Serial.println("lights automatically Is ON");

delay(200);

else

digitalWrite(relay1, LOW);

digitalWrite(relay2, LOW);

Serial.println("Nobody In Room");

Serial.print("lights Is off");

}
IOT

Exp-3

1. Interface ultrasonic Sensor with ARDUINO

AIM: To develop the program determines the distance of an object using ultrasonic sensor.

COMPONENTS

 ARDUINO Uno board


 Ultrasonic sensor
 5mm LED or 5V buzzer
 330 ohm or 220 ohm resistor
 Jumper wires
 Breadboard
 USB Cable

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.

 The module has only 4 pins,

 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.

 It is done using the formula Distance = (Speed of sound * Time delay) / 2

 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

I) Interface ultrasonic sensor with arduino


int tripin= 7;
int echopin= 8;
int led = 9; // or int buz
=9; int duration, distance
void setup()
{
pinMode(tripin, OUTPUT);
pinMode(led, OUTPUT);// pinMode(buz, OUTPUT);

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 System


2. Develop a circuit to Door Alarm with Ultrasonic Sensor
3. Develop a circuit to Hand Sanitizer Dispenser Using Arduino
IOT

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;

int LedGreen =8;


int LedRed =9;

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;

int buzzer =8;

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

EXP: 4 Interface LDR and Temperature Sensor with ARDUINO

AIM:

1. Develop the program to display Temperature using LM35 sensor.


2. Develop the program to display light intensity using LDR sensor.

COMPONENTS

 ARDUINO Uno board


 LDR
 Lm35
 5mm LED or 5V buzzer
 330 ohm or 220 ohm resistor
 Jumper wires
 Breadboard
 USB Cable

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

1. Interface LDR sensor with arduino

// write a program print the value in serial monitor using


ldr int LDR = A0;
int input_val =
0; void setup()
{
Serial.begin(9600);
}
void loop()
{
input_val =
analogRead(LDR);
Serial.print("LDR Value is: ");
Serial.println(input_val);
delay(1000);
}
2. // write a program led On/Off using ldr sensor

int LedPin = 10;


int sensorPin =
IOT

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;

int sensorPin = A5;


int sensorValor = 0;
void setup()
{
Serial.begin(9600);
pinMode(LedPin, OUTPUT);
}
void loop()
{
int sensorValor = analogRead(sensorPin);
Serial.println(sensorValor);
if(sensorValor > 700)
{
digitalWrite(Street_Light, HIGH);
digitalWrite(Street_Light1, HIGH);
IOT

digitalWrite(Street_Light2, HIGH);

}
else
{
digitalWrite(Street_Light, HIGH);
digitalWrite(Street_Light1, HIGH);
digitalWrite(Street_Light2, HIGH);
}

LM35 temperature sensor


 An LM35 is a 3 pin temperature sensor.
 It gives output in voltage according to the temperature, having an accuracy of 10mV
per degree Celsius.
 It can measure temperatures in the range of -55°C to 150°C and it operates from 4V
to 20V.
 Its output voltage is proportional to the temperature i.e., higher the temperature, higher
is the output voltage.

LM35 analog temperature sensor connections

LM35 Arduino

Pin 1 (+VS) 5V

Pin 2 (VOUT) Pin A0

PIN 3 (GND) GND


Converting the LM35 output voltage into temperature
IOT

To convert the output voltage of the sensor into the temperature in degree Celsius, use the following
formula:-

Temperature (°C) = VOUT / 10

To convert the voltage to temperature, simply use the basic formula:


IOT

Temperature (°C) = Vout * 100

With VOUT in millivolt (mV). So if the output of the sensor is 750

mV, The temperature is 75°C.

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:

VOUT = reading from ADC *


(Vref / 1024)

Program sketch
IOT

1. Interface LM35 sensor with arduino

const int lm35_pin = A1; /* LM35

O/P pin */ void setup()


{
Serial.begin(9600);
}

void loop()
{
int
temp_ad
c_val;
float
temp_val
;

temp_adc_val = analogRead(lm35_pin); /* Read Temperature */


temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent
voltage */ temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print(" Degree
Celsius\n");
delay(1000);
}

Task

1. Develop a circuit to room Temperature is high automatically fan is ON Temperature is low


automatically fan OFF using Temperature sensor.

int lm35_pin = A1; /* LM35 O/P pin */

int fan =3;

void setup()

{
IOT

Serial.begin(9600);

pinMode(fan,OUTPUT);

pinMode(lm35_pin ,INPUT);

void loop()

int temp_adc_val;

float temp_val;

temp_adc_val = analogRead(lm35_pin); /* Read Temperature */

temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent voltage */

temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */

Serial.print("Temperature = ");

Serial.print(temp_val);

Serial.print(" Degree Celsius\n");

delay(1000);

if(temp_val > 50)

digitalWrite(fan, HIGH);

else

digitalWrite(fan, LOW);

}
IOT

EXP

INTERFACING LM35 TEMPERATURE SENSOR WITH ARDUINO UNO

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

1. Write a program to Measure the Temperature using LM35 Sensor

const int lm35_pin = A1; /* LM35 O/P pin */

int temp_adc_val;

float temp_val;

void setup()

{
IOT

Serial.begin(9600);

void loop()

temp_adc_val = analogRead(lm35_pin); /* Read Temperature */

temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent voltage */

temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */

Serial.print("Temperature = ");

Serial.print(temp_val);

Serial.print(" Degree Celsius\n");

delay(1000);

2) Develop a circuit to room Temperature is high automatically fan is ON Temperature is


low automatically fan OFF using Temperature sensor.

int lm35_pin = A1; /* LM35 O/P pin */

int fan =3;

void setup()

Serial.begin(9600);

pinMode(fan,OUTPUT);

pinMode(lm35_pin ,INPUT);

void loop()
IOT

int temp_adc_val;

float temp_val;

temp_adc_val = analogRead(lm35_pin); /* Read Temperature */

temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent voltage */

temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */

Serial.print("Temperature = ");

Serial.print(temp_val);

Serial.print(" Degree Celsius\n");

delay(1000);

if(temp_val > 50)

digitalWrite(fan, HIGH);

else

digitalWrite(fan, LOW);

}
IOT

Circuit Diagram
IOT

Result:

EXP

Develop a circuit to print the message in 16x2 LCD

AIM: Print the Message in 16x2 LCD using Arduino microcontroller

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

1) Develop a circuit to print the message in 16x2 LCD

#include<LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()

lcd.begin(16, 2); // initializes the 16x2 LCD

void loop()

lcd.setCursor(0,0); //sets the cursor at row 0 column 0

lcd.print(“WEL-COME"); // prints Welcome

lcd.setCursor(2,1); //sets the cursor at row 1 column 2

lcd.print(“MLRIT WORLD"); // prints MLRIT WORLD

2) Develop a circuit to print the Temperature in 16x2 LCD using LM35 and Ardunio
uno

#include<LiquidCrystal.h>
IOT

int lm35_pin = A0; /* LM35 O/P pin */

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup()

lcd.begin(16, 2);

pinMode(fan,OUTPUT);

pinMode(lm35_pin ,INPUT);

void loop()

int temp_adc_val;

float temp_val;

temp_adc_val = analogRead(lm35_pin); /* Read Temperature */

temp_val = (temp_adc_val * 4.88); /* Convert adc value to equivalent voltage */

temp_val = (temp_val/10); /* LM35 gives output of 10mv/°C */

lcd.setCursor(0,0); //sets the cursor at row 0 column 0

lcd.print(“Temperature = "); // prints Welcome

lcd.setCursor(2,1); //sets the cursor at row 1 column 2

lcd.print(temp_val); // prints MLRIT WORLD

}
IOT

Circuit Diagram
IOT

Result:

EXP

Interfacing Motor with Arduino Program

AIM:

Component Requirement:

8) Motor
9) Arduino Micro-controller
10) Jumper Wire
11) USB Cable

Software:

12) Arduino IDE


13) tinkercad
14) wokwi

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 ENA = 10;

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

 HC-05 Bluetooth Module

 LED

 Jumper Wires

 Bread Board

Software Required
IOT

 Arduino IDE

 Android App – Arduino Bluetooth Controller

HC-05 Bluetooth Module

HC-05 Bluetooth Module

 Operating Voltage : 4 V to 6V
(have internal 3.3V regulator).

 Operating Current : 30mA

 Integrated antenna and an edge


connector.

 Range about 10 meters and


frequency 2.4GHz

 Configurable in both master and slave modes.

 Pins : STATE, RXD, TXD, GND, VCC, KEY/ENABLE

Program

char data = 0; //Variable for storing received data

void setup()

Serial.begin(9600);

pinMode(13, OUTPUT);

void loop()
IOT

if(Serial.available() > 0) // Send data only when you receive data:

data = Serial.read(); //Read the incoming data and store it into variable data

Serial.print(data); //Print Value inside data in Serial monitor

Serial.print("\n"); //New line

if(data == '1')

{ //Checks whether value of data is equal to 1

digitalWrite(13, HIGH); //If value is 1 then LED turns ON

else if(data == '0') //Checks whether value of data is equal to 0

digitalWrite(13, LOW); //If value is 0 then LED turns OFF

2. Write a Program to control Moment of Motor (ROBOT )using Bluetooth and


android Mobile

char t;

void setup()

{
IOT

pinMode(13,OUTPUT); //left motors forward

pinMode(12,OUTPUT); //left motors reverse

pinMode(11,OUTPUT); //right motors forward

pinMode(10,OUTPUT); //right motors reverse

Serial.begin(9600);

void loop()

if(Serial.available()>0)

t = Serial.read();

Serial.println(t);

if(t == 'F')

{ //move forward(all motors rotate in forward direction)

digitalWrite(13,HIGH);

digitalWrite(12,LOW);

digitalWrite(11,LOW);

digitalWrite(10,HIGH);

else if(t == 'B')

{ //move reverse (all motors rotate in reverse direction)


IOT

digitalWrite(13,LOW);

digitalWrite(12,HIGH);

digitalWrite(11,HIGH);

digitalWrite(10,LOW);

else if(t == 'L')

digitalWrite(13,HIGH);

digitalWrite(12,LOW);

digitalWrite(11,LOW);

digitalWrite(10, LOW);

else if(t == 'R')

digitalWrite(13,LOW);

digitalWrite(12,HIGH);

digitalWrite(11,LOW);

digitalWrite(10, LOW);

else if(t == 'S')

{ //STOP (all motors stop)

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);

Serial.print(“\n”); //New line

if(data == ‘1’)
IOT

digitalWrite(RELAY, HIGH);

Serial.println(“Bulb is now turned ON.”);

else if(data == ‘0’)

digitalWrite(RELAY,LOW);

Serial.println(“Bulb is now turned OFF.”);

Circuit Diagram
IOT

Result:
IOT

INTRODUCTION TO NODEMCU ESP8266


NodeMCU is an open-source Lua based firmware and development board specially targeted for
IoT based Applications. It includes firmware that runs on the ESP8266 Wi-Fi SoC from
Espressif Systems, and hardware which is based on the ESP-12 module.

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: 1
 I2Cs: 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
IOT

Pin diagram

Programming NodeMCU ESP8266 with Arduino IDE

Step1: Install the COM/Serial Port Driver

CH340 serial chip, download and install the driver

Step2: Install the ESP8266 Board Package

1. open Arduino IDE , go to File > Preferences.


IOT

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:

Setup ESP8266 Support


IOT

EXP

Write a program to LED Blinking Using Nodemcu


IOT

Program
#define LED D0 // Led in NodeMCU at pin GPIO16 (D0).

void setup()

pinMode(LED, OUTPUT); // LED pin as output.

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>

const char* ssid = "********"; // Enter SSID here

const char* password = "*******"; //Enter Password here

// Variable to store the HTTP request

String header;

String LED1State = "off";

const int LED1 = D0;

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);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

}
IOT

// Print local IP address and start web server

Serial.println("");

Serial.println("WiFi connected-->");

Serial.println("Copy this IP address: ");

Serial.println(WiFi.localIP());

server.begin();

void loop()

WiFiClient client = server.available();

if (client) { // If a new client connects,

Serial.println("new client connected");

String currentLine = ""; // make a String to hold incoming data from the client

while (client.connected())

if (client.available())

{ // if there's bytes to read from the client,

char c = client.read();

Serial.write(c);

header += c;

if (c == '\n') { // if the byte is a newline character

if (currentLine.length() == 0) {

client.println("HTTP/1.1 200 OK");

client.println("Content-type:text/html");
IOT

client.println("Connection: close");

client.println();

if (header.indexOf("GET /LED1/on") >= 0) {

Serial.println("LED1 on");

LED1State = "on";

digitalWrite(LED1, HIGH);

} else if (header.indexOf("GET /LED1/off") >= 0) {

Serial.println("LED1 off");

LED1State = "off";

digitalWrite(LED1, LOW);

// Display the HTML web page

client.println("<!DOCTYPE html><html>");

client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-


scale=1\">");

client.println("<link rel=\"icon\" href=\"data:,\">");

client.println("<style>html { font-family: Cairo; display: inline; margin: 0px auto; text-align:


center; background-color: #ccffb3;}");

client.println(".button { background-color: #006699; border: none; color: white; padding: 16px


40px;");

client.println("text-decoration: none; font-size: 35px; margin: 2px; cursor: pointer;}");

client.println(".button2 {background-color: #555555;}</style></head>");


IOT

client.println("<svg width=\"300\" height=\"80\"><text fill=\"#00bfbf\" font-family=\"serif\"


font-size=\"24\" id=\"svg_1\" stroke=\"#000000\" text-anchor=\"middle\"
transform=\"matrix(1.35388 0 0 1.42308 -6.66283 -8.67308)\" x=\"86.5\"
xml:space=\"preserve\" y=\"41.5\">Circuit Digest</text></svg>");

// Web Page Heading

client.println("<body><h1>Welcome to ESP12e Web Server</h1>");

client.println("<p>LED1_State: " + LED1State + "</p>");

// If the LED1State is off, it displays the ON button

if (LED1State=="off") {

client.println("<p><ahref=\"/LED1/on\"><button class=\"button\">ON</button></a></p>");

client.println("<svg width=\"500\" height=\"300\"><ellipse cx=\"258.5\" cy=\"125.5\"


fill=\"#ffffff\" rx=\"47\" ry=\"52\" stroke=\"#ffffaa\" stroke-width=\"5\"/><rect fill=\"#cccccc\"
height=\"40\" stroke=\"#ffffaa\" stroke-width=\"5\" transform=\"rotate(-0.485546 261 187.5)\"
width=\"39\" x=\"241.5\" y=\"167.5\"/></svg>");

else

client.println("<p><a href=\"/LED1/off\"><button class=\"button


button2\">OFF</button></a></p>");

client.println("<svg width=\"500\" height=\"300\"><ellipse cx=\"258.5\" cy=\"125.5\"


fill=\"#ff7f00\" rx=\"47\" ry=\"52\" stroke=\"#ffffaa\" stroke-width=\"5\"/><rect fill=\"#cccccc\"
height=\"40\" stroke=\"#ffffaa\" stroke-width=\"5\" transform=\"rotate(-0.485546 261 187.5)\"
width=\"39\" x=\"241.5\" y=\"167.5\"/></svg>");

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>

const char* ssid = "*********"; // Your ssid

const char* password = "***********"; // Your Password

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);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println("");

Serial.println("WiFi is connected");

server.begin();

Serial.println("Server started");

Serial.println(WiFi.localIP());

void loop() {

temp_celsius = (analogRead(A0) * 330.0) / 1023.0; // To convert analog values to Celsius We


have 3.3 V on our board and we know that output voltage of LM35 varies by 10 mV to every
degree Celsius rise/fall. So , (A0*3300/10)/1023 = celsius

temp_fahrenheit = celsius * 1.8 + 32.0;


IOT

Serial.print(" Temperature = ");

Serial.print(temp_celsius);

Serial.print(" Celsius, ");

Serial.print(temp_fahrenheit);

Serial.println(" Fahrenheit");

WiFiClient client = server.available();

client.println("HTTP/1.1 200 OK");

client.println("Content-Type: text/html");

client.println("Connection: close"); // the connection will be closed after completion of the


esponse

client.println("Refresh: 10"); // update the page after 10 sec

client.println();

client.println("<!DOCTYPE HTML>");

client.println("<html>");

client.print("<p style='text-align: center;'><span style='font-size: x-large;'><strong>Digital


Thermometer</strong></span></p>");

client.print("<p style='text-align: center;'><span style='color: #0000ff;'><strong style='font-size:


large;'>Temperature (*C)= ");

client.println(temp_celsius);

client.print("<p style='text-align: center;'><span style='color: #0000ff;'><strong style='font-size:


large;'>Temperature (F) = ");

client.println(temp_fahrenheit);

client.print("</p>");

client.println("</html>");
IOT

delay(5000);

You might also like