0% found this document useful (0 votes)
8 views59 pages

IoT Maual

The document is a lab manual for a BCA III semester course on the Internet of Things (IoT), detailing the practical aspects of IoT projects. It covers key characteristics of IoT, communication protocols, and the role of Arduino in IoT applications, including detailed descriptions of the Arduino Uno and D1 boards. The manual also includes acknowledgments, declarations, and an index, emphasizing the importance of hands-on experience in understanding IoT concepts.

Uploaded by

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

IoT Maual

The document is a lab manual for a BCA III semester course on the Internet of Things (IoT), detailing the practical aspects of IoT projects. It covers key characteristics of IoT, communication protocols, and the role of Arduino in IoT applications, including detailed descriptions of the Arduino Uno and D1 boards. The manual also includes acknowledgments, declarations, and an index, emphasizing the importance of hands-on experience in understanding IoT concepts.

Uploaded by

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

LAB MANUAL

IoT: Internet of
Things
BCA III
Semester

Under the guidance of:

Prepared By

Academic Year

Page 1
Acknowledgment
The creation of this computer practical file has been an enriching learning experience, made
possible by the invaluable guidance and support of my Computer Science teacher. Her clear
explanations, combined with access to essential resources, were crucial to the successful
completion of this project.
I would also like to express my gratitude to my parents for their continuous encouragement
and to my friends for their moral support throughout this journey. Their support, along with
my teacher's dedication, has greatly enhanced my understanding and practical skills in the
field of Computer Science.

Declaration
I hereby declare that the work presented in this Practical File is the result of my own efforts.
The data, codes, and information provided are authentic and have been created or compiled
by me, under the guidance of my Teacher. This work has not been submitted elsewhere for
any other examination or evaluation.
I would like to acknowledge the support and resources provided by my Teacher, which were
instrumental in completing this practical file.

Name:
Class:
Roll No.:
Date:

Student Signature:

Page 2
Index
S. No. Aim Sign

Page 3
Internet of Things (IoT)
The Internet of Things (IoT) refers to a vast network of interconnected devices, commonly
known as "things," that communicate with each other in both domestic and professional
settings. According to Gartner, a leading technology consulting firm, the number of connected
devices was projected to exceed 20 billion by 2020.

Key Characteristics of IoT


1. Communication (M2M): IoT devices communicate with each other (machine-to-
machine, or M2M) or with servers locally or via the internet. This communication
enables the exchange and processing of data between devices.
2. Networking: Through networking capabilities, IoT devices can connect to broader
systems, allowing them to collect, send, and receive data for various purposes.
3. Sensing: IoT devices have sensors that monitor and capture environmental data, such
as temperature, humidity, or motion.
4. Action: Many IoT devices are designed to take specific actions based on data or
commands. They can lock doors, emit signals (such as beeps), control lighting, or
even operate household appliances like televisions.

Communications in IoT
Communications are a fundamental aspect of IoT projects, serving as the backbone of device
interaction and data exchange. The choice of communication protocols significantly impacts
the performance and efficiency of IoT systems.
 Trade-offs in IoT Communications
There is a balance between the complexity of protocols, data rates, and the processing
power required. Higher data rates and complex protocols often demand more
powerful processors and greater energy consumption.
 TCP/IP-based Communications
Protocols such as TCP/IP and HTTP (e.g., RESTful services) offer flexibility and
high functionality, enabling web servers, streaming data, and more. However, this
comes at the cost of higher processor power and increased electrical consumption,
making them suitable for applications requiring robust data handling and connectivity.
 Low-power Protocols
For energy-efficient IoT devices, protocols like Bluetooth and ZigBee are preferred.
These low-power solutions reduce data bandwidth and functionality, but they extend
battery life, making them ideal for devices in smart homes or industrial monitoring
 Flexible Requirements
IoT projects vary widely in their communication needs, from high-bandwidth, high-
functionality devices to low-power, low-data-rate systems, depending on the use case.

Arduino in IoT
In IoT applications, Arduino plays a critical role by acting as a bridge between sensors,
actuators, and the internet. It collects data from various sensors, processes that information,
and then sends it to the cloud or other connected systems. Additionally, it can receive control

Page 4
signals from the internet to operate actuators, which perform actions like moving parts or
switching devices on and off.
Key Functions of Arduino in IoT:
1. Data Collection: Arduino boards gather data from attached sensors, monitoring
environmental parameters like temperature, humidity, or motion.
2. Data Transmission: The collected sensor data is sent to the cloud for further analysis
or storage using platforms like the Arduino IoT Cloud.
3. Actuator Control: Arduino can also receive data from the cloud and use it to control
actuators, enabling real-time responses based on the sensor input, such as opening a
door or adjusting lighting.

Arduino Uno: A Detailed Overview


The Arduino Uno is an open-source microcontroller board developed by Arduino.cc and
built around the ATmega328P microcontroller from Microchip Technology. It is highly
popular due to its simplicity, ease of use, and versatile design, making it ideal for both
beginners and professionals working on embedded systems and prototyping.
Technical Specifications:
 Input/Output (I/O) Pins: The Arduino Uno features 14 digital I/O pins, of which 6 can be
used for PWM (Pulse Width Modulation) output. In addition, it includes 6 analog input
pins, allowing it to interface with a wide range of sensors and peripherals.
 Programming: The board is programmed using the Arduino IDE (Integrated Development
Environment), a user-friendly software that supports various programming languages.
Code can be uploaded through a Type-B USB connection.
 Power Supply: The Arduino Uno can be powered via a USB cable or an external 9V
battery, with supported input voltages ranging from 7V to 20V. This flexibility makes it
suitable for both portable and stationary applications.
Key Features:
 Open-Source: As an open-source platform, Arduino provides users with the freedom to
modify both hardware and software designs.
 Expandable: The board's I/O pins can be connected to shields, or expansion boards
designed to add functionality, such as Wi-Fi, motor control, or display interfaces.
 Versatile Powering Options: It can draw power from either a USB connection or an
external power source for greater flexibility in project design.
The term "Uno," which means "one" in Italian, symbolizes the first version of Arduino
software, marking a foundational milestone in the Arduino product line.

Arduino D1: A Detailed Overview


The Arduino D1 is a development board designed for IoT (Internet of Things) applications
and is based on the ESP8266EX WiFi chip. It is Arduino-compatible, which means you
can

