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

2024-25 Sem-II IoTL Lab Manual copy

The document is a lab manual for the Internet of Things Laboratory at the Pune Institute of Computer Technology for the academic year 2024-2025. It outlines course objectives, outcomes, problem statements, and assignments related to microcontrollers such as Raspberry Pi, Beagle Board, and Arduino, focusing on their applications in IoT. The manual also includes practical exercises on operating systems, logic gates, and sensor integration to enhance students' understanding and skills in the field of Artificial Intelligence and Data Science.

Uploaded by

studddy34
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)
0 views

2024-25 Sem-II IoTL Lab Manual copy

The document is a lab manual for the Internet of Things Laboratory at the Pune Institute of Computer Technology for the academic year 2024-2025. It outlines course objectives, outcomes, problem statements, and assignments related to microcontrollers such as Raspberry Pi, Beagle Board, and Arduino, focusing on their applications in IoT. The manual also includes practical exercises on operating systems, logic gates, and sensor integration to enhance students' understanding and skills in the field of Artificial Intelligence and Data Science.

Uploaded by

studddy34
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/ 52

PUNE INSTITUTE OF COMPUTER TECHNOLOGY

DHANKAWADI, PUNE – 43.

LAB MANUAL
ACADEMIC YEAR: 2024-2025
DEPT: ARTIFICIAL INTELLIGENCE & DATA SCIENCE
CLASS: S.E. SEMESTER: II
SUBJECT: 217531- INTERNET OF THINGS LABORATORY

Teaching Scheme: Credits Examination Scheme:


Practical: 04 Hours/Week 02 Term Work (TW): 50 Marks
Practical(PR): 25 Marks
Prerequisite Courses: Programming and Problem Solving (110005),
Basic Electronics Engineering (104010)
Companion Course: Internet of Things (217529)
Course Objectives
1 Hardware platforms and operating systems commonly used in IoT systems
2 Help the students in providing a good learning environment and also work with
real time problems faced in day-to-day life.

Course Outcomes: On completion of the course, learner will be able to–


CO1 Understand IOT Application Development using Raspberry Pi/ Beagle board/
Arduino board
CO2 Develop and modify the code for various sensor-based applications using wireless
sensor modules and working with a variety of modules like environmental
modules.
CO3 Make use of Cloud platform to upload and analyse any sensor data

CO-PO Mapping
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
CO1 2 1 3 - - - - - - - - -
CO2 - 2 3 - - - - - - - - -
CO3 - - 3 2 - - - - - - - 3
AVG 2 1.5 3 2 - - - - - - - 3

P:F-LTL-UG / 03 /R0
Sr. PROBLEM STATEMENTS
No.
Group A
1. Study of Raspberry-Pi/ Beagle board/ Arduino and other microcontroller ( History &
Elevation)
2. Study of different operating systems for Raspberry-Pi /Beagle board/Arduino.
Understanding the process of OS installation
3. Study of different GATES (AND, OR, XOR), Sensors and basic binary operations.

4. Study of Connectivity and configuration of Raspberry-Pi /Beagle board/Arduino


circuit with basic peripherals like LEDS. Understanding GPIO and its use in the
program.
Group B
5. Write a program using Arduino to control LED (One or more ON/OFF). Or Blinking.

6. Create a program that illuminates the green LED if the counter is less than 100,
illuminates the yellow LED if the counter is between 101 and 200 and illuminates the
red LED if the counter is greater than 200
7. Create a program so that when the user enters ‘b’ the green light blinks, ‘g’ the green
light is illuminated ‘y’ the yellow light is illuminated and ‘r’ the red light is
illuminated
8. Write a program that asks the user for a number and outputs the number squared that
is entered.
9. Write a program to control the color of the LED by turning 3 different
potentiometers. One will be read for the value of Red, one for the value of Green, and
one for the value of Blue.
10. Write a program read the temperature sensor and send the values to the serial monitor
on the computer.
11. Write a program so it displays the temperature in Fahrenheit as well as the maximum
and minimum temperatures it has seen.
12. Write a program to show the temperature and shows a graph of the recent
measurements.
13. Understanding the connectivity of Raspberry-Pi /Beagle board circuit / Arduino with
IR sensor. Write an application to detect obstacle and notify user using LEDs.
Group C
14. Write an application to control the operation of hardware simulated traffic signals.
(Mini project)
15. Write an application for stopwatch or countdown timer. (Mini project)

P:F-LTL-UG / 03 /R0 2
GROUP A

P:F-LTL-UG / 03 /R0 3
Assignment No. 1
Aim Study of Raspberry-Pi/ Beagle board/ Arduino and other microcontrollers.
Objective To understand the history, evolution, and applications of various
microcontrollers, specifically Raspberry Pi, Beagle Board, and Arduino.
Outcome 1.Students will gain a comprehensive understanding of the history and
evolution of Raspberry Pi, Beagle Board, and Arduino.
2.Students will be able to compare and contrast the features and applications
of these microcontrollers.
3.Students will develop presentation skills and the ability to communicate
technical information effectively.
Materials Needed 1.Raspberry Pi (any model) OR Beagle Board (any model) OR Arduino (e.g.,
Arduino Uno)
2.Documentation and datasheets for each microcontroller
3.Internet access for research
4.Presentation software (e.g., PowerPoint, Google Slides)
Procedure Research and Gather Information:
• Raspberry Pi:
 Investigate the history of Raspberry Pi, including its inception in 2012
by the Raspberry Pi Foundation.
 Explore its evolution through various models (e.g., Raspberry Pi 1, 2,
3, 4).
 Identify key features such as GPIO pins, USB ports, HDMI output,
and its use in education and projects.
• Beagle Board:
 Research the Beagle Board's introduction in 2008 and its purpose as
an open-source hardware platform.
 Examine different versions (e.g., BeagleBone, BeagleBoard-xM) and
their specifications.
 Discuss its applications in robotics, IoT, and embedded systems.
• Arduino:
 Study the Arduino platform's launch in 2005 and its role in making
electronics accessible to beginners.
 Review various Arduino boards (e.g., Arduino Uno, Mega, Nano) and
their features.
 Highlight its use in DIY projects, prototyping, and education.

Create a Comparative Analysis:


Develop a table comparing the key specifications of Raspberry Pi, Beagle
Board, and Arduino, including:
• Processor type and speed
• RAM size
• Input/Output options (GPIO, USB, etc.)
• Operating system support Typical applications

P:F-LTL-UG / 03 /R0 4
Applications in IoT:
• Raspberry Pi: Used for home automation, media centers, and as a web
server.
• Beagle Board: Employed in robotics, industrial automation, and sensor
networks.
• Arduino:Commonly used in sensor-based projects,
wearable technology, and simple automation tasks.

