Configure Arduino & Raspberry Pi for Sensors
Configure Arduino & Raspberry Pi for Sensors
with Sensors
Aim
To configure the Arduino UNO and Raspberry Pi boards by preparing their hardware and
software environments, and writing a basic initialization program to enable the Digital
Input/Output (I/O) and Analog Input pins for subsequent sensor interfacing.
Theory
Interfacing a sensor requires two main steps:
1. Hardware Connection: Connecting the sensor's output (voltage) to the board's
appropriate pin (Digital or Analog).
2. Software Configuration: Writing code that initializes the pin, sets its mode (INPUT or
OUTPUT), and reads the incoming data.
<!-- end list -->
● Digital I/O: Pins that can only be \text{HIGH} (e.g., 5V or 3.3V) or \text{LOW} (0V). Used
for simple ON/OFF switches, buttons, and sensors that output binary data.
● Analog Input: Pins found primarily on Arduino (and often accessed via an external ADC
on Raspberry Pi) that measure a continuous range of voltages and convert it into a
discrete digital value (e.g., 0-1023 for a 10-bit ADC). This is essential for sensors like
temperature, light, and humidity that have variable output.
Board Digital I/O (GPIO) Analog Input Typical Voltage Level
Arduino UNO \text{Pins } 0-13 \text{Pins A0-A5} 5\text{V}
(Onboard 10-bit ADC)
Raspberry Pi \text{All GPIO pins} None (Requires 3.3\text{V}
External ADC)
Code & Configuration
1. Arduino UNO Configuration (Using C++)
This code sets up a Digital Pin (2) as an INPUT to read a switch and an Analog Pin (A0) to
read a variable voltage sensor.
// Arduino C++ Code
const int digitalPin = 2; // Pin for digital sensor (e.g., switch)
const int analogPin = A0; // Pin for analog sensor (e.g., LDR)
void setup() {
// 1. Initialize Serial Communication for debugging
[Link](9600);
// 2. Configure Digital Pin as an INPUT
pinMode(digitalPin, INPUT);
// NOTE: Analog pin configuration is automatic in Arduino
// when using analogRead(), so no explicit pinMode() is needed.
[Link]("Arduino configured for sensor interfacing.");
}
void loop() {
// Read Digital Sensor (will be HIGH or LOW)
int digitalState = digitalRead(digitalPin);
// Read Analog Sensor (will be 0 to 1023)
int analogValue = analogRead(analogPin);
// Print values for verification
[Link]("Digital State: ");
[Link](digitalState);
[Link](" | Analog Value: ");
[Link](analogValue);
delay(500); // Wait half a second
}
This code uses the \text{[Link]} library to configure a GPIO pin (17) as a Digital Input.
Note: As the RPi has no internal Analog-to-Digital Converter (ADC), you must use an external
component (like the \text{MCP3008}) for analog input. This code focuses on the mandatory
digital configuration.
# Raspberry Pi Python Code
import [Link] as GPIO
import time
digital_pin = 17 # Use BCM numbering for GPIO 17
# 1. Set the GPIO mode
[Link]([Link])
# 2. Configure the Digital Pin as an INPUT
[Link](digital_pin, [Link])
print("Raspberry Pi configured for sensor interfacing.")
try:
while True:
# Read Digital Sensor (will be 0 or 1)
digital_state = [Link](digital_pin)
# Print value for verification
print(f"Digital State (GPIO 17): {digital_state}")
[Link](0.5)
except KeyboardInterrupt:
# 3. Clean up the GPIO settings on exit
[Link]()
print("GPIO cleanup complete.")
Conclusion
The practical successfully configured both the Arduino UNO and Raspberry Pi platforms for
sensor interfacing. The Arduino was initialized to use both Digital Input and its built-in Analog
Input (A0), demonstrating its direct capability for variable sensor reading. The Raspberry Pi
was configured for Digital Input using the \text{[Link]} library in Python, highlighting its
reliance on digital signals and the need for external hardware for analog measurements. These
configurations lay the groundwork for connecting and processing data from any subsequent
sensor in the practical list.
💡 Practical 3: Interface, Control & Program LED
Using Switch
Aim
To interface a tactile switch (input) and a Light Emitting Diode (LED) (output) with an
Arduino UNO board and program the board such that the LED toggles its state (ON or OFF)
every time the switch is pressed.
Theory
This practical utilizes basic Digital Input and Digital Output.
1. LED (Output): An LED is a diode that requires current limiting. We connect it to a digital
pin (output) through a current-limiting resistor (typically 220\text{ }\Omega or 330\text{
}\Omega) to prevent it from burning out. Setting the digital pin to \text{HIGH} turns the
LED ON, and \text{LOW} turns it OFF.
2. Switch (Input): A tactile switch acts as a momentary button. To read its state, we use a
digital input pin. To ensure the pin reads a stable \text{LOW} when the switch is not
pressed, we use a pull-down resistor (e.g., 10\text{ k}\Omega) connected to ground.
When the switch is pressed, the pin is connected to 5\text{V} and reads \text{HIGH}.
3. State Toggling Logic: The program uses a state variable to track the current ON/OFF
status of the LED. It also employs edge detection logic (checking for a transition from
\text{LOW} to \text{HIGH} on the switch) to ensure the LED state changes only once per
press, not multiple times while the button is held down.
Components Required
● Arduino UNO Board
● LED
● Tactile Switch (Push button)
● 220\text{ }\Omega Resistor (for LED)
● 10\text{ k}\Omega Resistor (for switch pull-down)
● Breadboard and connecting wires
Conclusion
The objective was successfully achieved. By configuring Digital Pin 2 as an input (with a
pull-down resistor) to read the switch and Digital Pin 13 as an output to control the LED, a
simple control system was created. The program uses edge detection logic (if
(currentSwitchState == HIGH && lastSwitchState == LOW)) to distinguish a new button press
from a held button, ensuring that the LED's state toggles exactly once with each press. This
demonstrates fundamental control flow and I/O management, which is essential for creating
interactive IoT devices.
🖥️ Practical 4: Interface, Control & Program LCD
Display Using a Switch
Aim
To interface a 16 \times 2 Liquid Crystal Display (LCD) with an I2C module and a tactile
switch to an Arduino UNO board. The program will display different messages on the LCD
based on whether the switch is pressed or released.
Theory
This practical combines Digital Input (from the switch) with Digital Output to a complex display
device (LCD).
1. I2C 16 \times 2 LCD: Standard parallel 16 \times 2 LCDs require many GPIO pins (at
least 6). The I2C (Inter-Integrated Circuit) module is an adapter that reduces the
required connections to just two data lines: SDA (Serial Data) and SCL (Serial Clock),
plus power (VCC) and ground (GND). This conserves valuable GPIO pins for other
sensors.
2. Arduino I2C Pins: On the Arduino UNO, the I2C lines are typically connected to Analog
Pin 4 (SDA) and Analog Pin 5 (SCL), though they may also be available on dedicated
pins near the \text{AREF} header.
3. Switch Input: The switch is configured as a Digital Input using a pull-down resistor (as
in Practical 3) to give a clean \text{LOW} (released) or \text{HIGH} (pressed) signal.
4. Logic: The program continuously checks the switch state. If \text{HIGH}, it displays one
message; if \text{LOW}, it displays a different message.
Components Required
● Arduino UNO Board
● 16 \times 2 LCD with I2C module (PCF8574)
● Tactile Switch (Push button)
● 10 \text{ k}\Omega Resistor (for switch pull-down)
● Breadboard and connecting wires
Conclusion
The practical successfully demonstrated the interface of both an input device (switch) and an
output device (I2C LCD) with the Arduino UNO. By leveraging the I2C communication
protocol, pin utilization was minimized. The program successfully implemented decision logic
(if/else) based on the switch's digital input state, resulting in a dynamic change of the displayed
text on the LCD. This establishes a foundation for creating user interfaces where physical inputs
trigger information updates, a common requirement in many IoT monitoring devices.
Yes, here is the fifth practical on your list: Interfacing and controlling a DC Motor. This shifts
the focus from passive outputs (LEDs, LCDs) to controlling an actuator, which is crucial for
Aim
To interface a small DC motor with an Arduino UNO board using an L298N H-Bridge Motor
Driver and program the Arduino to control the motor's speed and direction.
Theory
Directly connecting a DC motor to an Arduino's GPIO pins will damage the board because
motors draw significantly more current than the pins can safely supply (typically 20-40\text{
mA}).
1. Motor Driver (L298N): This is an \text{H}-bridge circuit designed to handle the high
current required by motors, using a separate power supply. It acts as an interface and
power amplifier between the low-current digital signals of the Arduino and the
high-current requirements of the motor.
2. Direction Control: The L298N module typically uses two input pins (e.g., IN1 and IN2)
per motor. By setting one \text{HIGH} and the other \text{LOW}, the motor rotates in one
direction. Reversing the signals reverses the direction.
3. Speed Control (PWM): To control the motor's speed, we use Pulse Width Modulation
(PWM). PWM is a technique that rapidly switches the power ON and OFF. The duty cycle
(the percentage of time the power is ON) determines the effective voltage supplied to the
motor, thus controlling its speed. On the Arduino UNO, PWM is available on specific
digital pins (marked with a \sim, e.g., Pins 3, 5, 6, 9, 10, 11).
Components Required
● Arduino UNO Board
● L298N H-Bridge Motor Driver Module
● Small DC Motor (3\text{V} to 12\text{V})
● External Power Supply (e.g., 9\text{V} battery or power adapter) for the motor driver
● Connecting wires
Conclusion
The practical successfully interfaced and controlled a DC motor using an L298N motor driver
to safely bridge the power gap between the Arduino and the high-current motor. By manipulating
the digital \text{IN1} and \text{IN2} pins, the motor's direction was controlled (forward and
reverse). More importantly, the use of the analogWrite() function on the dedicated PWM pin (Pin
9) allowed for the effective control of the motor's speed, demonstrating a fundamental principle
of actuator control in IoT and embedded systems.
Would you like me to proceed with the sixth practical: "Interface & program a stepper
motor," which involves a motor requiring more precise rotational control?
🧭 Practical 6: Interface & Program a Stepper Motor
Aim
To interface a unipolar/bipolar stepper motor with an Arduino UNO board using a suitable
motor driver (e.g., ULN2003 for unipolar, L298N for bipolar) and program the Arduino to
control the motor to rotate a specific number of steps in both clockwise (CW) and
counter-clockwise (CCW) directions.
Theory
A stepper motor is a brushless DC electric motor that divides a full rotation into a number of
equal steps. This allows for precise control of position and speed without any feedback
mechanism (open-loop control).
1. Stepping: The motor moves in discrete steps, typically 1.8^\circ per step (200 steps per
revolution) or 5.625^\circ per step (64 steps per revolution for a common 28\text{BYJ}-48
geared motor).
2. Motor Driver: Stepper motors have multiple coils that must be energized in a precise
sequence.
○ Unipolar Stepper: Often uses a ULN2003 Darlington Array driver, which
simplifies the wiring and sequencing.
○ Bipolar Stepper: Requires an \text{H}-bridge driver like the L298N (used in
Practical 5) or a specialized driver like the A4988 for current control.
3. Control: The Arduino controls the stepping sequence by sending digital signals to the
driver. The sequence defines the direction and amount of rotation. We typically use the
Arduino Stepper Library to handle the complex coil sequencing.
Components Required
● Arduino UNO Board
● 28\text{BYJ}-48 Stepper Motor (Unipolar, with gear reduction)
● ULN2003 Stepper Motor Driver Board
● External Power Supply (5\text{V} for the motor)
● Connecting wires
Theory
A Servo Motor is an actuator that provides rotational position control within a limited range,
typically 0^\circ to 180^\circ. Unlike DC motors, which spin continuously, and Stepper motors,
which require constant stepping, a Servo motor maintains a specific angle when commanded,
making it ideal for positioning tasks.
1. Three Wires: Servo motors typically have three wires:
○ \text{GND} (Black/Brown)
○ \text{VCC} (Red, usually 5\text{V})
○ Signal (Orange/Yellow/White)
2. Control Signal (PWM): The Servo is controlled by a specific type of Pulse Width
Modulation (PWM) signal sent to the signal wire. The pulse width (the length of the
\text{HIGH} signal) determines the commanded angular position:
○ A narrow pulse (e.g., 500\text{ }\mu\text{s} or 1\text{ ms}) commands the 0^\circ
position.
○ A wide pulse (e.g., 2500\text{ }\mu\text{s} or 2\text{ ms}) commands the 180^\circ
position.
○ A mid-range pulse (e.g., 1500\text{ }\mu\text{s} or 1.5\text{ ms}) commands the
90^\circ position.
3. Arduino \text{Servo} Library: The Arduino \text{Servo} library is essential as it
simplifies this complex timing process. Instead of manually calculating pulse widths, you
simply use the \text{[Link]}(\text{angle}) function, where angle is a value from 0 to
180.
Components Required
● Arduino UNO Board
● SG90 or similar Standard Servo Motor
● Connecting wires
Conclusion
The practical successfully interfaced and controlled the Servo motor using the Arduino's
\text{Servo} library. The use of \text{[Link]}(\text{angle}) simplified the underlying PWM
signal generation, allowing for direct control over the motor's angular position. The code
demonstrated both discrete positioning (moving to 0^\circ, 90^\circ, and 180^\circ) and
continuous, controlled motion (the sweep pattern). This highlights the Servo motor's
capability for precise, limited-range actuation, making it a critical component for IoT applications
requiring specific physical movements or alignments.
🔆 Practical 8: Interface & Program Light Sensor
(LDR) with IoT Board (Arduino)
Aim
To interface a Light Dependent Resistor (LDR) with an Arduino UNO board and program it to
read the ambient light intensity and print the corresponding analog value and a scaled,
human-readable measurement to the Serial Monitor.
Theory
An LDR (Photoresistor) is a passive sensor whose resistance changes based on the intensity
of light falling on its surface.
1. Operation: In bright light, the resistance is low (a few hundred ohms). In darkness, the
resistance is very high (several megaohms).
2. Voltage Divider: Since the Arduino's analog pins measure voltage, not resistance, the
LDR must be part of a voltage divider circuit. This circuit consists of the LDR and a
fixed-value series resistor (e.g., 10 \text{ k}\Omega). The voltage at the midpoint
between the two resistors is fed to the Arduino's analog pin.
○ As light increases, LDR resistance decreases, causing the voltage at the analog pin
to increase.
○ As light decreases, LDR resistance increases, causing the voltage at the analog pin
to decrease.
3. Analog Read: The Arduino's built-in Analog-to-Digital Converter (ADC) converts the
analog voltage (0V to 5V) into a digital value ranging from 0 (darkest) to 1023
(brightest).
Components Required
● Arduino UNO Board
● Light Dependent Resistor (LDR)
● 10 \text{ k}\Omega Resistor (Fixed, for voltage divider)
● Breadboard and connecting wires
Conclusion
The practical successfully interfaced the LDR with the Arduino by implementing a voltage
divider circuit to convert the LDR's resistance change into a measurable voltage. The
analogRead() function was used to capture this analog voltage and convert it into a digital value
(0 to 1023). The code demonstrated how to not only read raw sensor data but also process
and scale it into a more meaningful percentage and descriptive status, which is essential before
transmitting data in a real-world IoT application.
🌡️ Practical 9: Interface & Program Temperature
Sensor (LM35) with IoT Board (Arduino)
Aim
To interface the LM35 Precision Centigrade Temperature Sensor with an Arduino UNO
board and program it to read the analog voltage output, convert this reading into a temperature
in Degrees Celsius (\mathbf{^\circ C}), and display the result on the Serial Monitor.
Theory
The LM35 is a linear analog temperature sensor that provides an output voltage directly
proportional to the temperature in Celsius. It is commonly preferred over thermistors because it
does not require complex linearization or a voltage divider circuit.
1. Linearity: The LM35 outputs 10\text{ mV} for every 1^\circ \text{C} change.
○ At 0^\circ \text{C}, the output is 0\text{V}.
○ At 25^\circ \text{C} (Room Temperature), the output is 250\text{ mV} (0.25\text{V}).
2. Arduino ADC: The Arduino's 10-bit Analog-to-Digital Converter (ADC) reads voltages
from 0\text{V} to 5\text{V} and translates them into a digital value from 0 to 1023.
3. Conversion Formula: To get the temperature in ^\circ \text{C}, we must perform two
steps:
○ Step 1: Convert ADC Reading to Voltage (mV): (Where 5000 is the 5\text{V}
reference expressed in \text{mV})
○ Step 2: Convert Voltage to Temperature (\mathbf{^\circ C}): (Since the LM35
outputs 10\text{ mV} per ^\circ \text{C})
Components Required
● Arduino UNO Board
● LM35 Temperature Sensor
● Connecting wires
Conclusion
The practical successfully interfaced the LM35 temperature sensor and demonstrated the
conversion of its analog output into precise, human-readable temperature units. The core of the
exercise involved:
1. Using the LM35's linear voltage property (no complex voltage divider needed).
2. Accurately using the Arduino ADC resolution (1024 steps across 5000\text{ mV}) to
calculate the measured voltage.
3. Applying the factor of 10\text{ mV} per \mathbf{^\circ C} to derive the final temperature
reading.
This process is fundamental for any IoT application focused on environmental monitoring and
provides a reliable method for quantitative data acquisition.
🔥 Practical 10: Interface & Program Gas Sensor
(MQ-2) with IoT Board (Arduino)
Aim
To interface an MQ-2 Gas Sensor (sensitive to Methane, Butane, LPG, Smoke, etc.) with an
Arduino UNO board and program it to read both the sensor's analog gas concentration level
and provide a simple digital alert when a dangerous threshold is reached.
Theory
The MQ-2 Gas Sensor is a Metal Oxide Semiconductor (MOS) type sensor used for detecting
combustible gases and smoke.
1. Operation: The sensor has a sensing material whose resistance decreases when it
comes into contact with the target gases. This is due to a chemical reaction that releases
electrons.
2. Output: The MQ-2 module typically provides two outputs:
○ Analog Output (A0): Provides a continuous voltage proportional to the gas
concentration (used for quantitative measurement).
○ Digital Output (D0): Provides a \text{HIGH} or \text{LOW} signal when the gas
concentration crosses a pre-set threshold (adjustable via a potentiometer on the
module, used for quick alerts).
3. Arduino Interface: We will use both outputs:
○ Analog Reading (A0): Connected to an Arduino Analog Pin to read the raw
concentration level (0-1023).
○ Digital Reading (D0): Connected to an Arduino Digital Pin to trigger an immediate
action (like turning on an alarm LED).
Components Required
● Arduino UNO Board
● MQ-2 Gas Sensor Module (must have both \text{A0} and \text{D0} pins)
● LED (for digital alarm indicator)
● 220\text{ }\Omega Resistor (for LED)
● Connecting wires
Conclusion
The practical successfully interfaced the MQ-2 gas sensor and demonstrated a dual-mode
monitoring system.
1. Quantitative Monitoring: The Analog output (\text{A0}) provided a raw concentration
level (0-1023), allowing for fine-grained monitoring and the implementation of a custom
alarm threshold in the code.
2. Binary Safety Alert: The Digital output (\text{D0}) provided a quick, binary
\text{ALARM}/\text{SAFE} status based on the module's pre-set sensitivity, which was
used to control an indicator LED.
This dual approach is valuable in IoT safety systems, providing both an immediate hardware
alert and the raw data necessary for logging and analysis.
🔥 Practical 11: Interface & Programming Fire Sensor
with IoT Board (Arduino)
Aim
To interface an Infrared Flame Sensor with an Arduino UNO board and program a simple
alarm system that provides a digital alert (e.g., turning on an LED and printing a message)
immediately upon detecting the specific infrared (IR) light signature of a flame.
Theory
The Infrared Flame Sensor is designed to detect the presence of fire.
1. Operation: Flames emit a specific wavelength of infrared light (typically around 760
\text{ nm} to 1100 \text{ nm}) that is distinct from normal ambient light. The sensor module
uses an IR phototransistor to detect this specific spectrum.
2. Output: Most flame sensor modules provide two outputs (similar to the MQ-2 gas
sensor):
○ Digital Output (D0): This is the most crucial output for fire detection. It is set to
\text{LOW} (or \text{HIGH}, depending on the module) when the detected IR
intensity crosses a pre-set threshold (adjustable via a potentiometer on the
module). This is used for a quick, binary fire/no-fire alert.
○ Analog Output (A0): Provides a voltage proportional to the IR intensity (used for
distance or intensity measurement, but often less critical than D0).
3. Alarm System: The practical focuses on reading the \text{D0} pin. When the state
changes (indicating fire), the Arduino triggers an actuator, such as an LED or buzzer, to
serve as the local alarm.
Components Required
● Arduino UNO Board
● Infrared Flame Sensor Module (with D0 and A0 pins)
● LED (for alarm indicator)
● Piezo Buzzer (optional, for a louder alarm)
● 220\text{ }\Omega Resistor (for LED)
● Connecting wires
Conclusion
The practical successfully interfaced the Infrared Flame Sensor and implemented a
rapid-response digital alarm system. By monitoring the sensor's Digital Output (\mathbf{D0}),
the Arduino was able to establish a binary state (fire or no fire). The code utilized simple
\text{digitalRead} and \text{digitalWrite} functions to trigger an immediate visual alarm (LED),
demonstrating a fundamental principle of safety-critical IoT systems: swift detection and
actuation based on digital inputs.
📏 Practical 12: Interface & Programming Ultrasonic
Sensor with IoT Board (Arduino)
Aim
To interface the HC-SR04 Ultrasonic Sensor with an Arduino UNO board and program it to
measure the distance to the nearest object in centimeters and output the measurement to the
Serial Monitor.
Theory
The HC-SR04 measures distance using the principle of sonar (Sound Navigation and Ranging).
1. Operation: The sensor has two transducers: a transmitter (Trigger pin) and a receiver
(Echo pin).
○ The Arduino sends a short (\mathbf{10\text{ }\mu\text{s}}) \text{HIGH} pulse to the
Trigger pin.
○ The sensor emits an 8\text{-cycle} burst of 40\text{ kHz} ultrasonic sound
waves.
○ The sound wave travels, hits an object, and bounces back.
○ The sensor's Echo pin goes \text{HIGH} when the sound is emitted and returns
\text{LOW} when the reflected wave is received.
2. Distance Calculation: The Arduino measures the duration of the \text{HIGH} pulse on
the Echo pin, which is the time elapsed between sound transmission and reception.
○ Formula for Distance:
○ Speed of Sound in Air: Approximately 343\text{ m/s} or 0.0343\text{
cm}/\mu\text{s}.
○ Simplified Formula (in cm): Since the time is for a round trip (divided by 2) and
the Arduino measures time in \text{microseconds}, the final formula is: (Where 58 is
derived from 1,000,000 \text{ } \mu\text{s}/\text{second} / (343 \text{ m/s} \times 100
\text{ cm/m}) / 2 \approx 58.12)
Components Required
● Arduino UNO Board
● HC-SR04 Ultrasonic Sensor
● Connecting wires
Conclusion
The practical successfully interfaced the HC-SR04 Ultrasonic Sensor by correctly configuring
the Trigger pin as an output and the Echo pin as an input. The core functionality was achieved
by using the pulseIn() function to accurately measure the time-of-flight of the sound wave. By
applying the specific conversion factor (\mathbf{58}) to the measured duration, the distance to
the object was reliably calculated in centimeters. This demonstrates the use of time-based
measurement principles for proximity sensing, a key function in autonomous and monitoring IoT
systems.
🌱 Practical 13: Interfacing & Programming Moisture
Sensor with IoT Board (Arduino)
Aim
To interface an Analog Soil Moisture Sensor with an Arduino UNO board and program it to
measure the moisture content of the soil and output a processed, human-readable moisture
percentage to the Serial Monitor.
Theory
A Soil Moisture Sensor (capacitive or resistive) measures the water content of the soil. We will
focus on the resistive type for this practical, as it is the most common module with dual
analog/digital outputs.
1. Operation: The sensor probes act as electrodes. When placed in soil:
○ Dry Soil: Has high electrical resistance.
○ Wet Soil: Has low electrical resistance (due to water and dissolved salts).
2. Output & Voltage Divider: The sensor module converts this resistance change into a
voltage that is fed to the Arduino's analog pin.
○ Dry Soil (High Resistance): Results in a low analog output voltage (ADC value
close to 1023 in some modules, or 0 in others, depending on the internal wiring).
For simplicity, we assume low voltage = wet and high voltage = dry for mapping
purposes, which is common.
3. Mapping: The raw 0-1023 ADC reading needs to be mapped to a meaningful range
(e.g., 0-100\%). Since the raw ADC reading is typically inversely proportional to the
moisture, the mapping often involves reversing the range.
Components Required
● Arduino UNO Board
● Analog Soil Moisture Sensor Module (e.g., \text{FC-28} or similar)
● Connecting wires
● Small cup of dry soil and water (for testing)
Conclusion
The practical successfully demonstrated the interface of an analog soil moisture sensor. The
core challenge was overcome by calibrating the sensor by defining boundary values
(DRY_AIR_VALUE and WET_WATER_VALUE) and then using the \text{map()} function to
re-scale the inverse analog voltage reading into a positive, linear moisture percentage. This
allows the Arduino to provide meaningful, actionable data, forming the basis of an automated
irrigation system in an IoT environment.
🚶 Practical 14: Interfacing & Programming PIR
Sensor with IoT Board (Arduino)
Aim
To interface a Passive Infrared (PIR) Motion Sensor with an Arduino UNO board and
program it to act as a security trigger, activating a digital output (LED) and notifying the user
via the Serial Monitor whenever motion is detected.
Theory
The PIR Sensor is a reliable, low-power sensor designed to detect movement based on
changes in infrared radiation (heat) emitted by objects (like humans or animals) in its field of
view.
1. Operation: The sensor has a Fresnel lens that focuses IR energy onto a pyroelectric
sensor. When a warm body moves, the pattern of IR radiation changes rapidly, triggering
the sensor.
2. Output: The PIR sensor is a digital device. Its signal pin provides:
○ \mathbf{\text{LOW}} (0V): No motion detected.
○ \mathbf{\text{HIGH}} (3.3V/5V): Motion detected.
3. Adjustments: Most PIR modules have two potentiometers: one to adjust the sensitivity
(detection range) and one to adjust the delay time (how long the output stays \text{HIGH}
after motion stops).
4. Application: In IoT, PIR sensors are fundamental for smart lighting, security alarms, and
occupancy tracking.
Components Required
● Arduino UNO Board
● HC-SR501 or similar PIR Motion Sensor Module (with three pins: VCC, GND, OUT)
● LED (for alarm indicator)
● 220\text{ }\Omega Resistor (for LED)
● Connecting wires
Conclusion
The practical successfully interfaced the PIR sensor, utilizing its digital output for reliable
motion detection. By employing edge detection logic (lastPirState), the Arduino was able to
accurately distinguish between the start of motion, continuous motion, and the end of motion.
This allowed for clean, non-repetitive messages on the Serial Monitor and effective control of
the alarm LED, proving the PIR sensor's fundamental role in event-driven security and
automation aspects of IoT.
🚶 Practical 14: Interfacing & Programming PIR
Sensor with IoT Board (Arduino)
Aim
To interface a Passive Infrared (PIR) Motion Sensor with an Arduino UNO board and
program it to act as a security trigger, activating a digital output (LED) and notifying the user
via the Serial Monitor whenever motion is detected.
Theory
The PIR Sensor is a reliable, low-power sensor designed to detect movement based on
changes in infrared radiation (heat) emitted by objects (like humans or animals) in its field of
view.
1. Operation: The sensor has a Fresnel lens that focuses IR energy onto a pyroelectric
sensor. When a warm body moves, the pattern of IR radiation changes rapidly, triggering
the sensor.
2. Output: The PIR sensor is a digital device. Its signal pin provides:
○ \mathbf{\text{LOW}} (0V): No motion detected.
○ \mathbf{\text{HIGH}} (3.3V/5V): Motion detected.
3. Adjustments: Most PIR modules have two potentiometers: one to adjust the sensitivity
(detection range) and one to adjust the delay time (how long the output stays \text{HIGH}
after motion stops).
4. Application: In IoT, PIR sensors are fundamental for smart lighting, security alarms, and
occupancy tracking.
Components Required
● Arduino UNO Board
● HC-SR501 or similar PIR Motion Sensor Module (with three pins: VCC, GND, OUT)
● LED (for alarm indicator)
● 220\text{ }\Omega Resistor (for LED)
● Connecting wires
Conclusion
The practical successfully interfaced the PIR sensor, utilizing its digital output for reliable
motion detection. By employing edge detection logic (lastPirState), the Arduino was able to
accurately distinguish between the start of motion, continuous motion, and the end of motion.
This allowed for clean, non-repetitive messages on the Serial Monitor and effective control of
the alarm LED, proving the PIR sensor's fundamental role in event-driven security and
automation aspects of IoT.