Page 5
program it using the Arduino IDE, making it very user-friendly for developers familiar with
Arduino.
Key Features:
1. WiFi Connectivity: The D1 comes with built-in WiFi, making it ideal for projects that
require internet access or wireless communication, without the need for additional
modules.
2. Input/Output Pins: The board includes 11 digital I/O pins, which support interrupts,
PWM, I2C, and one-wire protocols (except for D0). There is also 1 Analog input for
connecting analog sensors.
3. Compact Design: It is smaller and more compact than typical Arduino boards, making it
easy to integrate into various projects where space is a concern.
4. Power Options: It supports both USB power and external power sources, similar to other
Arduino boards.
5. The Arduino D1 is widely used in IoT projects, home automation, and for integrating
sensors, displays, and other peripherals via WiFi.

Arduino Components:

1. Analog Reference Pin - Used to set an external reference voltage for the analog inputs.
2. Serial Data Acquisition (SDA) - This pin is for I2C communication, used to connect
sensors and other devices.
3. Serial Clock (SCL) - Another pin used for I2C communication, providing the clock
signal. The Serial Clock (SCL) pin is a crucial component of the I2C (Inter-Integrated
Circuit) communication protocol, which allows multiple devices to communicate with
each other using only two wires: SDA (Serial Data Line) and SCL.
Function of SCL:
Page 6
 Clock Signal: SCL generates a clock signal that synchronizes the data transfer
between the master and slave devices on the I2C bus. This ensures that data is sent
and received at the correct intervals, maintaining data integrity.
How it Works:
A. Master and Slave: In an I2C communication setup, one device acts as the master
(usually a microcontroller), and the others are slaves (sensors, displays, etc.).
B. Data Transfer: When the master device sends data to a slave, it toggles the SCL line.
Each pulse of the SCL clock signal indicates when the slave should read the data on
the SDA line.
Example:
Suppose you have an Arduino as the master and a temperature sensor as the slave. Here’s
how the SCL pin works during communication:
a. Initialization: The Arduino initializes the I2C communication.
b. Data Request: The Arduino sends a request to the temperature sensor to read the
current temperature.
c. Clock Pulses: The Arduino toggles the SCL pin, generating clock pulses:
o For each bit of data sent on the SDA line, the Arduino generates a clock pulse
on the SCL line.
o The temperature sensor reads the data on SDA when SCL goes high.
Visual Representation:
 SCL High: Data is valid and can be read.
 SCL Low: The line is idle, waiting for the next data bit.
This synchronous operation ensures that the master and slaves are perfectly aligned in
their data exchange.
4. Digital Ground - A ground (0V) reference point for digital circuits.
5. Digital I/O Pins (2-13) - These pins can act as inputs or outputs, used for controlling
LEDs, reading sensors, etc.
6. Serial Out (TX) - Transmits data over the serial interface. In Other words, The Serial
Out (TX) pin on an Arduino is used to transmit data from the microcontroller to another
device, such as a computer or another Arduino. It operates using a communication
protocol known as serial communication, where data is sent one bit at a time over a
single wire (or pin). Serial In (RX) - Receives data over the serial interface. In other
words, The Serial In (RX) pin on an Arduino is used to receive data from another device
through a serial interface. It allows the microcontroller to read incoming data, which can
be sent from a variety of sources like another Arduino, a computer, or a sensor.
Example:
Consider you have two Arduino boards (Arduino A and Arduino B) that need to
communicate. Here's how the TX pin works:
1. Wiring:
a. Connect the TX pin (pin 1) of Arduino A to the RX pin (pin 0) of Arduino B.
b. The TX pin of Arduino A will send data to Arduino B's RX pin.
2. Code for Arduino A (Transmitter):

Page 7
3. Code for Arduino B (Receiver):

Here, Arduino A uses the TX pin to transmit "Hello, Arduino B!" to Arduino B, which
receives and displays it.
7. ICSP for ATmega16U2 - Used to program the USB-to-serial converter chip.
In-Circuit Serial Programming (ICSP) for the ATmega16U2 is used to program the USB-
to-serial converter chip found on certain Arduino boards, such as the Arduino Uno and
Mega. The ATmega16U2 acts as a bridge between the computer's USB port and the main
microcontroller’s (ATmega328P or ATmega2560) serial interface.

When programming the ATmega16U2, ICSP allows you to upload firmware to this chip,
such as when you need to restore or update the USB-to-serial functionality. This is
particularly useful when customizing or repairing the communication features of the
Arduino board.

Example:
If you want to update or restore the firmware of the ATmega16U2 on an Arduino Uno
using ICSP:

1. Wiring Setup:Connect an external programmer (like another Arduino board) to the


ICSP header of the target Arduino. Ensure the following connections:
- MISO, MOSI, SCK, and RESET pins match between the two boards.
- Use the external programmer to interface with the ATmega16U2.

2. Code & Firmware Upload:

Page 8
- On the external programmer Arduino, load the "Arduino as ISP" sketch.
- Use software like AVRDUDE to upload the desired firmware to the ATmega16U2 via
ICSP, restoring or updating its USB communication functionality.

This method is commonly employed for reprogramming the USB controller when
standard USB communication is non-functional.

8. On-Board LED (Pin 13) - A built-in LED connected to digital pin 13 for basic testing.
9. Power LED Indicator - Lights up when the board is powered.
10. TX and RX LEDs - These blink when data is transmitted or received via the serial port.
The TX (Transmit) and RX (Receive) LEDs on microcontroller boards like Arduino
indicate data communication activity over the serial port. These LEDs blink to visually
signal when data is being transmitted from the microcontroller to another device (TX) or
received by the microcontroller from an external device (RX).
Example:
1. TX LED: When you upload code from the Arduino IDE to an Arduino board via
USB, the TX LED blinks, indicating that data is being sent from the computer to the
Arduino’s USB-to-serial converter.
2. RX LED: When the Arduino sends data back to the computer (e.g., sensor data from
the board), the RX LED blinks, signaling that the data is being received by the USB
port.
For example, if you write a simple Arduino sketch that prints "Hello World" every second,
you will observe the TX LED blinking each time data is transmitted to the computer
through the serial monitor. If the board is receiving data (such as commands), the RX
LED will blink.
These indicators provide simple, visual feedback that confirms active communication.
Example:
In this code example, the Arduino will transmit a string of data ("Hello, World!") over the
serial port every second. The TX LED will blink every time data is sent, and the RX
LED will blink when the Arduino receives any data from the serial monitor.

 TX LED: Every time Serial.println("Hello, World!") is called, the TX LED will blink,