Prepare a Presentation:
• Compile the research findings into a presentation format.
• Include visuals such as images of each microcontroller, diagrams of their
architecture, and examples of projects.
• Prepare to present the findings to the class, highlighting the unique
features and applications of each microcontroller.
Documentation • Prepare a report summarizing the research findings, comparative
analysis, and applications discussed.
• Include references to all sources used for research, such as websites,
articles, and datasheets.

Documentation Here is a list of documentation and datasheets for each of the


and Datasheets microcontrollers: Raspberry Pi, Beagle Board, and Arduino. These resources
for provide detailed specifications, features, and usage guidelines.
Microcontrollers
1. Raspberry Pi
• Official Raspberry Pi Documentation:
https://www.raspberrypi.com/documentation/
This site includes guides on getting started, hardware specifications, and
software installation.
• Datasheets
Raspberry Pi Datasheet:
https://www.raspberrypi.com/documentation/computers/raspberrypi.html
• Additional Resources: https://forums.raspberrypi.com/

2. Beagle Board
• Official BeagleBoard Documentation:
https://www.beagleboard.org/projects/documentation
This site provides comprehensive information on various BeagleBoard
models, including setup guides and tutorials.

3. Arduino
• Official Arduino Documentation: https://www.arduino.cc/
• Additional Resources: https://wokwi.com/arduino

P:F-LTL-UG / 03 /R0 5
Conclusion In this experiment, I explored the fundamental aspects of three prominent
microcontroller platforms: Raspberry Pi, Beagle Board, and Arduino.
Through comprehensive research and analysis, I gained insights into their
historical development, technical specifications, and diverse applications in
the field of Internet of Things (IoT) and embedded systems.

Key takeaways from the experiment include:

• Raspberry Pi:

• Beagle Board:

• Arduino:

P:F-LTL-UG / 03 /R0 6
Assignment No. 2
Aim Study of different operating systems for Raspberry-Pi /Beagle-board /
Arduino. Understanding the process of OS installation
Objective • To explore various operating systems compatible with Raspberry Pi,
Beagle Board, and Arduino.
• To understand the installation process of different operating systems
on these platforms.
• To learn about the features and functionalities of each operating
system.
• To gain hands-on experience in setting up and configuring an
operating system on a microcontroller or single-board computer.
Outcome Upon completion of this lab, students will be able to:
• Identify and differentiate between various operating systems suitable
for Raspberry Pi, Beagle Board, and Arduino.
• Successfully install an operating system on a Raspberry Pi or Beagle
Board.
• Understand the basic configuration and setup of the installed
operating system.
• Access and utilize the features of the operating system for
development purposes.
Materials Needed • Raspberry Pi (any model, e.g., Raspberry Pi 4)
• Beagle Board (e.g., BeagleBone Black)
• Arduino board (e.g., Arduino Uno, Arduino Nano)
• MicroSD card (at least 8GB for Raspberry Pi and Beagle Board)
• USB power supply for Raspberry Pi/Beagle Board
• USB cable for Arduino
• Computer with internet access
• HDMI cable (for Raspberry Pi/Beagle Board)
• Monitor or display
• Keyboard and mouse (for Raspberry Pi/Beagle Board)
Procedure 1. Research Operating Systems
 Raspberry Pi: Explore Raspbian (now Raspberry Pi OS), Ubuntu
Mate, and other distributions.
 Beagle Board: Investigate Debian, Ubuntu, and Angstrom.
 Arduino: Understand that Arduino typically runs a simple firmware
rather than a full OS.
2. Download OS Images
 Visit the official websites to download the latest OS images:
 Raspberry Pi OS: Raspberry Pi Downloads
 Beagle Board: BeagleBoard Downloads
 Arduino: No OS installation is required, but download the
Arduino IDE from Arduino Software.
3. Prepare the MicroSD Card

P:F-LTL-UG / 03 /R0 7
 Insert the MicroSD card into your computer.
 Use Etcher or Win32 Disk Imager to flash the downloaded OS image
onto the MicroSD card:
 Open the flashing software.
 Select the OS image file.
 Choose the MicroSD card as the target.
 Click "Flash" to start the process.
4. Install the Operating System
 For Raspberry Pi:
 Insert the flashed MicroSD card into the Raspberry Pi.
 Connect the monitor, keyboard, and mouse.
 Power on the Raspberry Pi.
 Follow the on-screen instructions to complete the setup (e.g.,
setting up Wi-Fi, updating software).
 For Beagle Board:
 Insert the flashed MicroSD card into the Beagle Board.
 Connect the monitor, keyboard, and mouse.
 Power on the Beagle Board.
 Follow the on-screen instructions to complete the setup.
5. Explore the Operating System
 Familiarize yourself with the desktop environment, terminal
commands, and package management.
 For Raspberry Pi, explore the Raspberry Pi Configuration tool.
 For Beagle Board, explore the Debian or Ubuntu desktop
environment.
6. Document the Process
 Take notes on the installation steps, any challenges faced, and how
they were resolved.

Documentation Create a report that includes:


 Overview of the operating systems studied.
 Installation steps for Raspberry Pi and Beagle Board.
 Screenshots of the installation process and the desktop environment.
 Any additional configurations made after installation.

Documentation Include datasheets for the Raspberry Pi, Beagle Board, and Arduino in your
and Datasheets report. These can typically be found on the official websites:
for  Raspberry Pi Datasheet: Raspberry Pi Documentation
Microcontrollers  Beagle Board Datasheet: BeagleBoard Documentation
 Arduino Datasheet: Arduino Documentation

P:F-LTL-UG / 03 /R0 8
Conclusion In this lab, we gained valuable insights into the various operating systems
available for Raspberry Pi, Beagle Board, and Arduino. We learned the
installation processes, explored the features of each operating system, and
developed practical skills in configuring and utilizing these platforms for
their projects. The hands-on experience provided a deeper understanding
of how different operating systems can enhance the functionality of
microcontrollers and single-board computers, paving the way for future
exploration in the field of embedded systems and IoT applications.

P:F-LTL-UG / 03 /R0 9
Assignment No. 3
Aim Study of different GATES (AND, OR, XOR), Sensors and basic binary
operations
Objective  To understand the functionality and applications of basic logic gates
(AND, OR) and derived gates (XOR, XNOR).
 To explore universal gates (NAND, NOR) and their significance in
digital circuits.
 To learn about various sensors and their applications in conjunction
with logic gates.
 To perform basic binary operations using logic gates.

