0% found this document useful (0 votes)
42 views73 pages

IoT Record

The document describes four experiments involving interfacing sensors with an Arduino Uno board: 1. Blinking an LED by connecting it to a digital pin on the Arduino and writing code. 2. Reading temperature and humidity values from a DHT11 sensor and printing them to the serial monitor. 3. Sensing light intensity with an LDR sensor and controlling an LED based on the reading. 4. Detecting objects that reflect infrared radiation using an IR sensor.

Uploaded by

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

IoT Record

The document describes four experiments involving interfacing sensors with an Arduino Uno board: 1. Blinking an LED by connecting it to a digital pin on the Arduino and writing code. 2. Reading temperature and humidity values from a DHT11 sensor and printing them to the serial monitor. 3. Sensing light intensity with an LDR sensor and controlling an LED based on the reading. 4. Detecting objects that reflect infrared radiation using an IR sensor.

Uploaded by

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

IoT Lab Questions

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

• Setup the Circuit:


• Connect the positive (anode) leg of the LED to a digital pin on the Arduino
Uno (e.g., pin 13).
• Connect the negative (cathode) leg of the LED to one end of a current-
limiting resistor (220-330 ohms).
• Connect the other end of the resistor to the ground (GND) pin on the
Arduino Uno.
• Write the Arduino Sketch:
• Open the Arduino IDE on your computer.
• Write a simple Arduino sketch to turn the LED on and off at regular
intervals
• Upload the Sketch:
• Connect the Arduino Uno to your computer using a USB cable.
• Select the appropriate board and port from the Arduino IDE menu.
• Click the "Upload" button to upload the sketch to the Arduino Uno.
• Run the Sketch:
• Once the sketch is uploaded, the Arduino Uno will start executing the
code.
• You should see the LED connected to pin 13 blinking on and off at 1-
second intervals.

1604-20-737-002
Sketch (Code):

void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on
//(HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by
//making the voltage LOW
delay(1000); // wait for a second
}

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 :

• Security Systems: To check the status of security systems


• Warning Signals: In battery-operated devices, LED blinking can be
used to indicate low battery levels.
• In Testing and debugging.
• Status Indication: LEDs can be used to indicate different states of a
system.

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:

• Arduino Uno board


• DHT11 temperature and humidity sensor
• Breadboard
• Jumper wires

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>

// Create an instance of the DHT11 class and set the //digital


I/O pin.
DHT11 dht11(2);

void setup() {
// Initialize serial communication at 9600 baud rate.
Serial.begin(9600);
}

void loop() {
// Read the humidity from the sensor.
float humidity = dht11.readHumidity();

// Read the temperature from the sensor.


float temperature = dht11.readTemperature();

// If the temperature and humidity readings were //successful,


print them to the Serial Monitor.
if (temperature != -1 && humidity != -1) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");

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

// Wait for 2 seconds before the next reading.


delay(2000);
}

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

Circuit Diagram (Connections):

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

const int ledPin = 13;


const int ldrPin = A0;

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:

• Arduino Uno board


• IR sensor module (e.g., TCRT5000)
• Resistor (10k ohms)
• Breadboard
• Jumper wires

Circuit Diagram (Connections):

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

int IRSensor = 2; // connect IR sensor to arduino pin 2


int LED = 13; // connect Led to arduino pin 13

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:

• Object detection and counting systems


• Proximity sensing for obstacle avoidance in robotics
• Motion detection in security systems
• Object tracking in automation
• Interactive installations and gaming interfaces

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:

• Arduino Uno board


• Ultrasonic sensor module (e.g., HC-SR04)
• Jumper wires
• Breadboard

Circuit Diagram (Connections):

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:

• Arduino Uno board


• 16x2 LCD module
• Potentiometer (for contrast adjustment)
• Breadboard
• Jumper wires

Circuit Diagram (Connections):

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

// Set the cursor to the beginning of the first line


lcd.setCursor(0, 0);
}