indicating that the message is being transmitted.
 RX LED: The RX LED will blink if any data is received by the Arduino from the
computer, like when you send data through the Serial Monitor.
Page 9
11. ICSP for ATmega328 - Allows direct programming of the main microcontroller.
ICSP (In-Circuit Serial Programming) for the ATmega328 microcontroller allows
users to program the chip directly while it is soldered onto a circuit board. This method is
particularly useful for standalone applications where the microcontroller needs to be
programmed after assembly.
How ICSP Works:
ICSP utilizes specific pins on the ATmega328 to program the microcontroller. These pins
include:
 MISO (Master In Slave Out)
 MOSI (Master Out Slave In)
 SCK (Serial Clock)
 RESET
 VCC (Power)
 GND
Example Setup:
1. Components Needed:
o ATmega328 microcontroller
o ICSP programmer (like USBasp or Arduino as ISP)
o Breadboard and jumper wires
2. Wiring: Connect the ICSP programmer to the ATmega328 as follows:
o Programmer MISO → ATmega328 MISO
o Programmer MOSI → ATmega328 MOSI
o Programmer SCK → ATmega328 SCK
o Programmer RESET → ATmega328 RESET
o Programmer VCC → ATmega328 VCC
o Programmer GND → ATmega328 GND
3. Programming: Use the Arduino IDE or a suitable programming tool. Here’s a simple
example to upload a "Blink" program that toggles an LED on and off.
Sample Code (Blink):

Steps to Upload:
 Select the appropriate board (ATmega328) and port in the Arduino IDE.
 Choose the programmer (e.g., "USBasp" or "Arduino as ISP").
 Click on "Upload" to program the microcontroller directly via ICSP.
This allows the ATmega328 to execute the Blink program once powered, demonstrating
the direct programming capability of ICSP.

Page 10
12. ATmega328 Microcontroller - The main chip that executes the code uploaded to the
board.
13. Reset Button - Restart the program on the Arduino without disconnecting power.
14. USB Socket - Connects the board to a computer for uploading code and powering the
board.
15. ATmega16U2 Microcontroller - Acts as a USB-to-serial converter.
16. Voltage Regulator - Regulates the input voltage to a stable 5V or 3.3V for the board.
17. External Power Supply Socket - Used to power the board with an external power source
(e.g., battery).
18. IOREF Pin - Provides the voltage reference for the microcontroller (usually 5V or 3.3V).
19. Reset Pin - Can be connected externally to reset the board.
20. Voltage Out Pins (3.3V, 5V) - Provide 3.3V or 5V to external devices connected to the
Arduino.
21. Ground Pins (GND) - Provides ground connections for external devices.
22. Voltage In Pin - Provides a voltage input from an external power source (7-12V
recommended).
23. Analog Pins (0-5) - Used to read analog signals from sensors, converting them to digital
values.

Arduino Features
 Input and Output Capabilities: Arduino boards can read analog or digital input signals
from various sensors. They can perform actions based on these signals, such as activating
a motor, turning LEDs on or off, connecting to the cloud, and executing many other tasks.
 Control via Instructions: The functions of Arduino boards can be managed by sending a
set of instructions to the microcontroller onboard through the Arduino Integrated
Development Environment (IDE).
 Simplified Programming: The Arduino IDE employs a simplified version of C++, which
makes it easier for beginners to learn programming and develop applications for the
Arduino platform.
 Standard Form Factor: Arduino provides a standard form factor that organizes the
functions of the microcontroller into a more accessible package, facilitating easier
prototyping and development.

Arduino IDE (Integrated Development Environment)


The Arduino Software (IDE) is user-friendly and built upon the Processing programming
environment. This cross-platform application supports Windows, macOS, and Linux and
utilizes functions from C and C++. As an open-source tool, the Arduino IDE simplifies the
process of writing code and uploading it to any Arduino board.
Key Features: The Arduino IDE includes:
 Text Editor: For writing and editing code.
 Message Area: Displays information and notifications about the code and processes.
 Text Console: Shows detailed messages about the program execution and errors.

Page 11
 Toolbar: Contains buttons for common functions, along with a series of menus for
additional options.
The IDE effectively connects to Arduino hardware to upload programs and facilitate
communication between the software and the board.
The Arduino IDE is a powerful and accessible platform that enables users to develop
applications for Arduino boards easily. Its design is centered around simplicity, making it
suitable for both beginners and experienced developers. With integrated features for coding,
error handling, and hardware communication, the IDE serves as an essential tool for Arduino
programming.

1. Menu Bar: Gives you access to the tools needed for creating and saving Arduino
sketches.
2. Verify Button: Compiles your code and checks for errors in spelling or syntax.

Page 12
3. Upload Button: Sends the code to the board that’s connected such as Arduino Uno
in this case. Lights on the board will blink rapidly when uploading.
4. New Sketch: Opens a new window containing a blank sketch.
5. Sketch Name: When the sketch is saved, the name of the sketch is displayed here.
6. Open Existing Sketch: Allows you to open a saved sketch or one from the stored
examples.
7. Save Sketch: This saves the sketch you currently have open.
8. Serial Monitor: When the board is connected, this will display the serial
information of your Arduino
9. Code Area: This area is where you compose the code of the sketch that tells the
board what to do.
10. Message Area: This area tells you the status on saving, code compiling, errors and
more.
11. Text Console: Shows the details of an error messages, size of the program that
was compiled and additional info.
12. Board and Serial Port: Tells you what board is being used and what serial port it’s
connected to.

Installation of Arduino Software (IDE)


Step 1: Downloading
 To install the Arduino software, download it from the official page: Arduino
Software. Proceed with the installation and allow the driver installation process.
Step 2: Directory Installation
 Choose the installation directory where the software will be installed.
Step 3: Extraction of Files
 The installer will extract and install all the necessary files required for the
Arduino Software (IDE) to function properly.
Step 4: Connecting the Board
 Connect the Arduino board to your computer using a USB cable. This connection
is essential not only for powering the board but also for programming it. The power
LED (labelled PWR) should light up.
Step 5: Working on a New Project
 Open the Arduino IDE software on your computer. You can start coding in
the Arduino language to control your circuit.
 Create a new sketch file by clicking on "New."
Step 6: Working on an Existing Project
 To access an existing project example, navigate to File → Examples → Basics
→ Blink.
Step 7: Select Your Arduino Board

Page 13
 To prevent errors while uploading your program, select the correct Arduino board