Outcome Upon completion of this lab, students will be able to:


 Identify and explain the function of different logic gates.
 Construct simple circuits using various logic gates.
 Understand how sensors can be integrated with logic gates for
practical applications.
 Perform basic binary operations using logic gates.

Materials Needed  Hardware:


 Breadboard
 Logic gate ICs (e.g., 7408 for AND, 7432 for OR, 7486 for
XOR, 74266 for XNOR, 7400 for NAND, 7402 for NOR)
 LEDs (for output indication)
 Resistors (220Ω for LEDs)
 Push buttons (for input)
 Power supply (5V)
 Multimeter (for testing)
 Various sensors (e.g., temperature sensor, ultrasonic sensor,
etc.)
 Software:
 Logic simulator software (optional, e.g., Logisim, Tinkercad
Circuits)
 Arduino IDE (for programming sensors)

P:F-LTL-UG / 03 /R0 10
Description 1. Logic Gates
Logic gates are fundamental building blocks of digital circuits. They are used
to perform logical operations based on one or more binary inputs, producing
a single output.
1.1 AND Gate
• Symbol: .
• Truth Table:

A B Output

0 0 0

0 1 0

1 0 0

1 1 1

• IC Numbers: 7408 (Quad 2-input AND gate)

1.2 OR Gate
• Symbol: +
• Truth Table:

A B Output

0 0 0

0 1 1

1 0 1

P:F-LTL-UG / 03 /R0 11
1 1 1

• IC Numbers: 7432 (Quad 2-input OR gate)

1.3 XOR Gate (Exclusive OR)


• Symbol: ⊕\oplus
• Truth Table:

A B Output

0 0 0

0 1 1

1 0 1

1 1 0

• IC Numbers: 7486 (Quad 2-input XOR gate)


1.4 NAND Gate
• Symbol: A⋅B‾\overline{A \cdot B}
• Truth Table:

A B Output

0 0 1

0 1 1

1 0 1

1 1 0

• IC Numbers: 7400 (Quad 2-input NAND gate)


1.5 NOR Gate
• Symbol: A+B‾\overline{A + B}

P:F-LTL-UG / 03 /R0 12
• Truth Table:

A B Output

0 0 1

0 1 0

1 0 0

1 1 0

• IC Numbers: 7402 (Quad 2-input NOR gate)


1.6 NOT Gate
• Symbol: A‾\overline{A}
• Truth Table:

A Output

0 1

1 0

• IC Numbers: 7404 (Hex inverter)

1.7 EXOR Gate


• Symbol: A⊕BA \oplus B
• Truth Table:

P:F-LTL-UG / 03 /R0 13
A B Output

0 0 0

0 1 1

1 0 1

1 1 0

• IC Numbers: 7486 (Quad 2-input XOR gate)

2. Sensors

P:F-LTL-UG / 03 /R0 14
Sensors are devices that detect and measure physical phenomena and convert
them into a readable electrical signal. Below are the sensors included in the

report:
2.1 Temperature Sensor
• Example: LM35
• Working Principle: LM35 is an analog temperature sensor that
provides an output voltage linearly proportional to the centigrade
temperature.

P:F-LTL-UG / 03 /R0 15
• Applications: Temperature control systems, weather stations, HVAC
systems.

2.3 IR Sensor (Infrared Sensor)


• Example: IR Transmitter and Receiver pair
• Working Principle: Infrared sensors operate based on the emission
and detection of infrared light. They are typically used for proximity
detection or object sensing.
• Applications: Remote control devices, obstacle detection in robots.

2.4 Piezoelectric Sensor


• Example: Piezoelectric crystals
• Working Principle: Piezoelectric sensors generate a voltage when
subjected to mechanical stress or vibrations. The mechanical energy is
converted into electrical energy.
• Applications: Vibration sensing, pressure sensors, sound detection.

2.2 Motion Sensor


• Example: PIR Sensor (Passive Infrared)
• Working Principle: PIR sensors detect the infrared radiation emitted
by moving objects, especially humans or animals. The sensor works
by detecting changes in infrared radiation levels caused by motion.
• Applications: Security systems, automatic lighting systems.

P:F-LTL-UG / 03 /R0 16
3. Basic Binary Operations
Binary arithmetic operations are fundamental to digital systems, and they
form the basis for all complex digital computations. The basic operations
include:
3.1 Binary Addition
• Example:
• 1+1=101 + 1 = 10 (carry over)
• 1+0=11 + 0 = 1
• 0+0=00 + 0 = 0
3.2 Binary Subtraction
• Example:
• 1−1=01 - 1 = 0
• 1−0=11 - 0 = 1
• 0−1=10 - 1 = 1 (borrow)
3.3 Binary Multiplication
• Example:
• 1×1=11 \times 1 = 1
• 1×0=01 \times 0 = 0
• 0×0=00 \times 0 = 0
3.4 Binary Division
• Example:
• 10÷2=510 \div 2 = 5 (binary calculation)
These operations are implemented in digital circuits using combinations of

P:F-LTL-UG / 03 /R0 17
AND, OR, XOR, and NOT gates.

Documentation

Documentation
and Datasheets
for
Microcontrollers

Conclusion

P:F-LTL-UG / 03 /R0 18
Assignment No. 4
Aim Study of Connectivity and configuration of Raspberry-Pi /Beagle
board/Arduino circuit with basic peripherals like LEDS. Understanding
GPIO and its use in the program.
Objective

Outcome

Materials Needed

Procedure

Documentation

Documentation
and Datasheets
for
Microcontrollers

Conclusion

P:F-LTL-UG / 03 /R0 19
GROUP B

P:F-LTL-UG / 03 /R0 20
Assignment No. 5
Aim Write a program using Arduino to control LED (One or more ON/OFF). Or
Blinking
Objective  To understand the basic principles of controlling LEDs using
Arduino.
 To learn how to write and upload code to an Arduino board.
 To gain hands-on experience with circuit design and implementation.
Outcome Upon completion of this assignment, students will be able to:
 Control LEDs using Arduino.
 Write and upload Arduino code to perform specific tasks (ON/OFF or
blinking).
 Understand the basic components of an electronic circuit involving
LEDs.
Software Arduino IDE (Integrated Development Environment)
Requirements
Hardware  Arduino board (e.g., Arduino Uno)
Requirements  One or more LEDs (e.g., Red, Green, Blue)
 Resistors (220Ω or 330Ω for each LED)
 Breadboard
 Jumper wires
 Power supply (if not using USB)