void loop() {
// Print "Hello, world!" on the LCD
lcd.print("Hello, world!");
delay(1000); // Wait for 1 second
lcd.clear(); // Clear the LCD screen

// Scroll the text to the left


for (int positionCounter = 0; positionCounter < 13;
positionCounter++) {
lcd.scrollDisplayLeft(); // Scroll one position left
delay(1000); // Wait for 1 second
}
lcd.clear(); // Clear the LCD screen
delay(1000); // Wait for 1 second

// Scroll the text to the right

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:

• Arduino Uno board


• 16x2 LCD module
• DHT11 sensor module
• Potentiometer (for LCD contrast adjustment)
• Breadboard
• Jumper wires

Circuit Diagram (Connections):

Procedure (Steps):

Connect the DHT11 Sensor:


• Connect the VCC pin of the DHT11 sensor to the 5V output on the Arduino.

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

// Create an instance of the DHT11 class and set the //digital


I/O pin.
DHT11 dht11(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();

// Read the temperature from the sensor.


int temperature = dht11.readTemperature();

// If the temperature and humidity readings were


//successful, print them to the serial monitor.
if (temperature != -1 && humidity != -1)
{
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");

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

// Wait for 2 seconds before the next reading.


delay(2000);
}

1604-20-737-002
Observation:

Applications:

• Environmental monitoring systems


• Weather stations
• Indoor climate control systems
• Greenhouse monitoring
• HVAC (Heating, Ventilation, and Air Conditioning) systems
• Smart home automation systems

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:

• Arduino Uno board


• 16x2 LCD module
• LDR sensor
• Jumper wires

Circuit Diagram (Connections):

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>

// Define the LCD address and dimensions


LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define the LDR pin


const int ldrPin = A0;

void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("LDR and LCD Demo");

// Serial communication for debugging


Serial.begin(9600);
}

void loop() {
// Read the LDR value
int ldrValue = analogRead(ldrPin);

// Display LDR value on LCD


lcd.setCursor(0, 1);
lcd.print("LDR Value: ");
lcd.print(ldrValue);

1604-20-737-002
// Print LDR value to Serial Monitor for debugging
Serial.print("LDR Value: ");
Serial.println(ldrValue);

delay(1000); // Wait for a second


}

Observation:

Applications:

• Ambient light sensing


• Automatic lighting control systems
• Security systems
• Photovoltaic systems
• Environmental monitoring

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:

• Arduino Uno board


• 16x2 LCD module
• IR sensor module (e.g., IR receiver or IR obstacle avoidance sensor)
• Potentiometer (optional, for LCD contrast adjustment)
• Breadboard
• Jumper wires

Circuit Diagram (Connections):

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;

// connect IR sensor module to Arduino pin 9

LiquidCrystal_I2C lcd(0x27, 16, 2);


void setup()
{
Serial.begin(9600);
lcd.init();

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

// Wait for 1 seconds before the next reading.


delay(1000);
}

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:

• Arduino Uno board


• 16x2 LCD module
• Ultrasonic sensor (e.g., HC-SR04)
• Breadboard
• Jumper wires

Circuit Diagram (Connections):

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>

LiquidCrystal_I2C lcd(0x27, 16, 2);


const int trigPin = 9;
const int echoPin = 10;

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

pinMode(trigPin, OUTPUT); // Set trigPin as an output


}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 microseconds


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 LCD


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" cm");

// Prints the distance on the Serial MoniTor


Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

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:

• Raspberry Pi 3 B+ (or any model with GPIO pins)


• LED (any color)
• Resistor (220 ohms is commonly used)
• Breadboard
• Jumper wires

Circuit Diagram (Connections):

Procedure (Steps):

• Identify GPIO pins:


• Locate the GPIO (General Purpose Input/Output) pins on your Raspberry Pi. You
can find a pinout diagram for your specific model online.
• Connect the LED to the breadboard:

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.

Applications of this project include:

• Learning about GPIO programming on Raspberry Pi.