that matches the one connected to your computer.
 Go to Tools → Board and select your board model.
Step 8: Select Your Serial Port
 Choose the serial device corresponding to your Arduino board.
 Go to Tools → Serial Port. This is typically labeled as COM3 or higher (COM1
and COM2 are reserved for hardware serial ports).
 To identify the correct port, disconnect your Arduino board and observe which
entry disappears in the menu. Reconnect the board and select the remaining serial
port.
Step 9: Upload the Program to Your Board
 Click the "Upload" button in the IDE.
 Wait a few seconds; the RX and TX LEDs on the board will flash during the upload.
 If the upload is successful, the message "Done uploading" will appear in the status
bar.
Additional Functions
The Arduino Integrated Development Environment (IDE) provides several essential functions
that facilitate the coding, uploading, and debugging of sketches (programs) for Arduino
boards. Here’s a brief explanation of each additional function:
1. Verify
This function checks your code for errors without uploading it to the board. It compiles
the code and identifies any syntax or logical errors. This is an essential step to ensure
your code is error-free before uploading it.
2. Upload
This function transfers your compiled code (sketch) to the connected Arduino board.
After verifying your code, you can click "Upload" to program the board with the new
instructions.
3. New
This function opens a new sketch file, allowing you to start fresh with a blank coding
canvas. It’s useful for creating new projects or testing out new ideas.
4. Open
This function allows you to open an existing sketch file. You can load previously
saved projects to modify or continue working on them.
5. Save
This function saves your current sketch to your computer. It's crucial to regularly save
your work to avoid losing any progress.
Page 14
6. Serial Monitor
The Serial Monitor is a debugging tool that allows you to send and receive data from your
Arduino board over a serial connection. You can view output from your code and send
commands to the board, which is essential for troubleshooting and monitoring the
behavior of your sketches.
7. Installing Libraries in Arduino IDE
To enhance your projects in Arduino IDE, you may need to install libraries that
provide additional functionality. Here's how to install libraries in Arduino IDE:
1. Open the Arduino IDE: Launch the software on your computer.
2. Access Library Manager:
o Go to Sketch > Include Library > Manage Libraries. This opens
the Library Manager.
3. Search for Libraries:
o In the Library Manager, use the search bar to find the library you want
to install.
4. Install the Library:
o Click the Install button next to the library you wish to add.
5. Manual Installation (if you have a .zip file):
o Go to Sketch > Include Library > Add .ZIP Library.
o Select the .zip file of the library you downloaded to install it manually.
6. Verify Installation:
o You can check if the library is installed by going to Sketch > Include Library
to see it listed.

Page 15
General Sensors & Components
LED
A Light light-emitting diode (LED) is a semiconductor device that emits light when an
electric current flows through it. Understanding its structure is essential for proper usage:
1. Anode (+ve): The anode is the positive lead of the LED. It is
typically the longer leg of the diode and must be connected to the
positive voltage in a circuit. This allows current to flow into the
LED.
2. Cathode (-ve): The cathode is the negative lead of the LED,
usually the shorter leg. It connects to the ground or the negative
side of the power supply. The cathode serves as the exit point for
the current leaving the LED.
When a forward voltage is applied (anode to positive and cathode to negative), electrons
move from the anode to the cathode, recombining with electron holes and releasing energy in
the form of light. If the connections are reversed, the LED will not light up and may get
damaged due to reverse bias

Bread Board
A breadboard is a reusable platform used for prototyping and testing electronic circuits
without the need for soldering. It allows engineers, hobbyists, and students to quickly build
and modify circuits by placing components such as resistors, capacitors, and integrated
circuits into its interconnected holes.Key features include:
1. Solderless Connections: Components are inserted into holes that are electrically
connected in a grid, making it easy to connect different parts of the circuit.
2. Versatility: Breadboards can accommodate a variety of electronic
components, enabling quick experiments and modifications.
3. Ease of Use: They are user-friendly, making them ideal for beginners and
those learning electronics.

Note:

Page 16
Jumper wire
A jumper wire is an electrical wire with connector pins or terminals at each end. These wires
are commonly used to make temporary connections between different points in an electrical
circuit, such as on a breadboard, without the need for soldering.
Jumper wires are essential for prototyping and debugging circuits, as they enable quick and
easy setup. They are available in different types, including male-to-male, female-to-female,
and male-to-female, depending on the type of connection required. Additionally, jumper
wires come in various colors, which helps in organizing and distinguishing between
connections during circuit design.
Types of Jumper Wires
Jumper wires are essential components in electronic prototyping, and they come in various
types to suit different needs. Below are the main types:
1. Male-to-Male Jumper
o These have pins at both ends and are used for connecting two female ports,
such as on a breadboard or between modules.
2. Male-to-Female Jumper
o One end has a pin (male), and the other end has a socket (female). These are
ideal when connecting male headers on devices like sensors to a breadboard.
3. Female-to-Female Jumper
o These have sockets on both ends, used for connecting two male pins, such as
between two male header pins on different components.
Head Shapes

Jumper wires also come with two types of head shapes:


 Square head
 Round head
The head shape depends on the connector style but doesn't usually affect functionality.

Page 17
Additional Jumper Options
 Alligator Clips
o These are unique because they use spring-loaded metal clips, which can easily
connect components that lack standard pin connectors. They're handy for
irregular connections like those on a LilyPad Arduino.
Choosing the Right Jumper Wire
 Male-to-Male for connecting ports on a breadboard.
 Male-to-Female for connecting a breadboard to a sensor or module like an Ultrasonic
Sensor.

Note:

Page 18
DH11
The DHT11 is a low-cost, compact embedded sensor
designed for measuring temperature and humidity. It
features a simple four-pin configuration, which makes it
easy to integrate into various electronic projects. Here’s a
detailed breakdown of its specifications and functionality:
Key Specifications:
1. Temperature Range: Measures from 0°C to 50°C with an accuracy of ±2°C.
2. Humidity Range: Measures from 20% to 80% relative humidity with an accuracy of
±5%.
3. Pinout Configuration:
o Vcc: Requires a +5V power supply.
o Data: Digital output pin providing either 0V or 5V.
o NC: Not connected; reserved for future use.
o GND: Ground connection.
Functionality:
 The DHT11 uses a capacitive sensor for humidity measurement and an NTC
thermistor for temperature sensing.
 It updates the output value every 2 seconds and operates with a voltage range of 3V to