Procedure 1. Connect the longer leg (anode) of each LED to one end of a resistor.
2. Connect the other end of the resistor to a digital pin on the Arduino
(e.g., Pin 9 for LED1, Pin 10 for LED2).
3. Connect the shorter leg (cathode) of each LED to the ground (GND)
pin on the Arduino.
4. Ensure that the Arduino is powered either through USB or an
external power supply.
Code // Define pin numbers for the LEDs
const int led1 = 9; // LED 1 connected to digital pin 9
const int led2 = 10; // LED 2 connected to digital pin 10

void setup() {
// Initialize the digital pins as outputs
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}

void loop() {
// Turn LED 1 ON and LED 2 OFF
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);

P:F-LTL-UG / 03 /R0 21
delay(1000); // Wait for 1 second

// Turn LED 1 OFF and LED 2 ON


digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
delay(1000); // Wait for 1 second
}
Simulation
Output

Conclusion In this assignment, we successfully controlled one or more LEDs using an


Arduino board. We learned how to set up a simple circuit, write the
necessary code, and observe the output. This exercise provided a
foundational understanding of how microcontrollers can interact with
electronic components, paving the way for more complex projects in the
future.

P:F-LTL-UG / 03 /R0 22
Assignment No. 6
Aim Create a program that illuminates the green LED if the counter is less than 100,
illuminates the yellow LED if the counter is between 101 and 200 and
illuminates the red LED if the counter is greater than 200
Objective  To understand the basic principles of controlling LEDs using
Arduino.
 To learn how to write and upload code to an Arduino board.
 To gain hands-on experience with circuit design and implementation.
Outcome Upon completion of this assignment, students will be able to:
 Control LEDs using Arduino.
 Write and upload Arduino code to perform specific tasks (ON/OFF or
blinking).
 Understand the basic components of an electronic circuit involving
LEDs.
Software Arduino IDE (Integrated Development Environment)
Requirements
Hardware  Arduino board (e.g., Arduino Uno)
Requirements  3 LEDs (Green, Yellow, Red)
 3 Resistors (220Ω or 330Ω for each LED)
 Breadboard
 Jumper wires
Procedure 1. Green LED:
1.1 Connect the anode (longer leg) of the Green LED to digital pin 9
through a resistor (220Ω or 330Ω).
1.2 Connect the cathode (shorter leg) of the Green LED directly to
the ground (GND) pin on the Arduino.
2. Yellow LED:
2.1 Connect the anode of the Yellow LED to digital pin 10 through a
resistor.
2.2 Connect the cathode of the Yellow LED directly to the ground.
3. Red LED:
3.1 Connect the anode of the Red LED to digital pin 11 through a
resistor.
3.2 Connect the cathode of the Red LED directly to the ground.
Code // Define pin numbers for the LEDs
const int greenLED = 11; // Green LED connected to digital pin 11
const int yellowLED = 9; // Yellow LED connected to digital pin 9
const int redLED = 6; // Red LED connected to digital pin 6

// Counter variable
int counter = 0;

P:F-LTL-UG / 03 /R0 23
void setup() {
// Initialize the digital pins as outputs
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
// Start the Serial communication
Serial.begin(9600); // Set the baud rate to 9600
}

void loop() {
// Increment the counter
counter++;

// Print the counter value to the Serial Monitor


Serial.print("Counter: ");
Serial.println(counter);

// Check the value of the counter and illuminate the appropriate LED
if (counter < 100) {
digitalWrite(greenLED, HIGH); // Turn on Green LED
digitalWrite(yellowLED, LOW); // Turn off Yellow LED
digitalWrite(redLED, LOW); // Turn off Red LED
}
else if (counter >= 100 && counter <= 200) {
digitalWrite(greenLED, LOW); // Turn off Green LED
digitalWrite(yellowLED, HIGH); // Turn on Yellow LED
digitalWrite(redLED, LOW); // Turn off Red LED
}
else if (counter >200 && counter <=300) {
digitalWrite(greenLED, LOW); // Turn off Green LED
digitalWrite(yellowLED, LOW); // Turn off Yellow LED
digitalWrite(redLED, HIGH); // Turn on Red LED
}
else {
counter = 0; // Resetting counter variable
}

// Add a delay to slow down the counter increment


delay(10); // Adjust the delay as needed
}

P:F-LTL-UG / 03 /R0 24
Simulation
Output

Conclusion This program effectively demonstrates how to control multiple LEDs


based on the value of a counter.

P:F-LTL-UG / 03 /R0 25
Assignment No. 7
Aim Create a program so that when the user enters ‘b’ the green light blinks, ‘g’ the
green light is illuminated ‘y’ the yellow light is illuminated and ‘r’ the red light
is illuminated
Objective  To understand the basic principles of controlling LEDs using
Arduino.
 To learn how to write and upload code to an Arduino board.
 To gain hands-on experience with circuit design and implementation.
Outcome Upon completion of this assignment, students will be able to:
 Control LEDs using Arduino.
 Write and upload Arduino code to perform specific tasks
 Understand the basic components of an electronic circuit involving
LEDs.

Software Arduino IDE (Integrated Development Environment)


Requirements
Hardware  Arduino board (e.g., Arduino Uno)
Requirements  3 LEDs (Green, Yellow, Red)
 3 Resistors (220Ω or 330Ω for each LED)
 Breadboard
 Jumper wires
Procedure 1. Green LED:
1.2 Connect the anode (longer leg) of the Green LED to digital pin 11
through a resistor (220Ω or 330Ω).
1.3 Connect the cathode (shorter leg) of the Green LED directly to the
ground (GND) pin on the Arduino.
2. Yellow LED:
2.1 Connect the anode of the Yellow LED to digital pin 9 through a
resistor.
2.2 Connect the cathode of the Yellow LED directly to the ground.
3. Red LED:
3.1 Connect the anode of the Red LED to digital pin 6 through a resistor.
3.2 Connect the cathode of the Red LED directly to the ground.
Code // Define pin numbers for the LEDs
const int greenLED = 11; // Green LED connected to digital pin 11
const int yellowLED = 9; // Yellow LED connected to digital pin 9
const int redLED = 6; // Red LED connected to digital pin 6

// Counter variable
int counter = 0;

