Iot Lab Manual 2
Iot Lab Manual 2
(AUTONOMOUS)
KANURU, VIJAYAWADA-7
DEPARTMENT OF E.E.E.
Fig1.2
Fig1.3
1
EXPERIMENT – 1
Familiarization with Arduino/Raspberry Pi and perform necessary software
installation.
AIM
• Introduction to Arduino and necessary software installation.
• To Interface and control LED.
THEORY:
Introduction to Arduino:
What is Arduino?
software. Arduino boards are able to read inputs - light on a sensor, a finger on a button,
or a Twittermessage - and turn it into an output - activating a motor, turning on an LED,
publishing something online. You can tell your board what to do by sending a set of
instructions to the microcontroller on the board. To do so you use the Arduino
programming language (based on Wiring), and the ArduinoSoftware (IDE), based on
Processing.
After learning about the main parts of the Arduino UNO board, we are ready to learn how
to set up the Arduino IDE. Once we learn this, we will be ready to upload our program on
the Arduino board.
In this section, we will learn in easy steps, how to set up the Arduino IDE on our computer
and preparethe board to receive the program via USB cable.
Step 1 − First you must have your Arduino board (you can choose your favorite board)
and a USB cable. In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino
Mega 2560, or Diecimila,you will need a standard USB cable (A plug to B plug), the kind
you would connect to a USB printer as shown in the fig1.1
In case you use Arduino Nano, you will need an A to Mini-B cable instead as shown in
the fig1.2.
Step 2 − Download Arduino IDE Software.
You can get different versions of Arduino IDE from the download page on the Arduino
official website. You must select your software, which is compatible with your operating
system (Windows, IOS, or Linux). After your file download is complete, unzip the file as
shown in the fig1.3.
Step 3 − Power up your board.
The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power
from either, the USB connection to the computer or an external power supply. If you are
using an Arduino Diecimila, you have to make sure that the board is configured to draw
2
Fig1.4
Fig1.5
Fig1.6
3
power from the USB connection. The power source is selected with a jumper, a small piece
of plastic that fits onto two of the three pins between the USB and power jacks. Check that
it is on the two pins closest to the USB port.
Connect the Arduino board to your computer using the USB cable. The green power LED
(labeled PWR) should glow.
Step 4 – Launch Arduino IDE.
After your Arduino IDE software is downloaded, you need to unzip the folder. Inside thefolder,
you can find the application icon with an infinity label (application.exe). Double-click the icon
to start the IDE as shown in fig 1.4
4
Fig 1.7
Fig 1.8
Fig 1.9
5
Fig1.9 shows:
A − Used to check if there is any compilation error.
B − Used to upload a program to the Arduino board.C − Shortcut used to create a new sketch.
D − Used to directly open one of the example sketch.
E − Used to save your sketch.
F − Serial monitor used to receive serial data from the board and send the serial data to the
board.
Now, simply click the "Upload" button in the environment. Wait a few seconds; you willsee
the RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar.
void setup(){
outputpinMode (LED_BUILTIN,OUTPUT);
}
// The loop function runs over and over again
forever.void loop(){
RESULT:
6
Fig2.1
7
EXPERIMENT - 2
Digital I/O Interface –IR Sensor, Multi color Led
AIM: To interface and control RGB LED and a IR sensor with Arduino to detect motion
and display "Stop" or "Go" depending on the output from the sensor.
APPPARATUS REQUIRED:
S.No Name of the equipment Specifications Quantity
1 Arduino UNO 1
2 RGB common cathode LED 1
3 Infrared (IR)Sensor 1
4 Jumper wires required
5 Breadboard 1
6 Computer with Arduino IDE IDE 1.8.14 1
software
THEORY:
The RGB led consists of three different led’s, red, green and blue. Many other colors canbe
obtained by mixing up these colors. The Arduino has aa analog write function which is used
to obtain different colors for Arduino RGB led.
RGB LED Schematic
There are two types of RGB led’s; the common cathode one and the common anode. In the
common cathode RGB led, the cathode of all the led’s is common and a PWM signalsis fed
to the anode of led’s while in the common anode RGB led, the anode of all the led’sis common
and a PWM signals is fed to the cathode of led’s as shown in fig2.1.
IR 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:
Here an IR sensor is used for detecting obstacles. IR transmitter transmits IR signal, as that
signal detects any obstacle in its path, the transmitted IR signal reflects back from the obstacle
and receivedby the receiver.
8
9
PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE
OBSERVATIONS:
10
Fig: 2.2
11
PINOUT(fig2.2):
1. VCC: 3.3V-5V power input pin
2. GND: 0V power pin
3. OUT: Digital Output Pin
PROGRAME:
int ir = 2; // connect ir sensor to arduino
pin 2int led = 3; // conect Led to arduino
pin 3 void setup(){
pinMode (ir, INPUT); // sensor pin INPUT
pinMode (led, OUTPUT); // Led pin OUTPUT
}
void loop(){
int statusSensor =
digitalRead(ir); if (statusSensor
== 1){ digitalWrite(led, 0); // LED
LOW
}
else{
digitalWrite(led, 1); // LED High
}
OBSERVATIONS:
S.NO OBSTACL E LED Status
1.
2.
3.
RESULT:
12
SCHEMATIC DIAGRAM PIR SENSOR:
13
EXPERIMENT-3
Digital I/O Interface - PIR Sensor, Slot Sensor
Aim:
• To Interface a PIR with Arduino to detect motion and display "Stop" or "Go"
depending on the output from the sensor.
• To Interface a slot sensor with Arduino to detect object and control LEDbased
on sensor output.
APPPARATUS REQUIRED:
Theory:
Passive Infrared (PIR) Sensor
The PIR sensor consists of 4 pins: GND, VCC, OUT, and EN. It can measure movement up
to 30′. Within thedome-shaped lens (used to focus the incoming light onto the detectors), there
are two slots that can detect different levels of infrared (IR) light or radiation. The sensor does
not detect motion when the detectors sensethe same amount of IR. The motion is detected
when the detectors measure two different levels of IR. The levels of IR can vary from object
to object since each one emits different amounts of heat energy.
PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.
14
15
PROGRAM FOR PIR SENSOR:
OBSERVATIONS:
16
Fig3.2
17
LM393 Speed Sensor Module (H206)/SLOT SENSOR
H206 speed sensor module is composed of infrared light sensor and LM393 voltage
comparator IC, so it is named as LM393 speed sensor. The module also includesa grid plate,
which must be mounted on the rotating shaft of the motor. The infrared light sensor is
composed of infrared LED and phototransistor, separated by a small gap. As shown below,
the entire sensor device is placed in a black housing. The grid plate is composed of grooves,
and the plate is arranged between the gaps ofthe infrared light sensors so that the sensor
can sense the gap in the grid plate. Each gap in the grid plate triggers the IR sensor when
passing through the gap; a comparator is then used to convert these triggers into a voltage
signal. The comparator uses ON Semiconductor's LM393 IC as shown in fig3.2. The module
has three pins, two of which are used to power the module, and one output pin is used to
count the number of triggers.
PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.
PROGRAM
int slot Sensor = 2;
2.
3.
RESULT:
20
Fig4.1
SCHEMATIC DIAGRAM:
21
EXPERIMENT-4
Interface temperature Sensor with Arduino and write program to print
temperatureand humidity readings
APPPARATUS REQUIRED:
THEORY:
The analog input is a pin with ADC (Analog-to-Digital Converter) function. It
can convert the externally input analog signal into a digital signal that can be recognized
during chip operation, so as to realize the function of reading in the analog value. The
Arduino analog input function has 10-bit precision, that is, it can convert a voltage
signal of 0 to 5V into an integer form of 0 to 1024.
22
23
PROCEDURE:
• Build the circuit according to the schematic diagram
• Use Arduino Uno on the Arduino Desktop IDE.
• Select board type and port.
• Write and upload the program in the Arduino-IDE.
• Add the required library files.
• Observe the temperature and Humidity values.
PROGRAM:
#include <dht.h>
dht DHT;
#define DHT11_PN 8
void setup()
{
Serial.begin(9600);}
void loop(){
int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(1000);
}
24
25
OBSERVATIONS:
RESULT:
26
Fig5.1
SCHEMATIC DIAGRAM:
27
EXPERIMENT – 5
Wireless module interface – Bluetooth.
AIM:
APPPARATUS REQUIRED:
THEORY:
BLUETOOTH MODULE INTERFACE:
BLUETOOTH:
Bluetooth is a one of the wireless technology. HC-05 is a Bluetooth module which can
communicate in two way. It is full-duplex. It be used with most micro controllers. Because it
operates Serial Port Protocol (SSP). The module communicate with the help of
USART(Universal Synchronous/ Asynchronous Receiver/Transmitter) at the baud rate of
9600anditalso support other baud rate. This module can be interfaced with any
microcontroller which supports USART. The HC-05 operates in two modes. One is Data
mode and other is at command mode. When the Enable/Key pin is "LOW" the HC-05 is in
Data Mode. If that pin set as "HIGH" the module is in AT command mode.
FROM Fig5.1
Enable - This pin is used to set the Data Mode or and AT command mode (set high).
VCC - This is connected to +5V power supply.
Ground - Connected to ground of powering system.
Tx (Transmitter) - This pin transmits the received data Serially.
Rx (Receiver) - Used for broadcasting data serially over bluetooth.
State -Used to check if the bluetooth is working properly.
28
29
PROCEDURE:
• Build the circuit according to the schematic diagram.
• Use Arduino Uno on the Arduino Desktop IDE.
• Select board type and port.
• Write and upload the program in the Arduino-IDE.
• Download and install a Bluetooth terminal application on phone and use it to connect
to the HC-05Bluetooth module.
• Data is sent from the Smartphone using the Bluetooth terminal application.
PROGRAM:
#include<softwareSerial.h>
/* Create object named bt of the class SoftwareSerial */
SoftwareSerial bt(2, 3);
/* (Rx,Tx) */
void setup()
{
bt.begin(9600);
/* Define baud rate for software serial communication */
Serial.begin(9600);
/* Define baud rate for serial communication */
}
void loop()
{
if(bt.available())
{
/* If data is available on serial port */
Serial.write(bt.read());
/* Print character received on to the serial monitor */
}
}
OBSERVATION:
Input from mobile LED Status
S.No.
1.
2.
RESULT:
30
WI-FI (ESP8266) MODULE: NODEMCU
Fig6.1
Fig6.2
31
EXEPERIMENT-6
Wireless module interface –Wi-Fi
AIM: To control LED at Receiver through Switch at Transmitter using Wi-Fi module
interface with Arduino.
APPPARATUS REQUIRED:
THEORY:
Wireless control of wheeled robots using WiFi involves leveraging wireless network
technology to remotely operate and manage robot movements. WiFi connectivity enables real-
time communication between the robot and a control interface, such as a smartphone or
computer, allowing for the transmission of commands and reception of feedback. This setup
typically includes a microcontroller or onboard computer on the robot equipped with a WiFi
module. Commands are sent over the WiFi network, interpreted by the robot's control system,
and executed accordingly, enabling precise navigation and task performance in various
environments. This method benefits from WiFi's broad range, high data transfer rate, and
widespread availability.
PROCEDURE:
PROGRAM:
#include <ESP8266WiFi.h>
const char* ssid = ""; // Your Wi-Fi Name
const char* password = ""; // Wi-Fi
Passwordint LED = 2; // led connected to
GPIO2 (D4) WiFiServer server(80);
void setup()
32
33
{
Serial.begin(115200); //Default Baudrate
pinMode(LED, OUTPUT); digitalWrite(LED,
LOW); Serial.print("Connecting to the
Newtork"); WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin(); // Starts the Server
Serial.println("Server started");
Serial.print("IP Address of network: "); // will IP address on Serial Monitor
Serial.println(WiFi.localIP());
Serial.print("Copy and paste the following URL: https://"); // Will print IP address in URL
format
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop()
{
WiFiClient client = server.available();
if (!client)
{
return;
}
Serial.println("Waiting for new client");
while(!client.available())
{
delay(1);
}
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
int value = LOW;
if(request.indexOf("/LED=ON") != -1)
{
digitalWrite(LED, HIGH); // Turn LED ONvalue
= HIGH;
}
if(request.indexOf("/LED=OFF") != -1)
{
digitalWrite(LED, LOW); // Turn LED OFF
34
35
value = LOW;
}
//*------------------HTML Page Code ------------------------- *//
OBSERVATIONS:
Input from mobile LED Status
S.No.
1.
2.
RESULT:
36
ELECTRICAL CIRCUIT DIAGRAM:
DC VOLTMETER:
DC AMMETER:
37
EXPERIMENT – 7
Design of digital Voltmeter and Ammeter
APPARATUS:
S. No Name of the equipment Quantity
1 Arduino Uno 1
2 16 x 2 LCD display 1
3 ACS712 Voltage sensor 1
4 9/12V Battery 1
5 Computer with Arduino IDE software 1
6 jumper cables As required
THEORY:
Designing a digital DC voltmeter and ammeter using Arduino involves using a voltage divider
for voltage measurement and a shunt resistor for current measurement. The Arduino reads
analog signals from these components, converts them to digital values, and processes them to
determine the actual voltage and current. These readings are then displayed on an LCD screen
controlled by the Arduino. The setup requires programming the Arduino to handle analog-to-
digital conversion, calculation of the measurements, and updating the LCD display. This
design provides accurate, real-time monitoring of DC electrical circuit parameters.
PROCEDURE
38
39
➢ Procedure for DC Ammeter:
o Make the connection as per the electrical circuit diagram
o Open the Arduino IDE in computer and write the program.
o Compile the program for any errors and upload it to the Arduino.
o Observe the current on LCD display.
o If the load is increased by adding a series resistor to LED then
current increases and is updated in LCD display.
ARDUINO CODE:
void setup()
Serial.begin(9600);
void loop() {
offset
valuesSerial.print("Voltage: ");
Serial.print(voltage);//print the
voltgeSerial.println("V");
delay(500);
40
41
B) Code for DC Voltmeter:
void setup() {
Serial.begin(9600);
}
void loop() {
offset
valuesSerial.print("Voltage: ");
Serial.print(voltage);//print the
voltgeSerial.println("V");
delay(500);
}
void loop() {
float average = 0;
modedelay(1);
}
42
43
Serial.println(average);
}
//DC motor direction and speed
controlint in1 = 6;
int in2 = 7;
int enA = 9;
int Speed =
0;int val = 0;
void setup()
Serial.begin(9600);
pinMode(enA,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2, OUTPUT);
Serial.begin(9600);
}
//Enter value 0 or 1 to select motor direction, 0 for Backward, 1 for
Forwardvoid loop(){
// Anti clockwise
rotation
if(Serial.available() >
44
45
{
//FORWARD
Rotationif(state ==
‘1’){
analogWrite(enA,
Speed);
digitalWrite(in1, 1);
digitalWrite(in2, 0);
Serial.println(“FORWARD”
);delay(1000);
//BACKWARD Rotation
if(state == ‘0’){
analogWrite(enA,
Speed);
digitalWrite(in1, 0);
digitalWrite(in2, 1);
Serial.println(“BACKWARD”);
delay(1000);
RESULT:
46
Fig8.1
SCHEMATIC DIAGRAM:
47
EXPERIMENT – 8
Design and Speed Control of DC motor
APPARATUS REQUIRED:
THEORY:
The L298N is a dual-channel H-Bridge motor driver capable of driving a 2x
DC motors, making it ideal for building two-wheel robots.
Power Supply: From 'Vs' pin the H-Bridge gets its power for driving the motors which can
be 5 to 35V. 'Vss' is used for driving the logic circuitry which can be 5 to 7V. And they
both sink to a common ground named ‘GND’.
Output Pins: The L298N motor driver’s output channels for the motor A and B are broken
out to the edge of the module with two 3.5mm-pitch screw terminals.
Direction Control Pins: The IN1 and IN2 pins control the direction of the motor A while
IN3 and IN4 control the direction of the motor B.
Speed Control Pins: ENA and ENB are used to turn the motors ON, OFF and control its
speed. The module usually comes with a jumper on these pins. When this jumper is in
place, the motor is enabled and spins at maximum speed. If you want to control the speed of
motors, you need to remove the jumpers and connect themto PWM-enabled pins on
Arduino as shown in fig8.1
48
49
PROCEDURE:
1) Build the circuit according to the schematic diagram.
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.
5) Control the speed and direction of DC motor by varying potentiometer and switch.
PROGRAME:
//FORWARD Rotation
if(state == ‘1’){
analogWrite(enA, Speed);
digitalWrite(in1, 1);
digitalWrite(in2, 0);
Serial.println(“FORWARD”);
delay(1000);
}
//BACKWARD Rotation
if(state == ‘0’)
{
50
51
analogWrite(enA, Speed);
digitalWrite(in1, 0);
digitalWrite(in2, 1);
Serial.println(“BACKWARD”);
delay(1000);
}
}
}
OBSERVATIONS:
By varying the potentiometer, speed of the DC motor is controlled and each time
button is pressed, it changes the rotation direction of the motor.
RESULT:
52
Fig9.1
Fig9.2
SCHEMATIC DIAGRAM:
53
EXPERIMENT – 9
Smart Home Android App Development using APP Inventor and Arduino
AIM: To develop Home Automation with MIT App Inventor and ESP8266.
APPPARATUS REQUIRED:
THEORY:
Relay Module
A relay is an electrically operated switch. Relays are used for controlling multiple circuits by
one signal. So using relays we can turn the circuit “ON” and “OFF” with electricity. The relay
is controlled by a small current (5V) and can switch “ON” and “OFF” the large current.
Typically, the relay has five terminals as shown in fig9.1
When no voltage is applied to the coil, the COM terminal will be connected to the NC
(Normally Closed) terminal. And when voltage is applied to the coil, anelectromagnetic field
is produced that attracts the armature, and a COM and NO(Normally Open) terminal connection
is made, which allows for very large currents as shown in 9.2.
A small driver circuit with a transistor, diode, and a resistor is used to configure relay. The
transistoris used to amplify the current, the resistor is used to provide BIAS to the transistor,
and ifthe transistor is off, the diode is used to stop the reverse current flow. Here we have used
the 5V relaymodule for demonstration.
54
55
PROCEDURE:
1) Build the circuit according to the schematic diagram
2) Use Arduino Uno on the Arduino Desktop IDE.
3) Select board type and port.
4) Write and upload the program in the Arduino-IDE.
NodeMCU Relay
Vcc Vcc
GND GND
D4 Input
Pin connection of relay with NodeMCU ESP8266
Now we have to make an Android APP using MIT App Inventor forcontrolling home
appliances.
PROGRAME:
#include <ESP8266WiFi.h>
const char* ssid = "Enter Your WiFi Name ";
const char* password = "Enter Your WiFi Password";WiFiServer
server(80);
void setup() {
Serial.begin(115200); //Default Baud Rate for NodeMCUdelay(10);
pinMode(2, OUTPUT); // Connect Relay to NodeMCU's D4 PindigitalWrite(2, 0);
// Connect to WiFi network
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
connected");
// Start the server server.begin();
Serial.println("Server started");
// Print the IP address
Serial.println(WiFi.localIP());
}
void loop() {
// Check if a client has connected WiFiClient
client = server.available();if (!client) {
56
57
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){ delay(1);
}
String req = client.readStringUntil('\r');Serial.println(req);
client.flush();int val;
if (req.indexOf("/gpio/0") != -1)val = 0;
else if (req.indexOf("/gpio/1") != -1)val = 1;
else {
Serial.println("invalid request");client.stop();
return;
}
// Set GPIO2 according to the requestdigitalWrite(2, val);
client.flush();
String s = "HTTP/1.1 200 OK\r\nContent-Type:
text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low"; s +=
"</html>
RESULT:
58
59