5.5V, making it compatible with both 3.3V and 5V microcontroller systems.
 The sensor has a sampling frequency of 1Hz, allowing it to collect data every second.
 Dimensions are compact at 27mm x 59mm x 13.5mm (1.05" x 2.32" x 0.53"), suitable
for embedded applications.
Unique Features:
 The DHT11 sensor is known for its precision and calibrated output, providing reliable
readings at a low cost compared to other sensors like SHT10 and DS18B20.
 It utilizes a single-wire serial interface for data transmission, making it easy to
connect and communicate with microcontrollers

Note:

Page 19
Infrared Proximity Sensors (IR Sensors)
An infrared proximity sensor (IR sensor) is an electronic device designed to emit infrared
light to detect surrounding objects and their motion. These sensors are widely used in the
electronics industry, particularly in applications like obstacle avoidance robots and proximity
detection systems.
Key Components, The IR sensor typically includes:
1. IR Transmitter (LED): Emits infrared light.
2. IR Receiver (Photodiode): Detects the reflected infrared light from nearby
objects. Pinout Configuration:
The IR sensor has a 3-pin connector:
 VCC: Power supply pin (connects to the
5V pin on Arduino).
 OUT: 5V TTL logic output. A LOW
signal indicates no motion, while a HIGH
signal indicates motion.
 GND: Ground connection for the Arduino.
Working Principle:
1. Emission: The sensor applies voltage to the IR LED, causing it to emit infrared light.
2. Reflection: This light travels through the air and hits nearby objects. If the object is
close, the reflected light is stronger; if farther away, the reflection is weaker.
3. Signal Processing: The photodiode receives the reflected light, and after some
processing, the sensor outputs a corresponding signal. This signal can be read by
microcontrollers like Arduino to trigger actions.
Features:
 Onboard LEDs: One LED indicates power, while the other indicates circuit activation.
 Sensitivity Adjustment: A potentiometer allows users to adjust sensitivity levels.
 Low Power and Cost: These sensors are budget-friendly and energy-efficient, making
them popular for hobbyist projects.
Applications, IR sensors are commonly utilized in:
 Proximity detection
 Obstacle avoidance for robots
 Various automation projects

Page 20
SWITCH: 6 Pin Square 7mmx7mm DPDT Mini Push
Button / On Off Switch aka "Mini Self Locking Push
Switch"

A 6-Pin Push Switch, also called a Mini DPDT (Double Pole Double Throw) Push Switch, is
essentially two push switches combined into one package. This switch is unique because it
retains its state (ON or OFF) until it is pushed again. Unlike momentary switches that only
make contact temporarily, the DPDT switch remains in its set state, making it ideal for
controlling power connections. For example, if I push it once to turn it on, it will remain in
the ON state until it’s pushed again. That’s why this switch is useful in controlling power
connections most of the time.
1. Independent Circuits: It has two independent common ports that are not connected. This
allows switching to two separate circuits.
2. ON/OFF State:
o When pushed once, it enters the ON state, connecting Pin 1 to Pin 2 and Pin 5 to
Pin 6.
o When pushed again, it reverts to the OFF state, connecting Pin 2 to Pin 3 and Pin
5 to Pin 4.
Key Components:
1. Poles: A DPDT switch has two poles, meaning it can control two separate circuits at
the same time.
2. Throws: Each pole can connect to one of two outputs, giving it two throw options.
Thus, each pole has a "throw" that allows switching between two different output
connections.
3. Pins and Terminals: The six terminals are arranged as two common input terminals
and four output terminals.
o Pins 1 and 2 connect for one state (ON), while Pins 3 and 4 connect in the
other state (OFF) for each pole.
Operation:

Page 21
 ON State: When the switch is in one position, it connects the common
pin (input) to the first set of output terminals.
 OFF State: When toggled, it connects the common pin to the second
set of output terminals, allowing it to switch between two circuits.
This flexible switching mechanism is useful in applications requiring multiple
connections like motor control or routing signals between different paths.

Note:

Page 22
Arduino D1
The ESP-D1 is a development board
based on the popular ESP8266 WiFi
microcontroller module. It is designed to
provide WiFi capabilities while
maintaining compatibility with the
Arduino IDE. Its layout mimics that of
standard Arduino boards like the Uno or
Leonardo, allowing it to work with many
existing Arduino shields.
Key Features:

1. WiFi Module (ESP8266): It offers 802.11 wireless communication, turning the


microcontroller into a powerful WiFi-enabled board.
2. Arduino Compatibility: It is designed to work with the Arduino IDE, making
programming simple and familiar. Many standard Arduino functions (digital and
analog pin operations) can be used.
3. CH340 USB Interface: This onboard chip allows direct communication between the
board and your computer using a micro-USB cable, appearing as a regular serial port.
No additional hardware is needed for programming.
4. Board Manager Integration: The ESP8266 support can be added via the Board
Manager in the Arduino IDE, making the process of programming and managing the
board straightforward.
5. WiFi Applications: The IDE includes examples of using the board’s WiFi capabilities,
from simple LED blinking to creating a standalone web server.
Specification:
 Microcontroller: ESP-8266EX
 Operating Voltage: 3.3V
 Digital I/O Pins: 11
 Analog Input Pins: 1
 Clock Speed: 80MHz/160MHz
 Flash: 4M bytes

Page 23
Experiment: 01
Date:

LED Control Using Arduino Board

Aim:
To control LED Using an Arduino Uno board
Apparatus:

Procedure/Setup:
 Hardware Setup
o Connect the anode (+) of the LED to pin 13 on the Arduino Uno.
o Connect the cathode (-) of the LED to one end of the 220Ω resistor.
o Connect the other end of the resistor to GND on the Arduino board.
o Attach the power jack to the Arduino Uno.
o Connect the USB cable to the Arduino for monitoring and uploading code.
o Connect the 12V power supply to the Arduino board.
 Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
o Upload the code to the Arduino Uno using the USB cable.

Page 24
CIRCUIT DIAGRAM:

PROGRAM:
const int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}

PRECAUTIONS:
 Ensure proper polarity of the LED.
 Handle the 12V power supply with caution.
 Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by the Arduino Uno board, blinking on and off at 1-second
intervals.

Page 25
Experiment: 02
Date:

LED Control Using Arduino Board

Aim:
To toggle an LED ON and OFF with a push-button switch, while displaying the
state of the LED in the Serial Monitor.
Apparatus:

Procedure/Setup:
o Hardware Setup
o LED:
 Connect the longer leg (anode) of the LED to pin 13 of the Arduino.
 Connect the shorter leg (cathode) of the LED to GND through a 220-ohm