• Prototyping simple IoT (Internet of Things) devices.
• Creating visual indicators or status lights for projects.
• Experimenting with hardware interfacing and control in educational
settings.
• Building DIY gadgets, toys, or interactive installations that involve blinking
LEDs.

12. Aim:
1604-20-737-002
To Interface DHT-11 Sensor with Raspberry pi 3 B+.

Description:

This project involves interfacing a DHT-11 sensor with a Raspberry Pi 3 B+ to


measure temperature and humidity. The DHT-11 sensor provides digital
output, making it suitable for connecting directly to the GPIO pins of the
Raspberry Pi. The Raspberry Pi reads data from the sensor and processes it to
display or log temperature and humidity readings.

Components Required:

• Raspberry Pi 3 B+ (or any model with GPIO pins)


• DHT-11 temperature and humidity sensor
• Breadboard (optional)
• Jumper wires

Circuit Diagram (Connections):

Procedure (Steps):

Connect DHT-11 Sensor to Raspberry Pi

Install Required Libraries

Ensure that your Raspberry Pi is connected to the internet.


1604-20-737-002
Install the Adafruit_DHT library for Python using the following command:
Copy code
pip install Adafruit_DHT

• Identify DHT11 Sensor Pins:


• A DHT11 sensor typically has four pins: VCC (power), GND (ground), DATA
(data), and NC (not connected). Refer to the datasheet or documentation for your
specific DHT11 sensor model to identify the pinout.
• Connect the DHT11 Sensor to Raspberry Pi:
• Connect the VCC pin of the DHT11 sensor to a 3.3V GPIO pin on the Raspberry
Pi.
• Connect the GND pin of the DHT11 sensor to a ground (GND) pin on the
Raspberry Pi.
• Connect the DATA pin of the DHT11 sensor to a GPIO pin on the Raspberry Pi.
• Connect a resistor (4.7k ohms) between the VCC and DATA pins of the DHT11
sensor.
• Write a Python Script to Read DHT11 Sensor:
• Open a text editor on your Raspberry Pi and write a Python script to read the
temperature and humidity measurements from the DHT11 sensor. Save the script
with a .py extension, for example, dht11_sensor.py.

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)

print("DHT sensor read....")


print(" ")

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:

• Raspberry Pi 3 B+ (or any model with GPIO pins)


• Light Dependent Resistor (LDR)
• Resistor (optional, for voltage divider circuit)
• Jumper wires

Circuit Diagram (Connections):

Procedure (Steps):

Interfacing an LDR (Light-Dependent Resistor) 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 LDR Sensor Pins:
• An LDR sensor typically has two pins. The resistance across the two pins changes
based on the amount of light falling on the sensor. There is no strict polarity, so
you can connect the pins interchangeably.
• Connect the LDR Sensor to Raspberry Pi:
• Connect one leg of the LDR sensor to a 3.3V GPIO pin on the Raspberry Pi.

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)

print("LDR sensor read....")


print(" ")

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:

• Ambient light sensing.


• Security systems.
• Energy conservation.
• Plant growth monitoring.
• Smart appliances.

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

Circuit Diagram (Connections):

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

# Set the GPIO mode To BCM


GPIO.setmode(GPIO.BCM)

# Set the GPIO pin where the IR sensor is connected


ir_sensor_pin = 18

# Set the GPIO pin as an input


GPIO.setup(ir_sensor_pin, GPIO.IN)

try:
while True:
# Read the IR sensor state
ir_sensor_state = GPIO.input(ir_sensor_pin)

# If the IR sensor detects an object, print a message


if ir_sensor_state == GPIO.HIGH:
print("Object detected!")

# Wait for a short duration


time.sleep(0.1)

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:

This project involves interfacing an ultrasonic sensor with a Raspberry Pi 3 B+


to measure distances. Ultrasonic sensors work by emitting high-frequency sound
waves and measuring the time it takes for the waves to bounce off an object and
return to the sensor. By measuring this time, the Raspberry Pi can calculate the
distance to the object.