void setup() {

P:F-LTL-UG / 03 /R0 26
// Initialize the digital pins as outputs
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(redLED, OUTPUT);
// Start the Serial communication
Serial.begin(9600); // Set the baud rate to 9600
Serial.println("Enter 'b' to blink green LED, 'g' for green, 'y' for yellow, 'r'
for red.");
}

void loop() {
// Check if data is available to read
if (Serial.available() > 0) {
char input = Serial.read(); // Read the input character

// Control LEDs based on user input


switch (input) {
case 'b': // Blink green LED
for (int i = 0; i < 5; i++) { // Blink 5 times
digitalWrite(greenLED, HIGH); // Turn on Green LED
delay(500); // Wait for 500 milliseconds
digitalWrite(greenLED, LOW); // Turn off Green LED
delay(500); // Wait for 500 milliseconds
}
break;

case 'g': // Illuminate green LED


digitalWrite(greenLED, HIGH); // Turn on Green LED
digitalWrite(yellowLED, LOW); // Turn off Yellow LED
digitalWrite(redLED, LOW); // Turn off Red LED
break;

case 'y': // Illuminate yellow LED


digitalWrite(greenLED, LOW); // Turn off Green LED
digitalWrite(yellowLED, HIGH); // Turn on Yellow LED
digitalWrite(redLED, LOW); // Turn off Red LED
break;

case 'r': // Illuminate red LED


digitalWrite(greenLED, LOW); // Turn off Green LED
digitalWrite(yellowLED, LOW); // Turn off Yellow LED
digitalWrite(redLED, HIGH); // Turn on Red LED
break;

default:

P:F-LTL-UG / 03 /R0 27
// Turn off all LEDs if an invalid character is entered
digitalWrite(greenLED, LOW);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
break;
}
}
}
Simulation
Output

Conclusion This program effectively demonstrates how to control multiple LEDs


based on the user input.

P:F-LTL-UG / 03 /R0 28
Assignment No. 8
Aim Write a program that asks the user for a number and outputs the number squared
that is entered.
Objective  To understand how to interface an Arduino with a serial monitor.
 To learn how to read user input from the serial port.
 To perform basic arithmetic operations using Arduino.
 To display the output back to the user through the serial monitor.
Outcome Upon completion of this assignment, students will be able to:
 Write and upload a program to an Arduino board.
 Use the serial monitor for input and output operations.
 Understand basic programming concepts such as variables, data
types, and arithmetic operations.

Software Arduino IDE (Integrated Development Environment)


Requirements
Hardware  Arduino board (e.g., Arduino Uno)
Requirements
Procedure 1. Setup the Arduino Environment:
1.1. Install the Arduino IDE on your computer if it is not already
installed.
1.2. Connect the Arduino board to your computer using the USB cable.
2. Open the Arduino IDE:
3. Launch the Arduino IDE on your computer.
4. In the Arduino IDE, create a new sketch (File > New).
5. Write the code provided in the "Code" section below.
6. Upload the Program:
6.1. Select the correct board and port from the Tools menu.
6.2. Click on the upload button (right arrow icon) to upload the program
to the Arduino.
7. Open the Serial Monitor:
7.1. After uploading, open the Serial Monitor (Tools > Serial Monitor) to
interact with the program.
7.2. Set the baud rate to 9600 bps.
8. Test the Program:
8.1. Enter a number in the input field of the Serial Monitor and press
"Enter."
8.2. Observe the output displayed in the Serial Monitor, which will show
the squared value of the entered number.
Code void setup() {
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
Serial.println("Enter a number:");
}

void loop() {
P:F-LTL-UG / 03 /R0 29
// Check if data is available to read
if (Serial.available() > 0) {
// Read the input from the serial monitor
String input = Serial.readStringUntil('\n');

// Convert the input to an integer


int number = input.toInt();

// Calculate the square of the number


int squared = number * number;

// Output the result to the serial monitor


Serial.print("The square of ");
Serial.print(number);
Serial.print(" is ");
Serial.println(squared);

// Prompt the user for another number


Serial.println("Enter another number:");
}
}
Simulation
Output

Conclusion In this lab, we successfully created a simple Arduino program that interacts
with the user through the serial monitor. By entering a number, the user can
see the squared value of that number displayed back to them. This exercise
not only reinforces basic programming concepts but also demonstrates how
to use Arduino for simple input and output operations, laying the
groundwork for more complex Internet of Things applications.

P:F-LTL-UG / 03 /R0 30
Assignment 9
No.
Aim Write a program to control the color of the LED by turning 3 different potentiometers.
One will be read for the value of Red, one for the value of Green, and one for the
value of Blue
Objective  To understand how to interface potentiometers with an Arduino.
 To learn how to control an RGB LED using PWM (Pulse Width
Modulation).
 To explore the concept of analog input and output in Arduino.
 To develop skills in reading analog values and mapping them to PWM
signals.
Outcome Upon completion of this assignment, students will be able to:
 Interface multiple potentiometers with an Arduino.
 Control the brightness of an RGB LED using PWM signals.
 Understand how to read and process analog input values.

Software Arduino IDE (Integrated Development Environment)


Requirements
Hardware  Arduino board (e.g., Arduino Uno, Arduino Nano)
Requirements  Common cathode RGB LED
 3 Potentiometers (10kΩ recommended)
 3 Resistors (220Ω for each color channel of the RGB LED)
 Breadboard and jumper wires
 USB cable to connect the Arduino to the computer
Procedure 1. Setup the Arduino Environment:
1.1. Install the Arduino IDE on your computer if it is not already installed.
1.2. Connect the Arduino board to your computer using the USB cable.
2. Wiring the Circuit:
2.1. Connect the RGB LED to the Arduino:
2.1.1. The longest leg (cathode) of the RGB LED goes to GND.
2.1.2. Connect the Red leg to a PWM-capable pin (e.g., pin 9) through a
220Ω resistor.
2.1.3. Connect the Green leg to another PWM-capable pin (e.g., pin 10)
through a 220Ω resistor.
2.1.4. Connect the Blue leg to another PWM-capable pin (e.g., pin 11)
through a 220Ω resistor.
2.2. Connect the potentiometers:
2.2.1. Connect one terminal of each potentiometer to 5V.
2.2.2. Connect the other terminal of each potentiometer to GND.
2.2.3. Connect the middle terminal (wiper) of the first potentiometer to an
analog pin (e.g., A0 for Red), the second to A1 (for Green), and the
third to A2 (for Blue).
3. Launch the Arduino IDE on your computer.
4. In the Arduino IDE, create a new sketch (File > New).
5. Write the code provided in the "Code" section below.
P:F-LTL-UG / 03 /R0 31
6. Select the correct board and port from the Tools menu.
7. Click on the upload button (right arrow icon) to upload the program to the
Arduino.
8. Test the Program: After uploading, turn the potentiometers and observe the
RGB LED change colors based on the potentiometer values.
Code // Define the pins for the RGB LED
const int redPin = 9; // PWM pin for Red
const int greenPin = 10; // PWM pin for Green
const int bluePin = 11; // PWM pin for Blue

// Define the pins for the potentiometers


const int potRedPin = A0; // Potentiometer for Red
const int potGreenPin = A1; // Potentiometer for Green
const int potBluePin = A2; // Potentiometer for Blue

void setup() {
// Set the RGB LED pins as output
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
// Read the values from the potentiometers
int redValue = analogRead(potRedPin);
int greenValue = analogRead(potGreenPin);
int blueValue = analogRead(potBluePin);

// Map the potentiometer values (0-1023) to PWM values (0-255)


redValue = map(redValue, 0, 1023, 0, 255);
greenValue = map(greenValue, 0, 1023, 0, 255);
blueValue = map(blueValue, 0, 1023, 0, 255);

// Set the color of the RGB LED


analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);

// Small delay for stability


delay(10);
}