resistor.
o Push Button:
 Connect one leg of the push button to pin 2 of the Arduino.
 Connect the opposite leg of the button to GND.
 Place a 10k ohm pull-up resistor between the button pin and VCC (5V).
o Attach the power jack to the Arduino Uno.
o Connect the USB cable to the Arduino for monitoring and uploading code.
o Connect the 12V power supply to the Arduino board.
 Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
o Upload the code to the Arduino Uno using the USB cable.
Page 26
CIRCUIT DIAGRAM:

Button --> Pin 2 --> 10kΩ Resistor --> GND


LED (Anode) --> Pin 13
LED (Cathode) --> Resistor (220Ω) --> GND
PROGRAM:
const int buttonPin = 2; // Pin connected to the push button
const int ledPin = 13; // Pin connected to the LED
int buttonState = 0; // Variable to store button state
int lastButtonState = 0; // Variable to store last button state
int ledState = LOW; // Variable to store LED state

void setup() {
pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
pinMode(buttonPin, INPUT); // Initialize the button pin as an input
Serial.begin(9600);
}

void loop() {
// Read the state of the push button
buttonState = digitalRead(buttonPin);

// Check if the button was pressed (LOW to HIGH transition)


if (buttonState != lastButtonState && buttonState == HIGH) {
ledState = !ledState;
digitalWrite(ledPin, ledState);

// Display the LED state on the Serial Monitor


if (ledState == HIGH) {
Serial.println("LED is ON");
} else {
Serial.println("LED is OFF");
}
}
lastButtonState = buttonState; // Save the current button state for the next iteration
delay(50); // Small delay to debounce the button
}

PRECAUTIONS:
 Handle the 12V power supply with caution.
 Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page 27
Step 1: Item Preparation
 Breadboard
 Arduino Wemos D1 Wifi UNO ESP8266
 Jumper wires male to male
 LED Traffic Light Module ( you can also use base LEDs )
 micro USB
 Smartphone ( You need to download "Blynk" from Play Store/iStore )
Step 2: Pin Connection

Follow the connection as shown above.


Step 3: Board Installation

Page 28
Next, open Arduino IDE and go to [File => Preferences]. A dialog box appears. In this
box, an additional board manager URL text box is present.
 Copy and paste the following URL into the box and click OK to download
the packages.
 http://arduino.esp8266.com/stable/package_esp8266com_index.json
Step 4: Find Out in Board Manager

Page 29
Next, go to [Tools => Board => Board Manager] in your Arduino IDE. The Boards Manager
window appears as below. Scroll down the boards in the board manager to select ESP8266
from the list of available boards. Click on install to begin the installation.
Step 5: Select Board

Page 30
Next, uploading your first program select the type of "WeMos D1 R1" board from the [Tools
=> Boards] section in your Arduino IDE.
Step 6: Example Code

Page 31
5 More Images
To get the example code from the Blynk you need to download the library from
Blynk website.
 https://www.blynk.cc/getting-started/
Follow these steps:
1. Select "Download Blynk Library".
2. Select to "Blynk_Release_v0.5.4.zip".
3. Extract the files and copy both of the files (libraries, tools).
4. Open Arduino IDE go to [Files => Preferences] find the files that appears on the
"Sketchbooks location".
5. Open the Arduino file and paste both of the files you've copied.
Then, open your Arduino IDE, go to [Files => Examples => Blynk => Boards Wifi
=>Standalone] for the example code.
Step 7: Blynk Setup

Page 32
Page 33
6 More Images
Next, you need to set up your "Blynk" from your smartphone.
Follow these steps:
8. Download "Blynk" at Play Store/iStore.
9. Sign up using your email.
10. Go to "New Project" Enter your project name (if needed).
11. Choose device "WeMos D1".
12. Connection type "Wifi" then "Create". (After create you will receive Auth Token
from your email).
13. Slide to the left to open "Widget Box".
14. Select "Button" to add button.
15. Touch the button for "Button Settings".
16. Select [Output => Digital => D2,D3,D4] to choose pin connection.
17. Mode turn into "Switch".
Step 8: Uploading

Page 34
Now you need to check out your email inbox and copy the Auth token code.
Insert the Auth Token, Network name, and Password to your programming. Now upload the
code to your WeMos D1 (ESP8266) through micro USB. Make sure you use the right port
by select at [Tools => Port].
Step 9: Try Out Blynk Button

Select the play button from the upper right side and turn on the pin button.

Page 35
Experiment: 03
Date:

Push Button/Sensor Control Using Arduino

Aim:
To interface Push button/Digital sensor (IR/PDR) with Arduino/RaspberryPi
and write a program to turn on LED when push button is pressed or at sensor
detection.
Apparatus:

Procedure/Setup:
o Hardware Setup
o Connect one terminal of the push button to pin 7 on the Arduino.
o Connect the other terminal of the push button to GND.
 Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
o Upload the code to the Arduino Uno using the USB cable.

Page 36
CIRCUIT DIAGRAM:

PROGRAM:
// Define pins for LED and push button
int ledPin = 13;
int buttonPin = 7;

void setup() {
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);

// Set the button pin as an input with an internal pull-up resistor


pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
// Read the state of the button
int buttonState = digitalRead(buttonPin);

// Check if the button is pressed (buttonState is LOW due to pull-up)


if (buttonState == LOW) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// Turn off the LED
digitalWrite(ledPin, LOW);
Page 37
}
}

PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page 38
Experiment: 04
Date:
Dice Simulation Using LEDs and Arduino

Aim:
Simulate the rolling of a dice using LEDs. Use 7 LEDs to represent the numbers 1 to 6 and a
random number generator in Arduino to light up the corresponding LED when a button is
pressed.
Apparatus:

Procedure/Setup:
o Hardware Setup
o LEDs (1-7):

Place 7 LEDs on a breadboard, arranging them in a way that resembles the dots on a dice face.
Connect each anode (+) of the LEDs to different digital pins on the Arduino (for example, pins
2 to 8).
Connect the cathode (-) of each LED to GND on the Arduino through a 220Ω resistor for each
LED.
Push Button:

Connect one terminal of the push button to pin 9 on the Arduino.


Connect the other terminal of the push button to GND.
Use an internal pull-up resistor to keep the button state HIGH when not pressed.
Power Connections:

Attach the power jack to the Arduino Uno.