Components Required:
• Raspberry Pi 3 B+ (or any model with GPIO pins)
• Ultrasonic sensor (e.g., HC-SR04)
• Jumper wires

Circuit Diagram (Connections):

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.

• Write Python Script to Read ULtrasonic Sensor:


Write a Python script to interface with the ultrasonic sensor.
Use the RPi.GPIO library to control the GPIO pins on the Raspberry Pi.
Configure the Trig pin as an output and the Echo pin as an input.
Send a short pulse to the Trig pin to trigger the ultrasonic sensor.
Measure the time it takes for the echo signal to return to calculate the distance
to the object.

• 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

• Run the Script

Sketch (Code):
# Libraries
import RPi.GPIO as GPIO
import time

#GPIO Mode (BOARD / BCM)


GPIO.setmode(GPIO.BOARD)

#set GPIO Pins


GPIO_TRIGGER = 18
GPIO_ECHO = 24

#set GPIO direction (IN / OUT)


GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)

def distance():
# set Trigger To HIGH
GPIO.output(GPIO_TRIGGER, True)

# set Trigger after 0.01ms To LOW


time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER, False)

1604-20-737-002
StartTime = time.time()
StopTime = time.time()

# save StartTime
while GPIO.input(GPIO_ECHO) == 0:
StartTime = time.time()

# save time of arrival


while GPIO.input(GPIO_ECHO) == 1:
StopTime = time.time()

# time difference between start and arrival


TimeElapsed = StopTime - StartTime
# multiply with the sonic speed (34300 cm/s)
# and divide by 2, because there and back
distance = (TimeElapsed * 34300) / 2

return distance

if __name__ == '__main__':
try:
while True:
dist = distance()
print ("Measured Distance = %.1f cm" % dist)
time.sleep(1)

# Reset by pressing CTRL + C


except KeyboardInterrupt:
print("Measurement stopped by user")
GPIO.cleanup()

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.

Circuit Diagram (Connections):

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

In the ‘available devices’ section, select ‘HC-05’

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.

Follow these steps to control LED:

• 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:

Bluetooth Rc car app


Wireless Serial Communication
Remote Control
Home Automation
Bluetooth-enabled Robotics
Data Logging and Monitoring
Wearable Electronics
Smart Agriculture
DIY Gadgets and Toys

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

SIM900A GSM Module

SIM900Ais an ultra-compact and reliable wireless module. It provides a complete Dual-band


GSM/GPRS solution in a Surface Mount Technology (SMT) module, which can be easily
integrated into customer applications. This module offers an industry-standard interface and
delivers excellent performance for voice, SMS, Data, and Fax over GSM/GPRS 900/1800 MHz
frequencies. Its small form factor (24mmx24mmx3mm) and low power consumption make it
suitable for various user applications, especially those with slim and compact design requirements.
For more information about SIM900A, you can find the SIM900A pinout details in the following
link: SIM900A pinout.

1604-20-737-002
Components Required:

• Arduino UNO board


• SIM900A GSM Module
• Jumper Wires
• Cellular Network Card or SIM card

Circuit Diagram (Connections):

Procedure (Steps):

How to Test SIM900A GSM Module with SIM

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>

//Create software serial object to communicate with SIM900


SoftwareSerial gsmSerial(8, 9);
//SIM800 Tx & Rx is connected to Arduino #8 & #9

void setup()
{
//Begin serial communication with Arduino and Arduino IDE
//(Serial Monitor)
Serial.begin(9600);

//Begin serial communication with Arduino and SIM800


gsmSerial.begin(9600);

Serial.println("Initializing...");
delay(1000);

gsmSerial.println("AT"); //Handshaking with SIM900


updateSerial();

gsmSerial.println("AT+CMGF=1"); // Configuring TEXT mode


updateSerial();
gsmSerial.println("AT+CNMI=1,2,0,0,0");
// Decides how newly arrived SMS messages should be handled
1604-20-737-002
updateSerial();
}

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>