P:F-LTL-UG / 03 /R0 32
Simulation
Output

Conclusion In this lab, we successfully created a program that allows them to control the color
of an RGB LED using three potentiometers. By adjusting the potentiometers, we
can manipulate the intensity of each color channel (Red, Green, and Blue),
resulting in a wide range of colors being displayed by the RGB LED. This exercise
enhances understanding of analog input and output, as well as the practical
application of PWM in controlling LED brightness, which is fundamental in
various Internet of Things projects.

P:F-LTL-UG / 03 /R0 33
Assignment No. 10
Aim Write a program read the temperature sensor and send the values to the serial
monitor on the computer.
Objective  To understand how to interface a temperature sensor with an
Arduino.
 To learn how to read analog values from a temperature sensor.
 To display the temperature readings on the serial monitor.
 To familiarize with the concept of serial communication in Arduino.
Outcome Upon completion of this assignment, students will be able to:
 Interface a temperature sensor with an Arduino.
 Read and process analog input values from the sensor.
 Display real-time temperature readings on the serial monitor.

Software • Arduino IDE (version 1.8.0 or later)


Requirements • DHT sensor library (can be installed via the Library Manager in the
Arduino IDE)
Hardware  Arduino board (e.g., Arduino Uno, Arduino Nano)
Requirements  Temperature sensor (e.g., LM35, TMP36, or DHT11/DHT22)
 Breadboard and jumper wires
 USB cable to connect the Arduino to the computer
 10kΩ resistor (for pull-up on the DHT11/DHT22 data line)
Procedure 1. Setup the Arduino Environment:
1.1. Install the Arduino IDE on your computer if it is not already
installed.
1.2. Connect the Arduino board to your computer using the USB cable.
2. Wiring the Circuit:
2.1. Connect the temperature sensor to the Arduino:
2.1.1. For an LM35 or TMP36:
2.1.1.1. Connect the VCC pin of the sensor to the 5V pin on
the Arduino.
2.1.1.2. Connect the GND pin of the sensor to the GND pin on
the Arduino.
2.1.1.3. Connect the output pin of the sensor to an analog pin
on the Arduino (e.g., A0).
2.1.2. For a DHT11/DHT22:
2.1.2.1. Connect the VCC pin of the DHT11/DHT22 to the 5V
pin on the Arduino.
2.1.2.2. Connect the GND pin of the DHT11/DHT22 to the
GND pin on the Arduino.
2.1.2.3. Connect the data pin of the DHT11/DHT22 to a
digital pin on the Arduino (e.g., pin 2).
2.1.2.4. Place a 10kΩ resistor between the VCC and data pin
(pull-up resistor).
3. Launch the Arduino IDE on your computer.
4. In the Arduino IDE, create a new sketch (File > New).
5. Write the code provided in the "Code" section below.
P:F-LTL-UG / 03 /R0 34
6. If using DHT11/DHT22, install DHT sensor library.
7. Select the correct board and port from the Tools menu.
8. Click on the upload button (right arrow icon) to upload the program to
the Arduino.
9. Open the Serial Monitor (Tools > Serial Monitor) to view the
temperature readings.
10. Set the baud rate to 9600 bps.
11. Observe the temperature readings displayed in the Serial Monitor.
Code //By using TMP
// Define the pin for the temperature sensor
const int tempPin = A0; // Analog pin connected to the temperature sensor

void setup() {
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
}

void loop() {
// Read the analog value from the temperature sensor
int sensorValue = analogRead(tempPin);

// Convert the analog value to voltage (0-5V)


float voltage = sensorValue * (5.0 / 1023.0);

// Convert voltage to temperature in Celsius (for LM35: 10mV/°C)


float temperatureC = voltage * 100; // For TMP36, use voltage * 100 - 50

// Print the temperature to the serial monitor


Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");

// Wait for a second before the next reading


delay(1000);
}

//By using DHT22


#include <DHT.h>

#define DHTPIN 2 // Pin where the DHT22 is connected


#define DHTTYPE DHT22 // DHT 22

DHT dht(DHTPIN, DHTTYPE);

void setup() {

P:F-LTL-UG / 03 /R0 35
Serial.begin(9600); // Initialize serial communication
dht.begin(); // Initialize the DHT sensor
}