Connect the USB cable to the Arduino for monitoring and uploading code.
Connect the 12V power supply to the Arduino Uno to power the board.
• Software Procedure
Page 39
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
Upload the code to the Arduino Uno using the USB cable.

CIRCUIT DIAGRAM:

PROGRAM:
// Define pins for LEDs in a 3x3 pattern
int ledPins[] = {2, 3, 4, 5, 6, 7, 8}; // LEDs 1 to 7
int buttonPin = 9; // Button pin

void setup() {
// Set up LED pins as outputs
for (int i = 0; i < 7; i++) {
pinMode(ledPins[i], OUTPUT);
}

// Set up button pin as input with internal pull-up resistor


pinMode(buttonPin, INPUT_PULLUP);

// Initialize serial communication (optional for debugging)


Serial.begin(9600);

Page
310
// Seed random generator with an analog read from an unconnected pin
randomSeed(analogRead(0));
}

void loop() {
// Check if the button is pressed
if (digitalRead(buttonPin) == LOW) {
// Generate a random number between 1 and 6
int diceRoll = random(1, 7);

// Optional: Print the result to the Serial Monitor


Serial.println(diceRoll);

// Display the dice roll on the LEDs


displayDice(diceRoll);

// Wait for the button to be released


while (digitalRead(buttonPin) == LOW);
delay(500); // Debounce delay
}
}

// Function to display dice pattern on LEDs


void displayDice(int number) {
// Turn off all LEDs initially
for (int i = 0; i < 7; i++) {
digitalWrite(ledPins[i], LOW);
}

// Turn on LEDs based on the dice number


switch (number) {
case 1: // Center LED
digitalWrite(ledPins[4], HIGH);
break;
case 2: // Top-left and bottom-right
digitalWrite(ledPins[0], HIGH);
Page
311
digitalWrite(ledPins[6], HIGH);
break;
case 3: // Top-left, center, and bottom-right
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[4], HIGH);
digitalWrite(ledPins[6], HIGH);
break;
case 4: // Four corners
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[2], HIGH);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[8], HIGH);
break;
case 5: // Four corners and center
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[2], HIGH);
digitalWrite(ledPins[4], HIGH);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[8], HIGH);
break;
case 6: // Top, middle, and bottom left and right
digitalWrite(ledPins[0], HIGH);
digitalWrite(ledPins[2], HIGH);
digitalWrite(ledPins[3], HIGH);
digitalWrite(ledPins[5], HIGH);
digitalWrite(ledPins[6], HIGH);
digitalWrite(ledPins[8], HIGH);
break;
}
}
PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.
Page
312
Page
313
Experiment: 05
Date:
Traffic Light Simulation Using LEDs and Arduino

Aim:
Simulate a traffic light system using LEDs. Use red, yellow, and green LEDs to represent a
traffic signal and control the timing with Arduino code to simulate traffic light changes.
Apparatus:

Procedure/Setup:
o Hardware Setup
Red, Yellow, and Green LEDs:

Red LED: Connect the anode (+) to pin 10 on the Arduino and the cathode (-) to one end of a
220Ω resistor. Connect the other end of the resistor to GND.
Yellow LED: Connect the anode (+) to pin 11 and the cathode (-) through a 220Ω resistor to
GND.
Green LED: Connect the anode (+) to pin 12 and the cathode (-) through a 220Ω resistor to
GND.
Power Connections:

Attach the power jack to the Arduino Uno.


Connect the USB cable to the Arduino for monitoring and uploading code.
Connect the 12V power supply to the Arduino Uno to power the board.
• Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
Page
314
Upload the code to the Arduino Uno using the USB cable.
CIRCUIT DIAGRAM:

PROGRAM:
// Define pins for each LED
int redLed = 2;
int yellowLed = 3;
int greenLed = 4;

void setup() {
// Set each LED pin as an output
pinMode(redLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(greenLed, OUTPUT);
}

void loop() {
// Green light - GO
digitalWrite(greenLed, HIGH); // Turn on green LED
digitalWrite(yellowLed, LOW); // Ensure yellow LED is off
digitalWrite(redLed, LOW); // Ensure red LED is off
delay(5000); // Wait for 5 seconds

// Yellow light - CAUTION


digitalWrite(greenLed, LOW); // Turn off green LED
digitalWrite(yellowLed, HIGH); // Turn on yellow LED
digitalWrite(redLed, LOW); // Ensure red LED is off
Page
315
delay(2000); // Wait for 2 seconds

// Red light - STOP


digitalWrite(greenLed, LOW); // Ensure green LED is off
digitalWrite(yellowLed, LOW); // Ensure yellow LED is off
digitalWrite(redLed, HIGH); // Turn on red LED
delay(5000); // Wait for 5 seconds
}
PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page
316
Experiment: 06
Date:
IR Sensor Interface with Arduino

Aim:
To interface IR sensor with Arduino/Raspberry Pi and Write a program to turn on an LED
when motion is detected.
Apparatus:

Procedure/Setup:
o Hardware Setup
IR Sensor:

Connect the VCC pin of the IR sensor to the 5V pin on the Arduino.
Connect the GND pin of the IR sensor to the GND on the Arduino.
Connect the OUT (signal) pin of the IR sensor to digital pin 2 on the Arduino.
LED:

Connect the anode (+) of the LED to digital pin 13 on the Arduino.
Connect the cathode (-) of the LED to one end of a 220Ω resistor.
Connect the other end of the resistor to GND on the Arduino.
Power Connections:

Attach the power jack to the Arduino Uno.


Connect the USB cable to the Arduino for monitoring and uploading code.
Optionally, connect a 12V power supply to power the Arduino externally.
• Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
Page
317
o Click Save to store the program.
o Click Verify to check the code for errors.
Upload the code to the Arduino Uno using the USB cable.
CIRCUIT DIAGRAM:

PROGRAM:
// Define pins for IR sensor and LED
int irSensorPin = 7;
int ledPin = 13;

void setup() {
// Set up the LED pin as an output
pinMode(ledPin, OUTPUT);

// Set up the IR sensor pin as an input


pinMode(irSensorPin, INPUT);

// Begin serial communication (optional, for debugging)


Serial.begin(9600);
}

void loop() {
// Read the state of the IR sensor
int sensorState = digitalRead(irSensorPin);

// Check if motion or an object is detected


if (sensorState == HIGH) { // Adjust if your sensor outputs LOW when detecting
Page
318
// Turn on the LED
digitalWrite(ledPin, HIGH);
Serial.println("Motion detected"); // Debugging message
} else {
// Turn off the LED
digitalWrite(ledPin, LOW);
}

// Small delay to avoid rapid toggling


delay(100);
}
PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page
319
Experiment: 07
Date:
DHT11 Sensor Control Using Arduino

Aim:
To interface DHT11 sensor with Arduino/Raspberry Pi and write a program to Measure and
display temperature and humidity readings on the Serial Monitor
Apparatus:

Procedure/Setup:
o Hardware Setup
DHT11 Sensor:

Connect the VCC pin of the DHT11 sensor to the 5V pin on the Arduino.
Connect the GND pin of the DHT11 sensor to GND on the Arduino.
Connect the DATA pin of the DHT11 sensor to digital pin 2 on the Arduino.
Power Connections:

Attach the power jack to the Arduino Uno.


Connect the USB cable to the Arduino for monitoring and uploading code.
Optionally, connect a 12V power supply to the Arduino Uno for additional power.
• Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
Upload the code to the Arduino Uno using the USB cable.

Page
320
CIRCUIT DIAGRAM:

PROGRAM:
// Define the pin and type of DHT sensor
#define DHTPIN 2 // Pin where the DHT11 data pin is connected
#define DHTTYPE DHT11 // DHT11 sensor type

// Initialize DHT sensor


DHT dht(DHTPIN, DHTTYPE);

void setup() {
// Start serial communication for displaying readings
Serial.begin(9600);

// Initialize DHT sensor


dht.begin();

// Optional message
Serial.println("DHT11 Temperature and Humidity Sensor Test");
}

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

// Reading temperature and humidity


Page
321
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

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

// Display the readings on the Serial Monitor


Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}
PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page
322
Experiment: 08
Date:
LED control using Serial Monitor and Arduino

Aim:
LED control using Serial Monitor and Arduino
Apparatus:

Procedure/Setup:
o Hardware Setup
o .Connect the anode (+) of the LED to pin 13 on the Arduino Uno.
o Connect the cathode (-) of the LED to one end of the 220Ω resistor.
o Connect the other end of the resistor to GND on the Arduino board.
o Attach the power jack to the Arduino Uno.
o Connect the USB cable to the Arduino for monitoring and uploading code.
o Connect the 12V power supply to the Arduino board.

• Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
Upload the code to the Arduino Uno using the USB cable.

Page
323
CIRCUIT DIAGRAM:

PROGRAM:
// Define pin for LED

void setup() {
// Initialize the LED pin as an output
pinMode(13, OUTPUT);

// Start Serial communication for reading input


Serial.begin(9600);

// Wait for the serial monitor to open


while (!Serial) {
; // Wait for serial port to connect (needed for some boards like Leonardo)
}

Serial.println("LED Control Program");


Serial.println("Commands: ");
Serial.println(" ON - Turn on LED");
Serial.println(" OFF - Turn off LED");
Serial.println(" AUTO - Turn on LED every 2 seconds");
}

void loop() {
Page
324
// Check if data is available from the Serial Monitor
if (Serial.available() > 0) {
// Read the incoming byte
String command = Serial.readStringUntil('\n'); // Read until newline character

// Remove any extra whitespace from the input


command.trim();

// Control LED based on the command


if (command == "ON") {
digitalWrite(13, HIGH); // Turn LED on
Serial.println("LED is ON");
}
else if (command == "OFF") {
digitalWrite(13, LOW); // Turn LED off
Serial.println("LED is OFF");
}
else if (command == "AUTO") {
Serial.println("LED will turn on every 2 seconds.");

// Automatically toggle LED every 2 seconds


while (true) {
digitalWrite(13, HIGH); // Turn LED on
Serial.println("LED is ON");
delay(2000); // Wait for 2 seconds

digitalWrite(13, LOW); // Turn LED off


Serial.println("LED is OFF");
delay(2000); // Wait for 2 seconds

// Check for new command from Serial Monitor to exit "AUTO" mode
if (Serial.available() > 0) {
String newCommand = Serial.readStringUntil('\n');
newCommand.trim();
if (newCommand == "STOP") {
Serial.println("Exiting AUTO mode.");
Page
325
break;
}
}
}
}
else {
Serial.println("Invalid command. Please use ON, OFF, or AUTO.");
}
}
}
PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page
326
Experiment: 09
Date:
Controlling LED state based on even or odd number input via Serial Monitor

Aim:
To create a program using Arduino to control an LED based on user input, where the LED
turns ON for even numbers and OFF for odd numbers entered via the Serial Monitor.
Apparatus:

Procedure/Setup:
o Hardware Setup
o .Connect the anode (+) of the LED to pin 13 on the Arduino Uno.
o Connect the cathode (-) of the LED to one end of the 220Ω resistor.
o Connect the other end of the resistor to GND on the Arduino board.
o Attach the power jack to the Arduino Uno.
o Connect the USB cable to the Arduino for monitoring and uploading code.
o Connect the 12V power supply to the Arduino board.

• Software Procedure
o Open Arduino IDE on your computer.
o Click on File > New to create a new sketch.
o Write the program based on the circuit pin connections (see code below).
o Click Save to store the program.
o Click Verify to check the code for errors.
Upload the code to the Arduino Uno using the USB cable.

Page
327
CIRCUIT DIAGRAM:

PROGRAM:
// Define pin for LED

void setup() {
// Initialize the LED pin as an output
pinMode(13, OUTPUT);

// Start Serial communication for reading input


Serial.begin(9600);

// Wait for the serial monitor to open


while (!Serial) {
; // Wait for serial port to connect (needed for some boards like Leonardo)
}

Serial.println("Enter a number:");
}

void loop() {
// Check if data is available from the Serial Monitor
if (Serial.available() > 0) {
// Read the incoming byte
int number = Serial.parseInt(); // Read the number entered in the Serial Monitor
Page
328
// Print the number entered
Serial.print("You entered: ");
Serial.println(number);

// Check if the number is even or odd


if (number % 2 == 0) {
// If the number is even, turn on the LED
digitalWrite(13, HIGH);
Serial.println("The number is even. LED is ON.");
} else {
// If the number is odd, turn off the LED
digitalWrite(13, LOW);
Serial.println("The number is odd. LED is OFF.");
}
}
}
PRECAUTIONS:
• Handle the 12V power supply with caution.
• Double-check all circuit connections before powering the system.

EXPECTED RESULT:
The LED is successfully controlled by Switch, switching on and off on click.

Page
329

You might also like