IoT Record
IoT Record
1. Aim:
To Interface an LED with Arduino UNO (Blinking LED).
Description:
An LED, or Light Emitting Diode, is a semiconductor device that emits light when current
flows through it. It consists of a semiconductor diode chip encapsulated in a transparent
case, with two leads: anode (+) and cathode (-). When a voltage is applied across the
LED in the forward direction, current flows through it, causing electrons and holes to
recombine at the junction and emit light. The color of the light emitted depends on the
semiconductor material used in the LED. LEDs are highly efficient at converting electrical
energy into light energy and produce minimal heat. They are polarized devices, with the
anode connected to the positive terminal and the cathode to the negative terminal.
LEDs find wide applications in lighting, displays, indicators, and various other electronic
devices.
Components Required:
• 1 X LED
• 1 X Resistor, 330 Ohm
• Breadboard
• Arduino UNO
• Jumper wires
1604-20-737-002
Circuit Diagram (Connections):
Procedure (Steps):
1604-20-737-002
Sketch (Code):
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
Observation :
Applications:
The LED blinking project is an important and straightforward method that can
be utilized for a wide range of applications in microcontroller-based projects
like :
1604-20-737-002
2. Aim:
To Interface DHT-11 Sensor with Arduino UNO.
Description:
The DHT11 sensor module is a digital temperature and humidity sensor. It has four pins: VCC
(power supply), GND (ground), DATA (data communication), and NC (not connected).
The DHT11 sensor module is a crucial component for measuring temperature and
humidity. Its operation involves several steps: initialization, data transmission, data
interpretation, conversion, and output. First, the sensor requires initialization by sending
a start signal. Following this, it responds with a response signal and transmits
temperature and humidity data using a single-wire serial communication protocol. The
microcontroller, such as an Arduino, interprets this data and converts it into temperature
and humidity values. Finally, the microcontroller utilizes the data for various
applications, such as display or logging.
Components Required:
1604-20-737-002
• Circuit Diagram (Connections):
Procedure (Steps):
• Identify the DHT11 Sensor Pins: The DHT11 sensor typically has four pins: VCC
(power), GND (ground), DATA (data), and NC (not connected). Sometimes the pins
might be labeled slightly differently.
• Connect Power and Ground: Connect the VCC pin of the DHT11 sensor to the 5V
output on the Arduino UNO.Connect the GND pin of the DHT11 sensor to one of the
GND (ground) pins on the Arduino UNO.
• Connect the Data Pin: Connect the DATA pin of the DHT11 sensor to any digital pin
on the Arduino UNO. For example, use pin 2.
• Upload Arduino Sketch:Open the Arduino IDE on your computer.
Install the DHT sensor library if you haven't already. You can do this by going to Sketch
> Include Library > Manage Libraries and then searching for "DHT sensor library" and
installing it. Write or copy an Arduino sketch to read data from the DHT11 sensor.
1604-20-737-002
Sketch (Code):
#include <DHT11.h>
void setup() {
// Initialize serial communication at 9600 baud rate.
Serial.begin(9600);
}
void loop() {
// Read the humidity from the sensor.
float humidity = dht11.readHumidity();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
// If the temperature or humidity reading failed, print
//an error message.
Serial.println("Error reading data");
}
1604-20-737-002
Observation:
Applications:
• Environmental monitoring systems
• Weather stations
• Home automation systems
• Greenhouses and agricultural applications
• HVAC (Heating, Ventilation, and Air Conditioning) systems
• Indoor climate control systems
1604-20-737-002
3. Aim:
To Interface LDR Sensor with Arduino UNO.
Description:
The LDR (Light Dependent Resistor) sensor operates by exhibiting photoconductivity,
where its resistance changes in response to light intensity. This change is utilized in a
voltage divider circuit alongside a fixed resistor, resulting in a varying output voltage
proportional to light intensity. The analog output from this circuit is fed into an Arduino
Uno's analog pin, which converts it into digital values. To ensure accuracy, the Arduino is
calibrated to map these digital readings to corresponding light intensities. This
calibration enables precise measurement and response to ambient light conditions.
Components Required:
• Arduino Uno board
• LDR sensor
• Resistor (10k ohms)
• Breadboard
• Jumper wires
Procedure (Steps):
• Identify the I2C LCD Pins: A typical I2C LCD module has four pins: VCC (power),
GND (ground), SDA (data), and SCL (clock).
• Connect Power and Ground: Connect the VCC pin of the I2C LCD module to the 5V
output on the Arduino UNO. Connect the GND pin of the I2C LCD module to one of the
GND (ground) pins on the Arduino UNO.
1604-20-737-002
• Connect SDA and SCL Pins: Connect the SDA pin of the I2C LCD module to the A4
pin on the Arduino UNO Connect the SCL pin of the I2C LCD module to the A5 pin on
the Arduino UNO.
• Upload Arduino Sketch: Open the Arduino IDE on your computer. Install the
LiquidCrystal_I2C library if you haven't already. You can do this by going to Sketch >
Include Library > Manage Libraries and then searching for "LiquidCrystal_I2C" and
installing it. Write or copy an Arduino sketch to initialize the I2C LCD and display text.
Sketch (Code):
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop()
{
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <= 300)
{
digitalWrite(ledPin, LOW);
Serial.print("Its BRIGHT, Turn OFF the LED: ");
Serial.println(ldrStatus);
}
else
{
digitalWrite(ledPin, HIGH);
Serial.print("Its Dark, Turn ON the LED: ");
Serial.println(ldrStatus);
}
}
1604-20-737-002
Observation:
Applications:
• Automatic street lights
• Daylight sensing for energy-saving
• Security systems
• Photography exposure control
• Environmental monitoring
1604-20-737-002
4. Aim:
To Interface IR Sensor with Arduino UNO.
Description:
An IR sensor detects infrared radiation emitted or reflected by objects. By interfacing this sensor
with an Arduino Uno, we can detect the presence or absence of objects based on their reflection
of infrared light.
Components Required:
Procedure (Steps):
• Identify the LDR Sensor Pins: LDRs usually have two pins. Sometimes they may have
a third pin (e.g., for a built-in resistor, but not always). Identify the two main pins.
• Connect the LDR and Resistor in Series: Connect one leg of the LDR to the 5V output
on the Arduino UNO. Connect the other leg of the LDR to one leg of the resistor.
Connect the free leg of the resistor to one of the analog pins on the Arduino UNO (e.g.,
A0).
• Connect the Free End of the LDR to GND: Connect the free leg of the LDR (not
connected to the resistor) to one of the GND (ground) pins on the Arduino UNO.
• Upload Arduino Sketch: Open the Arduino IDE on your computer.
1604-20-737-002
Sketch (Code):
void setup()
{
Serial.begin(9600);
Serial.println("serial working");
pinMode (IRSensor, INPUT); // sensor pin INPUT
pinMode (LED, OUTPUT); // Led pin OUTPUT
}
void loop()
{
int statusSensor = digitalRead (IRSensor);
if (statusSensor == 1)
{
digitalWrite(LED, LOW); // LED LOW
Serial.println("object detected");
}
else
{
digitalWrite(LED, HIGH); // LED High
Serial.println("object not detected");
}
1604-20-737-002
Observation:
Applications:
1604-20-737-002
5. Aim:
To Interface Ultra-Sonic Sensor with Arduino UNO.
Description:
The ultrasonic sensor module is a commonly used component for distance measurement and
object detection. It comprises two main elements: a transmitter and a receiver. Operating on the
principle of sound wave reflection, the module sends out high-frequency ultrasonic pulses from
its trigger pin (TRIG). These pulses travel through the air and bounce off objects, with the
reflected signals detected by the module's echo pin (ECHO). By measuring the time it takes for
the pulse to travel to the object and back, the module calculates the distance based on the
speed of sound in air. This distance information is then provided as a digital or PWM signal,
which can be processed by a microcontroller such as the Arduino Uno for various applications.
Components Required:
Procedure (Steps):
• Identify the Ultrasonic Sensor Pins: The HC-SR04 ultrasonic sensor typically has four
pins: VCC (power), GND (ground), Trig (trigger), and Echo (echo/receive).
1604-20-737-002
• Connect Power and Ground: Connect the VCC pin of the ultrasonic sensor to the 5V
output on the Arduino UNO.Connect the GND pin of the ultrasonic sensor to one of the
GND (ground) pins on the Arduino UNO.
• Connect Trigger and Echo Pins: Connect the Trig (trigger) pin of the ultrasonic sensor
to any digital pin on the Arduino UNO. For example, use pin 9.Connect the Echo
(echo/receive) pin of the ultrasonic sensor to another digital pin on the Arduino UNO.
For example, use pin 8
• Upload Arduino Sketch: Open the Arduino IDE on your computer.Write or copy an
Arduino sketch to read data from the ultrasonic sensor.
Sketch (Code):
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time //in
microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
Serial.println(" cm");
}
1604-20-737-002
Observation:
Applications:
• Distance measurement
• Object detection and avoidance
• Robotics
• Security systems
• Parking assistance systems
• Proximity sensing
1604-20-737-002
6. Aim:
To Interface LCD 16X2 with Arduino UNO (Hello Word).
Description:
Interfacing an LCD (Liquid Crystal Display) with an Arduino UNO is a common project for
displaying information and feedback. LCDs come in different types, such as 16x2 or 20x4
character LCDs. The 16x2 LCD module is a display component that interfaces with the Arduino
Uno to showcase information.It consists of a 16-character, 2-line display with pins for power,
ground, contrast adjustment, data transfer, and control signals. The Arduino sends data and
control signals to the LCD module, instructing it to display text or other information on its
screen. This setup provides a simple and effective means of visualizing data and messages in
Arduino projects.
Components Required:
Procedure (Steps):
. Here are the steps to interface a 16x2 LCD with an Arduino UNO:
• Identify the I2C LCD Pins: A typical I2C LCD module has four pins: VCC (power),
GND (ground), SDA (data), and SCL (clock).
1604-20-737-002
• Connect Power and Ground: Connect the VCC pin of the I2C LCD module to the 5V
output on the Arduino UNO. Connect the GND pin of the I2C LCD module to one of the
GND (ground) pins on the Arduino UNO.
• Connect SDA and SCL Pins: Connect the SDA pin of the I2C LCD module to the A4
pin on the Arduino UNO Connect the SCL pin of the I2C LCD module to the A5 pin on
the Arduino UNO.
• Upload Arduino Sketch: Open the Arduino IDE on your computer. Install the
LiquidCrystal_I2C library if you haven't already. You can do this by going to Sketch >
Include Library > Manage Libraries and then searching for "LiquidCrystal_I2C" and
installing it. Write or copy an Arduino sketch to initialize the I2C LCD and display text.
Sketch (Code):
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.clear(); // Clear the LCD screen
void loop() {
// Print "Hello, world!" on the LCD
lcd.print("Hello, world!");
delay(1000); // Wait for 1 second
lcd.clear(); // Clear the LCD screen
1604-20-737-002
for (int positionCounter = 0; positionCounter < 13;
positionCounter++) {
lcd.scrollDisplayRight(); // Scroll one position right
delay(1000); // Wait for 1 second
}
lcd.clear(); // Clear the LCD screen
delay(1000); // Wait for 1 second
}
Observation:
Applications:
• Basic introduction to interfacing an LCD with an Arduino Uno.
• Education and learning about display technologies and microcontroller
programming.
• Prototyping and developing projects requiring visual feedback or information
display.
• DIY electronics projects and hobbyist applications involving text display or user
interaction.
1604-20-737-002
7. Aim:
To Interface LCD 16X2 and DHT-11 Sensor with Arduino UNO.
Description:
In this, we will connect a 16x2 LCD module and a DHT11 sensor to an Arduino Uno. The DHT11
sensor will measure temperature and humidity, while the Arduino Uno will collect this data and
display it on the LCD screen. This setup enables real-time monitoring of environmental
conditions.
Components Required:
Procedure (Steps):
1604-20-737-002
• Connect the GND pin of the DHT11 sensor to one of the GND (ground) pins on the
Arduino.
• Connect the DATA pin of the DHT11 sensor to any digital pin on the Arduino. For
example, use pin 2.
Connect the I2C LCD:
• Connect the VCC pin of the 16x2 I2C LCD module to the 5V output on the Arduino.
• Connect the GND pin of the LCD module to one of the GND (ground) pins on the
Arduino.
• Connect the SDA pin of the LCD module to the A4 pin on the Arduino (analog pin used
for data in I2C communication).
• Connect the SCL pin of the LCD module to the A5 pin on the Arduino (analog pin used
for clock in I2C communication).
Upload Arduino Sketch:
• Open the Arduino IDE on your computer.
• Make sure you have the Wire and LiquidCrystal_I2C libraries installed. You can install
them by going to Sketch > Include Library > Manage Libraries and searching for "Wire"
and "LiquidCrystal_I2C."
• Write or copy an Arduino sketch to read data from the DHT11 sensor, display
temperature and humidity on the I2C LCD.
Sketch (Code):
#include <DHT11.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.clear();
}
void loop()
{
1604-20-737-002
// put your main code here, to run repeatedly:
// Read the humidity from the sensor.
int humidity = dht11.readHumidity();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
//lcd.setCursor(0,0);
lcd.print("Temperature: ");
lcd.print(temperature);
lcd.print(" C");
//lcd.setCursor(0,1);
delay(100);
//lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
}
else
{
// If the temperature or humidity reading failed,
//print an error message.
Serial.println("Error reading data");
}
1604-20-737-002
Observation:
Applications:
1604-20-737-002
8. Aim:
To Interface LCD 16X2 and LDR Sensor with Arduino UNO.
Description:
In this project, the Arduino Uno will interface with both the 16x2 LCD module and the LDR
sensor. The LDR sensor will detect light intensity variations, while the Arduino Uno will read this
data and display it on the LCD module. The LDR sensor will be connected to one of the analog
pins of the Arduino Uno, and the 16x2 LCD module will be connected via digital pins, typically
using the I2C communication protocol for simplicity.
Components Required:
Procedure (Steps):
• Identify the LDR Pins: An LDR typically has two pins. Connect one end to the 5V output
on the Arduino and the other end to the analog pin (e.g., A0) on the Arduino.
• Connect the Resistor: Connect one leg of the 10kΩ resistor to the same analog pin
(e.g., A0) on the Arduino where you connected the LDR. Connect the other leg of the
resistor to the GND (ground) on the Arduino.
1604-20-737-002
• Connect the I2C LCD: Connect the VCC pin of the 16x2 I2C LCD module to the 5V
output on the Arduino. Connect the GND pin of the LCD module to one of the GND
(ground) pins on the Arduino. Connect the SDA pin of the LCD module to the A4 pin on
the Arduino (analog pin used for data in I2C communication). Connect the SCL pin of
the LCD module to the A5 pin on the Arduino (analog pin used for clock in I2C
communication).
• Upload Arduino Sketch: Open the Arduino IDE on your computer. Make sure you have
the Wire and LiquidCrystal_I2C libraries installed. You can install them by going to
Sketch > Include Library > Manage Libraries and searching for "Wire" and
"LiquidCrystal_I2C."
Write or copy an Arduino sketch to read data from the LDR and display
it on the I2C LCD.
Sketch (Code):
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("LDR and LCD Demo");
void loop() {
// Read the LDR value
int ldrValue = analogRead(ldrPin);
1604-20-737-002
// Print LDR value to Serial Monitor for debugging
Serial.print("LDR Value: ");
Serial.println(ldrValue);
Observation:
Applications:
1604-20-737-002
9. Aim:
To Interface LCD 16X2 and IR Sensor with Arduino UNO.
Description:
The IR sensor module is composed of three pins: VCC (power), GND (ground), and OUT (signal).
It functions by detecting infrared radiation emitted by objects within its field of view. Connected
to a +5V power source through the VCC pin and to the ground terminal via the GND pin, the
module continually scans its environment for infrared radiation. Upon detecting such radiation
emitted by an object within its detection range, the module outputs a digital signal from the
OUT pin, transitioning from LOW (0V) to HIGH (+5V). With a detection range typically spanning
from a few centimeters to several meters, the IR sensor module finds applications in proximity
sensing, obstacle detection, motion detection, and infrared remote control systems. Due to its
simplicity and effectiveness in detecting infrared radiation, it is widely used in various electronic
projects and systems.
Components Required:
1604-20-737-002
Procedure (Steps):
Here is the procedure to interface an IR sensor with an Arduino Uno and connect an I2C
LCD module:
• IR Sensor Connections:
• Connect the VCC pin of the IR sensor to the 5V output on the Arduino
Uno.
• Connect the GND pin of the IR sensor to one of the GND (ground) pins on
the Arduino Uno.
• Connect the OUT pin of the IR sensor to any digital pin on the Arduino
Uno. For example, use pin 2.
• I2C LCD Connections:
• Connect the VCC pin of the 16x2 I2C LCD module to the 5V output on the
Arduino Uno.
• Connect the GND pin of the LCD module to one of the GND (ground) pins
on the Arduino Uno.
• Connect the SDA pin of the LCD module to the A4 pin on the Arduino Uno
(analog pin used for data in I2C communication).
• Connect the SCL pin of the LCD module to the A5 pin on the Arduino Uno
(analog pin used for clock in I2C communication).
• Upload Arduino Sketch:
• Open the Arduino IDE on your computer.
• Make sure you have the Wire and LiquidCrystal_I2C libraries installed. You
can install them by going to Sketch > Include Library > Manage Libraries
and searching for "Wire" and "LiquidCrystal_I2C."
• Write or copy an Arduino sketch to read data from the IR sensor, detect
infrared signals, and display the status on the I2C LCD.
Sketch (Code):
//#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int IRSensor = 2;
1604-20-737-002
lcd.backlight();
lcd.clear();
pinMode(IRSensor, INPUT); // IR Sensor pin INPUT
}
void loop()
{
int sensorStatus = digitalRead(IRSensor);
if (sensorStatus == 1) // Check if the pin high or not
{
lcd.setCursor(0,0);
lcd.print("NO OBSTACLE!!");
Serial.println("NO OBSTACLE!!");
// print Motion Detected! on the serial monitor window
}
else
{
lcd.clear();
delay(1000);
lcd.setCursor(0,0);
lcd.print("OBSTACLE!!");
Serial.println("OBSTACLE!!");
}
Observation:
1604-20-737-002
Applications:
• Object detection
• Proximity sensing
• Home automation
• Security systems
• Robotics
1604-20-737-002
10. Aim:
To Interface LCD 16X2 and Ultra-Sonic Sensor with Arduino
UNO.
Description:
The ultrasonic sensor module, exemplified by the HC-SR04, consists of four pins: VCC (power
supply), GND (ground), TRIG (trigger), and ECHO (echo). The VCC and GND pins provide power
and ground connections, respectively, typically connected to +5V and ground on the Arduino.
The TRIG pin is used to trigger the sensor to emit ultrasonic waves, while the ECHO pin receives
the waves reflected off objects. Upon receiving a trigger signal, the sensor emits a burst of
ultrasonic waves and waits for the echo. By measuring the time it takes for the echo to return,
the sensor can calculate the distance to the object using the speed of sound.
Components Required:
Procedure (Steps)
To interface an ultrasonic sensor with a 16x2 LCD with a 4-pin I2C interface using an Arduino UNO, you
can follow these connection steps. For this example, we'll use the HC-SR04 ultrasonic sensor and a
common 16x2 I2C LCD module.
1604-20-737-002
Connect the Ultrasonic Sensor:
• Connect the VCC pin of the HC-SR04 to the 5V output on the Arduino.
• Connect the GND pin of the HC-SR04 to one of the GND (ground) pins on the Arduino.
• Connect the Trig pin of the HC-SR04 to any digital pin on the Arduino. For example, use
pin 7.
• Connect the Echo pin of the HC-SR04 to any digital pin on the Arduino. For example,
use pin 6.
Connect the I2C LCD:
• Connect the VCC pin of the 16x2 I2C LCD module to the 5V output on the Arduino.
• Connect the GND pin of the LCD module to one of the GND (ground) pins on the
Arduino.
• Connect the SDA pin of the LCD module to the A4 pin on the Arduino (analog pin used
for data in I2C communication).
• Connect the SCL pin of the LCD module to the A5 pin on the Arduino (analog pin used
for clock in I2C communication).
Upload Arduino Sketch:
• Open the Arduino IDE on your computer.
• Make sure you have the Wire and LiquidCrystal_I2C libraries installed. You can install
them by going to Sketch > Include Library > Manage Libraries and searching for "Wire"
and "LiquidCrystal_I2C."
• Write or copy an Arduino sketch to read data from the ultrasonic sensor, calculate
distance, and display it on the I2C LCD.
Sketch (Code):
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Defines variables
long duration;
int distance;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
1604-20-737-002
lcd.clear();
Serial.begin(9600);
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Reads the echoPin, returns the sound wave travel time //in
microseconds
duration = pulseIn(echoPin, HIGH);
delay(1000);
// Adjust delay as needed for your application
}
Observation:
1604-20-737-002
Applications:
• Distance measurement
• Object detection
• Robotics
• Security systems
1604-20-737-002
11. Aim:
To Interface an LED with Raspberry pi 3 B+ (Blinking LED).
Description:
In this project, we'll interface an LED (Light Emitting Diode) with a Raspberry Pi
3 B+ and write a Python program to make the LED blink at regular intervals. The
Raspberry Pi will control the LED using one of its GPIO (General Purpose Input
Output) pins.
Components Required:
Procedure (Steps):
1604-20-737-002
• Connect the longer leg (anode) of the LED to one of the breadboard rows.
• Connect the shorter leg (cathode) of the LED to a different row on the
breadboard.
• Connect the resistor:
• Connect one end of the resistor to the same row as the cathode of the LED.
• Connect the other end of the resistor to a GND (ground) pin on the Raspberry Pi.
• Connect the GPIO pin:
• Connect a jumper wire from a GPIO pin on the Raspberry Pi to the row where the
LED anode is connected.
• Write a Python script:
• Open a text editor on your Raspberry Pi and write a Python script to blink the
LED. Save the script with a .py extension, for example, blink_led.py.
Sketch (Code):
import RPi.GPIO as GPIO
import time
LED_PIN = 23
GPIO.setmode(GPIO.BCM)
GPIO.setup(LED_PIN, GPIO.OUT)
try:
while True:
GPIO.output(LED_PIN, GPIO.HIGH)
time.sleep(1)
GPIO.output(LED_PIN, GPIO.LOW)
time.sleep(1)
except keyboardInterrupt:
GPIO.cleanup()
1604-20-737-002
Observation:
Applications:
This project demonstrates the basic interaction between hardware (LED) and
software (Python program) using the GPIO pins of the Raspberry Pi. It can serve
as a foundation for more complex projects involving GPIO-based control and
interfacing with various sensors and actuators.
12. Aim:
1604-20-737-002
To Interface DHT-11 Sensor with Raspberry pi 3 B+.
Description:
Components Required:
Procedure (Steps):
Sketch (Code):
import RPi.GPIO as GPIO
import time
import Adafruit_DHT
sensor=Adafruit_DHT.DHT11
pin=4
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor, GPIO.IN)
#GPIO.setup(led, GPIO.OUT)
while True:
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C
Humidity={1:0.1f}%'.format(temperature, humidity))
else:
print('failed To read')
Observation:
1604-20-737-002
Applications:
• Environmental monitoring.
• Home automation.
• Weather stations.
• Agricultural applications.
13. Aim:
To Interface LDR Sensor with Raspberry pi 3 B+.
1604-20-737-002
Description:
This project involves interfacing a Light Dependent Resistor (LDR) sensor with
a Raspberry Pi 3 B+. The LDR sensor detects changes in ambient light intensity
and converts it into a corresponding electrical signal. The Raspberry Pi reads
this signal and processes it to perform various actions, such as logging data,
controlling lights, or triggering alarms.
Components Required:
Procedure (Steps):
1604-20-737-002
• Connect the other leg of the LDR sensor to one leg of the resistor.
• Connect the other leg of the resistor to a GPIO pin on the Raspberry Pi. This will
be the pin you use to read the sensor's output.
• Connect a jumper wire from the junction of the LDR and resistor to a ground
(GND) pin on the Raspberry Pi.
• Write a Python Script to Read LDR Sensor:
• Open a text editor on your Raspberry Pi and write a Python script to read the
resistance across the LDR sensor. Save the script with a .py extension, for
example, ldr_sensor.py.
Sketch (Code):
import RPi.GPIO as GPIO
import time
sensor = 16
#led = 13
GPIO.setmode(GPIO.BOARD)
GPIO.setup(sensor, GPIO.IN)
#GPIO.setup(led, GPIO.OUT)
try:
while True:
if (GPIO.input(sensor)==1):
#GPIO.output(led.True)
#print(GPIO.input(sensor))
print("Light Not Detected")
elif (GPIO.input(sensor)==0):
#GPIO.output(led.False)
#print(GPIO.input(sensor))
print("Light Detected")
except keyboardInterrupt:
GPIO.cleanup()
Observation:
1604-20-737-002
Applications:
14. Aim:
To Interface IR Sensor with Raspberry pi 3 B+.
1604-20-737-002
Description:
In this project, we will learn about Infrared Sensors, simply known as IR Sensor and how to
interface an IR Sensor with Raspberry Pi. By interfacing this IR Sensor with Raspberry Pi, you
can implement a Proximity Sensor Application (Obstacle Detection).
IR Sensors emit and receive Infrared radiation. They are often used as Proximity Sensors i.e.
detect and alarm if an object is close to the sensor.
Almost all mobile phones nowadays have IR Sensors in them. Usually, they will be placed near
the earpiece on the phone.
When the user makes or receives a phone call, the IR Sensor detects how far the phone is from
the user’s ear. If it is close to the ear, the phone’s display will be turned off so that you do not
touch anything on the screen accidently.
Another important application is in automobiles. All modern cars are equipped with reverse
parking sensor that sense how far you can reverse your car without hitting anything. These
reverse sensors are implemented using IR Sensors.
Components Required:
• Raspberry Pi 3 Model B
• IR Sensor
• 5V Buzzer
• Mini Breadboard
• Connecting Wires
• Power Supply
• Computer
1604-20-737-002
Procedure (Steps):
Interfacing an IR (Infrared) sensor with a Raspberry Pi involves connecting the sensor to the
GPIO pins and then reading the sensor's output in a Python script.
• Identify IR Sensor Pins:
• An IR sensor typically has three pins: VCC (power), GND (ground), and OUT
(signal). Refer to the datasheet or documentation for your specific IR sensor
model to identify the pin out.
• Connect the IR Sensor to Raspberry Pi:
• Connect the VCC pin of the IR sensor to a 5V GPIO pin on the Raspberry Pi.
• Connect the GND pin of the IR sensor to a ground (GND) pin on the Raspberry
Pi.
• Connect the OUT pin of the IR sensor to a GPIO pin on the Raspberry Pi. Choose
a pin that you will use to read the sensor's output.
• Write a Python Script to Read IR Sensor:
• Open a text editor on your Raspberry Pi and write a Python script to read the
output from the IR sensor. Save the script with a .py extension, for example,
ir_sensor.py.
Sketch (Code):
1604-20-737-002
import RPi.GPIO as GPIO
import time
try:
while True:
# Read the IR sensor state
ir_sensor_state = GPIO.input(ir_sensor_pin)
except KeyboardInterrupt:
# Clean up GPIO on Ctrl+C exit
GPIO.cleanup()
1604-20-737-002
Observation:
Applications:
• Proximity sensing
• Object detection and counting
• Line following robot
• Motion detection
• Temperature measurement
• Remote controls
• Occupancy detection
• Gesture recognition
15. Aim:
To Interface Ultra-Sonic Sensor with Raspberry pi 3 B+.
1604-20-737-002
Description:
Components Required:
• Raspberry Pi 3 B+ (or any model with GPIO pins)
• Ultrasonic sensor (e.g., HC-SR04)
• Jumper wires
Procedure (Steps):
• Connect Ultrasonic Sensor to Raspberry Pi:
Connect the VCC pin of the ultrasonic sensor to the 5V pin of the Raspberry Pi.
• Connect the GND pin of the ultrasonic sensor to any GND pin on the
Raspberry Pi.
1604-20-737-002
• Connect the Trig pin of the ultrasonic sensor to a GPIO pin (e.g., GPIO 23)
on the Raspberry Pi.
• Connect the Echo pin of the ultrasonic sensor to another GPIO pin (e.g.,
GPIO 24) on the Raspberry Pi.
• Calculate Distance:
Use the formula distance = (time * speed_of_sound) / 2 to calculate the distance.
The speed of sound is approximately 343 meters per second (at room
temperature).
• Display Distance
Sketch (Code):
# Libraries
import RPi.GPIO as GPIO
import time
def distance():
# set Trigger To HIGH
GPIO.output(GPIO_TRIGGER, True)
1604-20-737-002
StartTime = time.time()
StopTime = time.time()
# save StartTime
while GPIO.input(GPIO_ECHO) == 0:
StartTime = time.time()
return distance
if __name__ == '__main__':
try:
while True:
dist = distance()
print ("Measured Distance = %.1f cm" % dist)
time.sleep(1)
Observation:
1604-20-737-002
Applications:
• Object detection
• Obstacle avoidance
• Distance measurement
• Security systems
16. Aim:
To Interface Bluetooth Module with Arduino UNO.
1604-20-737-002
Description:
HC-05 is one of the commonly used Bluetooth device that uses a UART communication protocol.
The HC-05 Bluetooth is much different in features from all other Bluetooth devices because of its
multiple pins and their functions. It has multiple pins for the different method which makes it
unique as compared to others. The module normally operates at UART serial communication with
TX and RX pins at 9600 baud rates.
Its CSR Bluecore 04-External single chip is already configured to communicate with other
Bluetooth devices through serial communication. It offers a two-way communication method and
the HC-05 can act as either slave and master. The Bluetooth module offers only short distance
communications due to its limitation but still, most of the devices come with it due to its speed and
security. The limitation of this device is that it doesn’t allow to transfer any kind of media.
The HC-05 comes with multiple pins and indicators, which helps to control different operations
and view their states through indicators. This pinout diagram provides indications of all pins.
Pin Description
The operating voltage range is 3.3 volts. But I/O pins can withstand voltage of up
VCC to 5 volts. Therefore, we can connect 5 volts power source to this pin, and also
other pins can also operate on 5 volts signals such as Tx and Rx signals.
Ground reference of both ESP8266 and HC-05 should be at the same level.
GND Therefore, we should connect a power supply, HC05, and ESP8266 ground pins
to each other.
As discussed earlier, the HC-05 Bluetooth module uses UART communication to
Tx transmit data. This is a transmitter pin. The TX pin will be the data transfer pin
of the module in UART.
This pin is a data receiving the pin in UART communication. It is used to receive
Rx
data from the microcontroller and transmits it through Bluetooth.
The state shows the current state of the Bluetooth. It gives feedback to the
State controller about the connectivity of Bluetooth with another device. This pin has
an internal connection with the onboard LED which shows the working of HC05.
Using an external signal, Enable/Key pin is used to change the HC-05 mode
between data mode and command mode. The HIGH logic input will transfer the
Enable/Key
device in command mode and the LOW logic input will change the mode to data
mode. By default, it works in data mode.
1604-20-737-002
The command and data mode states are changeable through a button present on
Button
the module.
LED This pin shows the working status of module along with the State pin
Components Required:
• Arduino Uno (or Mega, Pro Mini, Nano – but in this tutorial we use the Arduino
UNO)
• Relay module.
• HC-05 Wireless Bluetooth Module.
• Lamp.
• Breadboard.
• Jumper wires.
• Arduino bluecontrol app.
Procedure (Steps):
• Download the “Bluetooth Terminal” App from Android playstore on your android phone.
• Open the app and connect with HC-05 Bluetooth.
In your smartphone settings, enable Bluetooth and scan for available Bluetooth devices. You will
see the HC-05 device in your scanned list. The default name for this Bluetooth device is “HC-05”
and the default pin code is either “0000” or “1234”.
1604-20-737-002
Setting up Android App
We will use an android smartphone to connect with our ESP8266 module. To do that you will have
to perform a series of steps.
After you have installed the ‘Serial Bluetooth Terminal app, open it. On the top left corner of the
screen, you will find three horizontal bars. Tap it.
1604-20-737-002
Now, tap on the Devices tab./
After you have selected the HC-05 module then tap the ‘link’ icon at the top of the screen. At first,
you will get the message: ‘Connecting to HC-05.’ After a successful connection, you will get the
message: ‘Connected.
• Download the “Bluetooth Terminal” App from Android playstore on your android phone.
• Open the app and connect with HC-05 Bluetooth.
• Send 1 to turn on the LED.
• Send 0 to turn off the LED.
1604-20-737-002
NOTE:
In your smartphone settings, enable Bluetooth and scan for available Bluetooth devices. You will
see the HC-05 device in your scanned list. The default name for this Bluetooth device is “HC-
05” and the default pin code is either “0000” or “1234”.
Sketch (Code):
#include <SoftwareSerial.h>
#define ledPin 13
SoftwareSerial EEBlue(10, 11); // RX | TX
int state = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
EEBlue.begin(9600);
//Default Baud for comm, it may be different for your //Module.
Serial.println("The bluetooth is ready.\n Connect To HC-05
from any other bluetooth device with 1234 as pairing key!.");
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if(EEBlue.available() > 0){
// Checks whether data is comming from the serial port
state = EEBlue.read();
1604-20-737-002
// Reads the data from the serial port
}
if (state == '0') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF");
// Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");
state = 0;
}
Observation:
1604-20-737-002
Applications:
1604-20-737-002
17. Aim:
To Interface GSM Module with Arduino UNO.
Description:
The Global System for Mobile Communication, or GSM Modules for short, provides us with
cellular capabilities. We can use these modules to connect to the cellular network and make or
receive phone calls, SMS, or GPRS. GSM modules are used in projects for remote monitoring,
IOT projects, location tracking, and even sending SMS alerts. GSM modules play a crucial role
in enabling communication and connectivity in various devices and systems, making them an
essential component in modern-day IoT devices where Wi-Fi and Ethernet are not available.
D5 This LED remains on, but whenever a call arrives, it starts flashing.
This LED indicates the connection status of the GSM module. In case the GSM is not
connected to any cellular network; this LED blinks every second. Once the GSM
D6
module connects to the cellular network, this LED starts blinking every 3 seconds,
indicating a successful connection.
Pinof
SIM900A Pin of Arduino Board
GSM Module
Tx Rx
Rx Tx
GND GND
1604-20-737-002
Components Required:
Procedure (Steps):
In this section we have listed the steps to successfully boot our SIM900A GSM Module:
• Insert the SIM card into the GSM module and lock it.
• Connect the adapter to the GSM module and turn it ON!
1604-20-737-002
• Now wait for some time (say 1 minute) and see the blinking rate of the status LED’ or
‘network LED’ (the GSM module will take some time to establish a connection with the
mobile network).
• Once the connection is established successfully, the status/network LED will blink
continuously every 3 seconds. You may try making a call to the mobile number of the SIM
card inside the GSM module. If you hear a ring back, the GSM module has successfully
established a network connection.
Open the Arduino IDE and go to File > New to create a new file. Now copy this sketch given
below and paste it in the Arduino File. Select the COM port of the connected Arduino board and
click Upload. This will upload the sketch to the Arduino board.
Sketch (Code):
//Receive SMS
#include <SoftwareSerial.h>
void setup()
{
//Begin serial communication with Arduino and Arduino IDE
//(Serial Monitor)
Serial.begin(9600);
Serial.println("Initializing...");
delay(1000);
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
gsmSerial.write(Serial.read());
//Forward what Serial received to Software Serial Port
}
while(gsmSerial.available())
{
Serial.write(gsmSerial.read());
//Forward what Software Serial received to Serial Port
}
}
//Send SMS
#include <SoftwareSerial.h>
void setup()
{
//Begin serial communication with Arduino and Arduino IDE
//(Serial Monitor)
Serial.begin(9600);
Serial.println("Initializing...");
delay(1000);
void loop()
{
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
gsmSerial.write(Serial.read());
//Forward what Serial received to Software Serial Port
}
while(gsmSerial.available())
{
Serial.write(gsmSerial.read());
//Forward what Software Serial received to Serial Port
}
}
Observation:
1604-20-737-002
Applications:
The SIM900A GSM Module has many features, these features are listed below:
1604-20-737-002
18. Aim:
To Interface XBee Module with Arduino Uno.
Description:
This program involves interfacing an XBee module with an Arduino Uno for
wireless communication. XBee modules are commonly used for wireless
communication in IoT, robotics, and remote sensing applications. By interfacing
an XBee module with an Arduino Uno, you can establish wireless
communication between multiple devices, enabling data transmission over a
significant distance.
Components Required:
Procedure (Steps):
1604-20-737-002
• Connect the XBee Explorer USB to your computer.
• Open XCTU and select the correct COM port.
• Click on the "Discover Radio Modules" button to identify your XBee module.
• Configure settings like PAN ID, channel, and baud rate. Ensure the settings match on all
XBee modules you plan to use.
• Write the configuration to the XBee module.
3. Connect XBee to Arduino:
• Remove the XBee module from the XBee Explorer USB.
• Connect the XBee module to the Arduino using jumper wires.
• Connect XBee VCC to Arduino 5V.
• Connect XBee GND to Arduino GND.
• Connect XBee DOUT to Arduino RX (pin 2).
• Connect XBee DIN to Arduino TX (pin 3).
4. Power the Arduino:
• Power the Arduino board using a USB cable or an external power source.
5. Write Arduino Code:
• Write Arduino code to initialize the Serial communication and read/write data through the
XBee module.
• You can use the SoftwareSerial library if you want to use other pins for communication.
Sketch (Code):
//XBee_Tx
#include <SoftwareSerial.h>
SoftwareSerial xbeeSerial(2,3); //RX, TX
void setup() {
Serial.begin(9600);
xbeeSerial.begin(9600);
}
void loop() {
if(Serial.available() > 0){
char input = Serial.read();
xbeeSerial.print(input);
}
}
//XBee_Rx
#include <SoftwareSerial.h>
SoftwareSerial xbeeSerial(2,3); //RX, TX
void setup() {
Serial.begin(9600);
1604-20-737-002
xbeeSerial.begin(9600);
}
void loop() {
if(xbeeSerial.available() > 0){
char input = xbeeSerial.read();
Serial.print(input);
}
}
Observation:
Applications:
• Wireless sensor networks: Deploying multiple sensor nodes with XBee
modules to collect data wirelessly and transmit it to a central hub (Arduino
Uno or another device).
• Remote monitoring and control: Using XBee modules to remotely monitor
and control devices or systems in IoT, home automation, or industrial
applications.
• Robotics: Implementing wireless communication between Arduino-based
robots or robot control systems for remote operation and data exchange.
1604-20-737-002
19. Aim:
To Log the Temperature and Humidity Data on the Thingspeak
Cloud platform using Raspberry pi 3 B+.
Description:
This project involves logging temperature and humidity data from a sensor
connected to a Raspberry Pi 3 B+ and sending this data to the ThingSpeak cloud
platform. ThingSpeak provides IoT services and allows you to visualize, analyze,
and react to data from sensors and other IoT devices.
Components Required:
Procedure (Steps):
ThingSpeak is an IoT analytics platform service that allows you to aggregate, visualize, and
analyze live data streams in the cloud. You can send data to ThingSpeak from your devices,
create instant visualization of live data, and send alerts.
1604-20-737-002
Environmental sensors allow us to measure the presence of pollution. ThingSpeak allows us to
store, see, and understand that data. Environmental data isn’t useful at the weather station or field
sensor.
ThingSpeak provides a number of features such as-
Putting your data in the cloud lets you monitor the data and act on it immediately.
Perform online analysis and data processing with MATLAB® and create automatic
visualizations from live processed data.
Build Internet of Things (IoT) systems without setting up servers or developing
websoftware.
For small- to medium-sized IoT systems, ThingSpeak provides a hosted solution that
youcan use in production.
In this experiment, Temperature and Humidity data is read from DHT-11 and the same data is
pushed onto cloud. Thingspeak API keys enable you to write data to a channel or read data from
a private channel. The HTTP POST request is executed by writing to a communication client
withouta separate library. Directly writing the HTTP request to the wireless network client can
offer increased flexibility and speed over the ThingSpeak Communication Library.
Data is read from the sensor and the same data is uploaded to ThingSpeak cloud. To upload data
on the cloud, a URL is executed using Python code. GET HTTP request is sent to the cloud.
Thus, Data is successfully uploaded to ThingSpeak cloud.
Sketch (Code):
import Adafruit_DHT
import os, sys
from time import sleep
import requests
import RPi.GPIO as GPIO
#GPIO.setmode(GPIO.BOARD)
baseURL =
'https://api.thingspeak.com/update?api_key=TX0O34YMD1YNADC'
SensorPin = 23
while True:
try:
print("Program is Running")
1604-20-737-002
humi, temp = Adafruit_DHT.read(Adafruit_DHT.DHT11,
SensorPin)
if (humi > 0 ) and (temp > 0):
print(humi)
print(temp)
print("Data received")
x = '{}{}{}{}{}'.format(baseURL, '&field1=', temp,
'&field2=', humi);
y = requests.post(x)
print(y.status_code)
print(x);
sleep(5)
except:
print("Data not received")
sleep(5)
Observation:
Applications:
1604-20-737-002
20. Aim:
To Communicate between Arduino and Raspberry pi 3 B+ using
serial cable.
Description:
Components Required:
1604-20-737-002
Procedure (Steps):
• For communication, we will use simple serial communication over USB cable.
Connect the LED to pin number 11.
• Turn on the Raspberry Pi and open Python 3 in a new window.
• Make sure the code is uploaded to Arduino.
• In your Raspberry Pi interface, be sure to enable Serial and I2C in PiConfig.
• Next, you'll need to restart your Raspberry Pi. Open the Terminal and execute these
commands:
sudo apt-get install python-serial
sudo pip install pyserial
• Connect your Arduino to your Raspberry Pi, and Execute. ls /dev/tty*.
• Then find a line with /dev/ttyACM0 or something like /dev/ttyACM1 etc. (check for an
ACM with any number 0,1,2 etc.)
• Open Python again and change ser=serial.Serial(“dev/ttyACM1”,9600) to the ACM
number you found. So, if in your case you got ACM0, the line should look like this:
ser=serial.Serial(“dev/ttyACM0”,9600).
• Now run the program you just created in Python3. You will see “Hello From Arduino!”
in the Python terminal, and your LED should be blinking as well.
Sketch (Code):
Arduino Code -
void setup() {
Serial.begin(9600); // Set the baud rate to 9600 bps
}
void loop() {
// Send a message to the Raspberry Pi
Serial.println("Hello from Arduino!");
try:
while True:
# Read data from Arduino
data = ser.readline().decode('utf-8').rstrip()
1604-20-737-002
if data:
print("Received from Arduino:", data)
Observation:
Applications:
1604-20-737-002