void loop() {
// Wait a few seconds between measurements
delay(2000);

// Read temperature as Celsius


float temperatureC = dht.readTemperature();
// Read humidity
float humidity = dht.readHumidity();

// Check if any reads failed and exit early (to try again).
if (isnan(temperatureC) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Print the temperature and humidity to the serial monitor


Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}

Simulation By using TMP


Output

P:F-LTL-UG / 03 /R0 36
By Using DHT22

P:F-LTL-UG / 03 /R0 37
Conclusion In this lab, we successfully created a program that reads temperature sensor
values and displays them on the serial monitor. By interfacing with either an
LM35, TMP36, or DHT11/DHT22 sensor, we learned how to convert analog
readings into temperature values and communicate these readings via serial
communication. This exercise enhances understanding of sensor integration
and data visualization, which are essential skills in the field of Internet of
Things and embedded systems.

Assignment No. 11
Aim Write a program so it displays the temperature in Fahrenheit as well as the
maximum and minimum temperatures it has seen.
Objective  To understand how to interface a temperature sensor with an
Arduino.
 To learn how to read analog values from a temperature sensor.
 To convert temperature readings from Celsius to Fahrenheit.
 To keep track of the maximum and minimum temperature readings.
 To display the temperature readings along with the maximum and

P:F-LTL-UG / 03 /R0 38
minimum values on the serial monitor.

Outcome Upon completion of this assignment, students will be able to:


 Interface a temperature sensor with an Arduino.
 Read and process analog input values from the sensor.
 Convert temperature readings between Celsius and Fahrenheit.
 Maintain and display maximum and minimum temperature readings
on the serial monitor.
Software • Arduino IDE (version 1.8.0 or later)
Requirements • DHT sensor library (can be installed via the Library Manager in the
Arduino IDE)
Hardware  Arduino board (e.g., Arduino Uno, Arduino Nano)
Requirements  Temperature sensor (e.g., LM35, TMP36, or DHT11/DHT22)
 Breadboard and jumper wires
 USB cable to connect the Arduino to the computer
 10kΩ resistor (for pull-up on the DHT11/DHT22 data line)
Procedure 1. Setup the Arduino Environment:
1.1. Install the Arduino IDE on your computer if it is not already
installed.
1.2. Connect the Arduino board to your computer using the USB cable.
2. Wiring the Circuit:
2.1. Connect the temperature sensor to the Arduino:
2.1.1. For an LM35 or TMP36:
2.1.1.1. Connect the VCC pin of the sensor to the 5V pin on
the Arduino.
2.1.1.2. Connect the GND pin of the sensor to the GND pin on
the Arduino.
2.1.1.3. Connect the output pin of the sensor to an analog pin
on the Arduino (e.g., A0).
2.1.2. For a DHT11/DHT22:
2.1.2.1. Connect the VCC pin of the DHT11/DHT22 to the 5V
pin on the Arduino.
2.1.2.2. Connect the GND pin of the DHT11/DHT22 to the
GND pin on the Arduino.
2.1.2.3. Connect the data pin of the DHT11/DHT22 to a
digital pin on the Arduino (e.g., pin 2).
2.1.2.4. Place a 10kΩ resistor between the VCC and data pin
(pull-up resistor).
3. Launch the Arduino IDE on your computer.
4. In the Arduino IDE, create a new sketch (File > New).
5. Write the code provided in the "Code" section below.
6. If using DHT11/DHT22, install DHT sensor library.
7. Select the correct board and port from the Tools menu.
8. Click on the upload button (right arrow icon) to upload the program to
the Arduino.
9. Open the Serial Monitor (Tools > Serial Monitor) to view the
P:F-LTL-UG / 03 /R0 39
temperature readings.
10. Set the baud rate to 9600 bps.
11. Observe the temperature readings displayed in the Serial Monitor,
including the maximum and minimum temperatures.
Code //By using TMP
// Define the pin for the TMP36 sensor
const int tempPin = A0; // Analog pin connected to the TMP36 sensor

// Variables to store maximum and minimum temperatures


float maxTemperature = -999; // Initialize to a very low value
float minTemperature = 999; // Initialize to a very high value

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

void loop() {
// Read the analog value from the TMP36 sensor
int sensorValue = analogRead(tempPin);

// Convert the analog value to voltage (0-5V)


float voltage = sensorValue * (5.0 / 1023.0);

// Convert voltage to temperature in Celsius (TMP36: 10mV/°C)


float temperatureC = voltage * 100;

// Convert Celsius to Fahrenheit


float temperatureF = (temperatureC * 9.0 / 5.0) + 32;

// Update maximum and minimum temperatures


if (temperatureF > maxTemperature) {
maxTemperature = temperatureF;
}
if (temperatureF < minTemperature) {
minTemperature = temperatureF;
}

// Print the temperatures and max/min values to the serial monitor


Serial.print("Current Temperature: ");
Serial.print(temperatureF);
Serial.print(" °F, Max Temperature: ");
Serial.print(maxTemperature);
Serial.print(" °F, Min Temperature: ");
Serial.println(minTemperature);

P:F-LTL-UG / 03 /R0 40
// Wait a few seconds before the next reading
delay(2000);
}

//By using DHT22


#include <DHT.h>

#define DHTPIN 2 // Pin where the DHT22 is connected


#define DHTTYPE DHT22 // DHT 22

DHT dht(DHTPIN, DHTTYPE);

// Variables to store maximum and minimum temperatures


float maxTemperature = -999; // Initialize to a very low value
float minTemperature = 999; // Initialize to a very high value

void setup() {
Serial.begin(9600); // Initialize serial communication
dht.begin(); // Initialize the DHT sensor
}

void loop() {
// Wait a few seconds between measurements
delay(2000);

// Read temperature as Celsius


float temperatureC = dht.readTemperature();
// dht.readTemperature(true); You can pass true for Fahrenheit

// Check if any reads failed and exit early (to try again).
if (isnan(temperatureC)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Convert Celsius to Fahrenheit


float temperatureF = (temperatureC * 9.0 / 5.0) + 32;

// Update maximum and minimum temperatures


if (temperatureF > maxTemperature) {
maxTemperature = temperatureF;
}
if (temperatureF < minTemperature) {
minTemperature = temperatureF;

P:F-LTL-UG / 03 /R0 41
}

// Print the temperatures and max/min values to the serial monitor


Serial.print("Current Temperature: ");
Serial.print(temperatureF);
Serial.print(" °F, Max Temperature: ");
Serial.print(maxTemperature);
Serial.print(" °F, Min Temperature: ");
Serial.println(minTemperature);

// Print humidity (optional)


float humidity = dht.readHumidity();
if (!isnan(humidity)) {
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
}

Simulation By using TMP


Output

P:F-LTL-UG / 03 /R0 42
By Using DHT22

Conclusion In this lab, we successfully created a program that reads temperature values
in Fahrenheit from both TMP36 (or TMP37) or DHT22 sensors, while also
tracking the maximum and minimum temperatures recorded. This exercise
enhances understanding of sensor integration, data conversion, and real-time
data monitoring, which are essential skills in the field of Internet of Things
and embedded systems.

P:F-LTL-UG / 03 /R0 43
Assignment No. 12
Aim Write a program to show the temperature and shows a graph of the recent
measurements.
Objective  To read temperature and humidity values from a DHT22 sensor.
 To visualize the temperature readings in real-time using the Serial
Plotter in the Arduino IDE.
Outcome Upon completion of this assignment, students will be able to:
 Interface a DHT22 sensor with an Arduino.
 Read and process digital input values from the sensor.
 Use the Serial Plotter to visualize temperature data.

Software • Arduino IDE (version 1.8.0 or later)


Requirements • DHT sensor library (can be installed via the Library Manager in the
Arduino IDE)
Hardware  Arduino board (e.g., Arduino Uno, Arduino Nano)
Requirements  DHT22 temperature and humidity sensor
 Breadboard and jumper wires
 USB cable to connect the Arduino to the computer
 10kΩ resistor (for pull-up on the DHT22 data line)
Procedure 1. Setup the Arduino Environment:
1.1. Install the Arduino IDE on your computer if it is not already installed.
1.2. Connect the Arduino board to your computer using the USB cable.
2. Wiring the Circuit:
2.1. Connect the DHT22 sensor to the Arduino:
2.1.1. Connect the VCC pin of the DHT22 to the 5V pin on the
Arduino.
2.1.2. Connect the GND pin of the DHT22 to the GND pin on the
Arduino.
2.1.3. Connect the data pin of the DHT22 to a digital pin on the
Arduino (e.g., pin 2).
2.1.4. Place a 10kΩ resistor between the VCC and data pin (pull-up
resistor).
3. Launch the Arduino IDE on your computer.
4. Install the DHT Library:
4.1. Go to Sketch > Include Library > Manage Libraries.
4.2. In the Library Manager, search for "DHT sensor library" by Adafruit
and install it.
5. In the Arduino IDE, create a new sketch (File > New).
6. Write the code provided in the "Code" section below.
7. Select the correct board and port from the Tools menu.
8. Click on the upload button (right arrow icon) to upload the program to the
Arduino.
9. Open the Serial Plotter (Tools > Serial Plotter) to visualize the
temperature readings.
10. Observe the temperature readings displayed in the Serial Plotter as a
graph.
P:F-LTL-UG / 03 /R0 44
Code #include <DHT.h>

#define DHTPIN 2 // Pin where the DHT22 is connected


#define DHTTYPE DHT22 // DHT 22

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600); // Initialize serial communication
dht.begin(); // Initialize the DHT sensor
}

void loop() {
// Wait a few seconds between measurements
delay(2000);

// Read temperature as Celsius


float temperatureC = dht.readTemperature();

// Check if any reads failed and exit early (to try again).
if (isnan(temperatureC)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

// Convert Celsius to Fahrenheit


float temperatureF = (temperatureC * 9.0 / 5.0) + 32;

// Print the temperature to the serial monitor and serial plotter


Serial.print("Temperature: ");
Serial.print(temperatureF);
Serial.println(" °F");

// Print the temperature for the Serial Plotter


Serial.print("TemperatureF: ");
Serial.println(temperatureF);
}

P:F-LTL-UG / 03 /R0 45
Simulation
Output

P:F-LTL-UG / 03 /R0 46
Output

Conclusion In this lab, we successfully interfaced a DHT22 temperature and humidity


sensor with an Arduino to read and display temperature measurements. By
utilizing the Serial Plotter feature in the Arduino IDE, we were able to
visualize real-time temperature data in a graphical format, enhancing their
understanding of data monitoring and visualization techniques.

P:F-LTL-UG / 03 /R0 47
Assignment No. 13
Aim Understanding the connectivity of Raspberry-Pi /Beagle board circuit / Arduino
with IR sensor. Write an application to detect obstacle and notify user using
LEDs.
Objective  To learn how to interface an IR sensor with an Arduino.
 To understand how to read digital signals from the IR sensor.
 To implement a simple obstacle detection application that activates
LEDs based on sensor readings.
 To gain hands-on experience in basic circuit design and programming
with Arduino.
Outcome Upon completion of this assignment, students will be able to:
 Interface an IR sensor with an Arduino.
 Read and process digital input values from the IR sensor.
 Control LEDs based on sensor readings to indicate the presence of
obstacles.
Software • Arduino IDE (version 1.8.0 or later)
Requirements
Hardware  Arduino board (e.g., Arduino Uno, Arduino Nano)
Requirements  IR sensor module (e.g., TSOP38238 or similar)
 2 LEDs (one for obstacle detected, one for no obstacle)
 2 resistors (220Ω for each LED)
 Breadboard and jumper wires
 USB cable to connect the Arduino to the computer
Procedure 1. Setup the Arduino Environment:
1.1. Install the Arduino IDE on your computer if it is not already installed.
1.2. Connect the Arduino board to your computer using the USB cable.
2. Wiring the Circuit:
2.1. Connect the IR sensor to the Arduino:
2.1.1. Connect the VCC pin of the IR sensor to the 5V pin on the
Arduino.
2.1.2. Connect the GND pin of the IR sensor to the GND pin on the
Arduino.
2.1.3. Connect the output pin of the IR sensor to a digital pin on the
Arduino (e.g., pin 7).
2.2. Connect the LEDs:
2.2.1. Connect the anode (long leg) of the first LED (Obstacle
Detected) to a digital pin on the Arduino (e.g., pin 8) through a
220Ω resistor.
2.2.2. Connect the anode of the second LED (No Obstacle) to another
digital pin on the Arduino (e.g., pin 9) through a 220Ω resistor.
2.2.3. Connect the cathodes (short legs) of both LEDs to GND.
3. Launch the Arduino IDE on your computer.
4. In the Arduino IDE, create a new sketch (File > New).
5. Write the code provided in the "Code" section below.

P:F-LTL-UG / 03 /R0 48
6. Select the correct board and port from the Tools menu.
7. Click on the upload button (right arrow icon) to upload the program to the
Arduino.
8. Test the Program:
8.1. After uploading, place an object in front of the IR sensor to test the
obstacle detection.
8.2. Observe the LEDs to see if they light up correctly based on the
presence of an obstacle.
Code // Define pin numbers
const int irSensorPin = 2; // Pin connected to the IR sensor output
const int ledPin1 = 9; // Pin for LED1 (No Obstacle )
const int ledPin2 = 10; // Pin for LED2 (Obstacle detected)

void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);

// Set pin modes


pinMode(irSensorPin, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}

void loop() {
// Read the value from the IR sensor
int sensorValue = digitalRead(irSensorPin);

// Print the sensor value to the Serial Monitor


Serial.println(sensorValue);

// Check if an obstacle is detected


if (sensorValue == HIGH) { // no obstacle detected
digitalWrite(ledPin1, HIGH); // Turn on LED1
digitalWrite(ledPin2, LOW); // Turn off LED2
}
else{
digitalWrite(ledPin1, LOW); // Turn off LED1
digitalWrite(ledPin2, HIGH); // Turn on LED2
}

// Small delay for stability


delay(100);
}

P:F-LTL-UG / 03 /R0 49
Simulation
Output

https://circuitdigest.com/microcontroller-projects/interfacing-ir-sensor-module-with-arduino

Output

P:F-LTL-UG / 03 /R0 50
Conclusion In this lab, we successfully interfaced a DHT22 temperature and humidity
sensor with an Arduino to read and display temperature measurements. By
utilizing the Serial Plotter feature in the Arduino IDE, we were able to
visualize real-time temperature data in a graphical format, enhancing their
understanding of data monitoring and visualization techniques.

P:F-LTL-UG / 03 /R0 51
We used following Simulation web resources
https://wokwi.com/projects/new/arduino-uno
https://www.tinkercad.com/

Special thanks to Miss. Bhumi for output image of Assignment No.12 and 13.

P:F-LTL-UG / 03 /R0 52

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy