Ex. No.
: 01
Object Detection Using IR Sensor and Buzzer
Date :
AIM:
To design and implement an object detection system using an IR sensor
interfaced with Arduino Mega such that a buzzer is activated whenever an
object is detected.
APPARATUS / COMPONENTS REQUIRED:
1. Arduino Mega
2. IR Obstacle Sensor Module
3. Buzzer
4. Connecting Wires
5. Breadboard
6. USB Cable
7. Arduino IDE.
THEORY:
An Infrared (IR) sensor consists of an IR transmitter (LED) and an IR
receiver (photodiode). When an object comes in front of the sensor, the IR rays
emitted by the transmitter are reflected back and detected by the receiver.
The IR sensor provides a digital output:
LOW (0) → Object detected
HIGH (1) → No object detected
The Arduino continuously monitors the sensor output. When an object is
detected, the Arduino sends a HIGH signal to the buzzer, causing it to sound
an alarm.
This system is commonly used in:
Security systems
Obstacle detection
Automatic doors
Robotics
Programs:
int irSensorPin = 2; // IR sensor output pin
int buzzerPin = 8; // Buzzer pin
void setup() {
pinMode(irSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
[Link](9600);
}
void loop() {
int sensorValue = digitalRead(irSensorPin);
if (sensorValue == LOW)
{
digitalWrite(buzzerPin, HIGH);
[Link]("Object Detected");
}
else {
digitalWrite(buzzerPin, LOW);
[Link]("No Object Detected");
}
delay(200);
}
RESULT:
Thus, the object detection system using an IR sensor and Arduino Mega was
implemented successfully. The buzzer alert mechanism worked properly
whenever an object was detected. This system can be used in security alarms,
obstacle detection, automatic door systems, and industrial monitoring
applications.
Ex. No.: 02
Implementation of AND Logic Gate Using Two Push Buttons
Date :
AIM:
To read digital data using two push buttons and verify the operation of an
different logic gate using Arduino.
APPARATUS / COMPONENTS REQUIRED:
1. Arduino Mega
2. Two Push Buttons
3. LED
4. 220Ω Resistor (for LED)
5. Breadboard
6. Connecting Wires
7. USB Cable
8. Arduino IDE Software
THEORY:
Basic logic gates are the fundamental building blocks of digital
electronics. They perform logical operations on one or more binary inputs and
produce a binary output. The inputs and outputs are represented by two states:
0 (LOW) and 1 (HIGH).
The common basic logic gates are:
AND Gate: Produces HIGH output only when all inputs are HIGH.
OR Gate: Produces HIGH output when at least one input is HIGH.
NOT Gate: Produces the opposite of the input.
Other derived logic gates include:
NAND Gate: Opposite of the AND gate.
NOR Gate: Opposite of the OR gate.
Programs:
int button1 = 2; // Push button 1
int button2 = 3; // Push button 2
int ledPin = 50; // Output LED
void setup() {
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
void loop() {
int b1 = digitalRead(button1);
int b2 = digitalRead(button2);
// AND Gate Logic
if (b1 == LOW && b2 == LOW) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
XOR Gate: Produces HIGH output when the inputs are different.
XNOR Gate: Produces HIGH output when the inputs are the same.
These gates are used in digital circuits, microprocessors, communication
systems, control systems, and Arduino-based projects to make decisions based
on input conditions.
RESULT:
The experiment was performed successfully. The required logic gate operation
was verified using Arduino, where the output became HIGH only for the
specified input condition. Thus, the experiment confirmed the working of basic
logic gates using digital inputs and outputs.
Ex. No.: 03
Automatic Street Light Control Using LDR Sensor
Date :
AIM:
To design and implement an automatic street light system using an LDR sensor
and Arduino such that the light turns ON at night and OFF during daytime
automatically.
APPARATUS / COMPONENTS REQUIRED:
1. Arduino Mega
2. LDR (Light Dependent Resistor)
3. 10 kΩ Resistor
4. LED (representing street light)
5. 220 Ω Resistor
6. Breadboard
7. Connecting Wires
8. USB Cable
9. Arduino IDE Software
THEORY:
An LDR (Light Dependent Resistor) is a sensor whose resistance changes with
the intensity of light falling on it:
• Bright light: LDR resistance is low
• Darkness / night: LDR resistance is high
By connecting the LDR in a voltage divider configuration to an Arduino analog
pin, the analog voltage varies according to light intensity.
Arduino reads this analog value and turns an LED ON or OFF based on a pre-
set threshold, simulating an automatic street light.
Applications:
• Street lights
• Garden lights
• Smart home lighting
Programs:
int ldrPin = A0; // LDR connected to analog pin A0
int ledPin = 8; // LED representing street light
int ldrValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
[Link](9600); // For monitoring LDR values
void loop() {
ldrValue = analogRead(ldrPin); // Read LDR analog value
[Link](ldrValue);
if (ldrValue < 500) { // Darkness threshold
digitalWrite(ledPin, HIGH); // LED ON
} else {
digitalWrite(ledPin, LOW); // LED OFF
delay(500); // Delay to avoid flickering
RESULT:
The automatic street light system was implemented successfully using an LDR
sensor and Arduino. The light turned ON automatically in low-light conditions
and turned OFF during daytime. Thus, the system worked correctly and can
help save electrical energy.
Ex. No.: 04
Body Temperature Measurement Using DHT11 Sensor
Date :
AIM:
To measure human body temperature using a DHT11 temperature sensor
interfaced with Arduino and display the value on the Serial Monitor.
APPARATUS / COMPONENTS REQUIRED:
1. Arduino Mega
2. DHT11 Temperature Sensor (Module)
3. 10 kΩ Resistor (if using bare sensor)
4. Breadboard
5. Connecting Wires
6. USB Cable
7. Arduino IDE Software
THEORY:
The DHT11 sensor is a low-cost digital temperature and humidity sensor.
It contains:
• A thermistor for temperature sensing
• A humidity sensor
• An internal ADC and digital communication unit
The DHT11 sends digital temperature data to Arduino using a single-wire
protocol.
Arduino processes this data and displays the temperature value in degrees
Celsius (°C).
Programs:
#include <DHT.h>
#define DHTPIN 2 // DHT11 data pin
#define DHTTYPE DHT11 // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
[Link](9600);
[Link]();
}
void loop() {
float temperature = [Link](); // Celsius
if (isnan(temperature)) {
[Link]("Failed to read from DHT11 sensor!");
return;
}
[Link]("Body Temperature: ");
[Link](temperature);
[Link](" °C");
delay(2000); // Mandatory delay
}
RESULT:
The body temperature measurement system using the DHT11 sensor and
Arduino was implemented successfully. The temperature value was measured
accurately and displayed on the Serial Monitor. Thus, the system can be used
for simple temperature monitoring applications.
Ex. No.: 05 Soil Moisture Measurement Using Arduino (2 Pin Soil
Date : Moisture Sensor)
AIM:
To measure the moisture content of soil using a 2 pin soil moisture sensor
interfaced with Arduino and to display the soil condition (WET, MOIST, or DRY)
on the Serial Monitor.
APPARATUS / COMPONENTS REQUIRED:
1. Arduino Mega
2. Soil Moisture Sensor
6. Breadboard
7. Connecting Wires
8. USB Cable
9. Arduino IDE Software
THEORY:
Soil moisture measurement is an important parameter in agriculture, irrigation
systems, and environmental monitoring. The 2 pin soil moisture sensor works
on the principle of electrical resistance.
• Wet soil conducts electricity better → low resistance → low analog value
• Dry soil conducts poorly → high resistance → high analog value
The sensor provides an analog voltage output, which is read by the Arduino
using its Analog to Digital Converter (ADC). The Arduino converts this voltage
into a digital value between 0 and 1023.
Based on predefined threshold values, the soil condition is classified as:
• WET
• MOIST
• DRY
Programs:
int soilPin = A0; // Analog pin connected to soil sensor
int soilValue = 0;
void setup() {
[Link](9600); // Initialize serial communication
}
void loop() {
soilValue = analogRead(soilPin); // Read soil moisture value
[Link]("Soil Moisture Value: ");
[Link](soilValue);
// Interpretation
if (soilValue < 400) {
[Link]("Status: WET Soil");
}
else if (soilValue >= 400 && soilValue < 700) {
[Link]("Status: MOIST Soil");
}
else {
[Link]("Status: DRY Soil");
}
delay(1000); // 1 second delay
}
RESULT:
The automatic street light system was implemented successfully using an LDR
sensor and Arduino. The light turned ON automatically in low-light conditions
and turned OFF during daytime. Thus, the system worked correctly and can
help save electrical energy.