SoftwareSerial gsmSerial(8, 9); // RX, TX

void setup()
{
//Begin serial communication with Arduino and Arduino IDE
//(Serial Monitor)
Serial.begin(9600);

//Begin serial communication with Arduino and SIM900


gsmSerial.begin(9600);

Serial.println("Initializing...");
delay(1000);

gsmSerial.println("AT"); //Handshaking with SIM900


updateSerial();

gsmSerial.println("AT+CMGF=1"); // Configuring TEXT mode


updateSerial();
gsmSerial.println("AT+CMGS=\"+ZZxxxxxxxxxx\"");
1604-20-737-002
//change ZZ with country code and xxxxxxxxxxx with phone
//number to sms
updateSerial();
gsmSerial.print("Happy SMS"); //text content
updateSerial();
gsmSerial.write(26);
}

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:

• Dual-Band 900/ 1800 MHz.


• GPRS multi-slot class 10/8GPRS mobile station class B.
• Compliant to GSM phase 2/2+Class 4 (2 W @850/ 900 MHz).
• Class 1 (1 W @ 1800/1900MHz).
• Control via AT commands (GSM 07.07,07.05 and SIMCOM enhanced AT Commands).
• Low power consumption: 1.5mA(sleep mode).
• Operation temperature: -40°C to +85 °C.

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:

• Arduino Uno board


• XBee module (e.g., XBee Series 2)
• XBee adapter or XBee shield for Arduino
• Jumper wires
• USB cable for Arduino Uno
• Power supply for XBee module (if required)

Circuit Diagram (Connections):

Procedure (Steps):

1. Connect XBee to XBee Explorer USB:


• Connect the XBee module to the XBee Explorer USB using the appropriate pins.
• Connect the XBee Explorer USB to your computer using a USB cable.
2. Configure XBee Module (Optional but recommended):
• Download and install XCTU (Xbee Configuration and Test Utility) on your computer.

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:

• Raspberry Pi 3 B+ (or any model with GPIO pins)


• DHT11 or DHT22 temperature and humidity sensor
• Jumper wires
• Internet connection for Raspberry Pi

Circuit Diagram (Connections):

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:

• Environmental monitoring: Monitoring temperature and humidity levels in


indoor or outdoor environments.
• Agriculture: Monitoring environmental conditions in greenhouses or farms
to optimize plant growth.
• Home automation: Integrating temperature and humidity sensing into
home automation systems for climate control and energy efficiency.
• Industrial monitoring: Monitoring temperature and humidity levels in
industrial settings to ensure optimal working conditions and equipment
performance.

1604-20-737-002
20. Aim:
To Communicate between Arduino and Raspberry pi 3 B+ using
serial cable.

Description:

Serial communication is established between an Arduino board and a


Raspberry Pi 3 B+ using a serial cable. The Arduino board sends data to the
Raspberry Pi, and the Raspberry Pi receives and processes the data. This setup
allows for data exchange between the two devices, enabling various
applications such as sensor data acquisition, robotics control, and IoT projects.

Components Required:

• Arduino board (e.g., Arduino Uno)


• Raspberry Pi 3 B+ (or any other model with GPIO pins)
• USB to TTL serial cable or USB to UART converter module
• Jumper wires

Circuit Diagram (Connections):

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

// Wait for a short duration


delay(1000);
}

Raspberry Pi Code (Python) -


import serial
import time

# Set the serial port and baud rate


ser = serial.Serial('/dev/ttyS0', 9600, timeout=1)

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)

time.sleep(1) # Wait for a short duration


except KeyboardInterrupt:
ser.close()
print("Serial communication closed.")

Observation:

Applications:

• Sensor Data Acquisition.


• Actuator Control.
• Home Automation.
• Robotics.
• Data Logging and Visualization.
• IoT Applications: Integrate Arduino sensors with Raspberry Pi to create Internet of
Things (IoT) applications for smart homes, agriculture, or industrial monitoring.

1604-20-737-002

You might also like