Experiment - 1: Download The File From The Link Given Below
Experiment - 1: Download The File From The Link Given Below
Experiment - 1: Download The File From The Link Given Below
Experiment – 1
Aim – To install all the tools or Software required for Sensor Theory &
Application’s Lab.
Software Required –
Arduino IDE
Installation of Arduino IDE on Windows 11 –
Step 1: Download the file from the link given below.
Windows MSI installer (arduino.cc)
Step 2: Open the file by double clicking on it, it automatically installs the
Arduino IDE and create a Desktop shortcut.
1|Pa g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Step 4: Open the Arduino IDE by double clicking and install the
required libraries .
The Arduino IDE is installed now and you can use to run your codes.
2|Pa g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT-4
Aim: To study the about Touch Sensor and its technical specifications.
Theory:
A touch sensor is a type of device that captures and records physical touch or embrace on a
device and/or object. It enables a device or object to detect touch or near proximity, typically by
a human user or operator. Touch sensing input devices offer numerous possibilities for novel
interaction techniques and it reliably replaces mechanical buttons and switches to eliminate
mechanical wear and tear. These can be configured into simple sliders, rotary wheels, or touch
pads for intuitive user interfaces.
A touch sensor primarily works when an object or individual gets in physical contact with it.
Touch sensors are also called as tactile sensors and are sensitive to touch, force or pressure. It
can be implemented using Capacitive or Resistive sensing technology.
20 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Principles of operation:
1. Capacitive Touch sensors: These sensors detect touch based on changes in capacitance.
When an object with capacitance (such as a finger) approaches the sensor surface, it
alters the capacitance, which is then detected by the sensor. Capacitive sensors are
widely used in smartphones, tablets, and touch-sensitive interfaces.
3. Infrared Touch Sensors: Infrared sensors emit infrared light beams across the surface.
When an object touches the screen, it interrupts these beams, and the interruption is
detected to determine the touch location.
Types of Touch Sensors:
a. Single-Touch vs. Multi-Touch: Single-touch sensors can detect only one point of
contact at a time, whereas multi-touch sensors can detect multiple points simultaneously,
enabling gestures like pinch-to-zoom.
b. Surface vs. Projected Capacitive: Surface capacitive touch sensors are suitable for flat
surfaces and are commonly used in devices like kiosks and ATMs. Projected capacitive
touch sensors can detect touches through non-conductive materials like glass, making
them ideal for smartphones and tablets.
c. Analog vs. Digital: Analog touch sensors provide continuous data about touch pressure
or position, while digital touch sensors provide discrete outputs indicating touch/no -
touch events.
Technical Specifications:
21 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Specifications:
• Operating voltage - 2.0V~5.5V
• Operating temperature: -40 to 80 °C
• Operating current @VDD=3V, no load
• Input Voltage: GND-0.3 ~ VCC+0.3 V
• At low power mode typical 1.5uA, maximum 3.0uA
• The response time max - 220mS
• At low power mode @VDD=3V
• Sensitivity can adjust by the capacitance(0~50pF) outside.
• Stable touching detection of human body for replacing traditional direct switch key.
• Provides Low Power mode.
• Output pin sink current – 8 mA.
• Output pin pull-up current – 4 mA.
• Dimensions – 3 x 2 x 1 cm
• Weight – 5 grams
• All output modes can be selected active high or active low by pad option (AHLB pin)
• Auto calibration for life
On the basis of applications:-
1. Smartphones and Tablets:
Touch Type: Capacitve.
Dimensions: Customized to device size.
Touch Resolution: High (e.g., 1080p or higher).
Touch Accuracy: Very high (sub-millimetre precision).
Multi-Touch Support: Essential for pinch-to-zoom and multi-finger gestures.
Touch Response Time: Low (typically milliseconds).
Durability: Scratch-resistant, impact-resistant.
Environmental Conditions: Operating temperature range of -10°C to 40°C, high
22 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
humidity tolerance.
Interface: Directly integrated into device's touchscreen controller.
Power Consumption: Low to conserve battery life.
Controller Compability: Optimized for specific touch controller chips used in
smartphones and tablets.
23 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT-5(A)
Aim: To measure the temperature using LM-35 and find out the reference room temperature.
Software: Arduino IDE
Hardware Board: Arduino Uno
Components Required:
• Arduino board
• LM35 sensor
• Bread board
• Jumper wires
Theory:
LM35 is a temperature sensor which can measure temperature in the range of -55°C to 150°C.
It is a 3-terminal device that provides analog voltage proportional to the temperature. Higher
the temperature, higher is the output voltage.
The sensitivity of LM35 is 10 mV/degree Celsius. As temperature increases, output voltage also
increases.
E.g. 250 mV means 25°C.
The output analog voltage can be converted to digital form using ADC so that a microcontroller
can process it.
LM 35 shows high voltage values than thermocouples and may not need the output voltage to
be amplified. The output voltage of LM35 is proportional to the Celsius temperature. The
temperature is calculated by formula, temperature= output voltage (in mv) /10 mv/ o C.
Specifications:
• Operating Voltage: 4 V to 30 V
• Output Voltage: 10mV/°C
• Sensitivity: 10mV/°C
• Linearity Error: ±1°C (for 0°C to +100°C)
• Operating Temperature: -55°C to +150°C
• Output Impedance: 100 Ω
• Power Consumption: 60 μA (typical)
• Package Type: TO-92, TO-220, SOIC
• Output Type: Analog
24 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
• Accuracy: ±1°C (typical)
Working Principle:
LM35 is the sensor that senses the temperature of its environment and based on it's value it
generates an analog output voltage. This analog voltage produced by the LM35 is then given as
input to the Bolt A0 pin. The Bolt then converts the analog value into a 10 bit digital value that
varies from 0-1023.
The LM35 temperature sensor uses the basic principle of a diode to measure known
temperature value. As we all know from semiconductor physics, as the temperature
increases the voltage across a diode increases at a known rate. By accurately amplifying the
voltage change, we can easily generate a voltage signal that is directly proportional to the
surrounding temperature.
Circuit Diagram:
The sensor can be powered from 5V. The positive voltage connects to ‘+Vs’ and ground
connects to ‘GND‘. The middle pin ‘Vout’ is the analog signal output from the sensor and
connects to the A0 analog input of an Arduino.
25 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:
const int lm35_pin = A1; /* LM35 O/P pin */
void setup() {
Serial.begin(9600);
}
void loop() {
int temp_adc_val;
float temp_val;
temp_adc_val = analogRead(lm35_pin); // Read Temperature
temp_val = (temp_adc_val * 4.88); // Convert adc value to vc
temp_val = (temp_val/10); // LM35 gives output of 10mv/°C
Serial.print("Temperature = ");
Serial.print(temp_val);
Serial.print(" Degree Celsius\n");
delay(1000);
}
26 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Experiment – 5(B)
Aim – To develop a temperature-controlled LED system using an Arduino board and a
temperature sensor (LM 35).
Apparatus Required:
Arduino Uno Board
Bread Board
Jumper Wires
LED’s
Temperature Sensor (LM 35)
Resistors
Software Required:
Arduino IDE
Circuit Diagram:
27 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Theory:
The LM35, developed and produced by Texas Instruments, is a low-power, cost-effective
temperature sensor known for its high precision. This IC delivers a voltage output linearly
corresponding to temperature changes. With a sturdy construction, the LM35 is suitable for
diverse environmental conditions, eliminating the need for external calibration components. It
boasts a typical accuracy of ±0.5°C at room temperature and ±1°C across a broad −55°C to
+155°C temperature range. Operating on a voltage range of 4V to 30V, it consumes a mere 60
µA during operation, making it ideal for battery-powered applications.
Despite its merits, the LM35 has two notable drawbacks. Firstly, it cannot measure negative
temperatures without biasing it with a dual-polarity supply. In such cases, the LM36 sensor can
be considered. Secondly, due to its analog data output, the LM35 is sensitive to noise.
28 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
The LM35 functions as a temperature sensor, providing an analog signal proportionate to the
instantaneous temperature, easily interpretable for Celsius readings. Its advantages over
thermistors include not requiring external calibration and being protected from self-heating by its
coating. The low cost (approximately $0.95) and high accuracy have made it popular among
hobbyists, DIY circuit makers, and students. Despite being around for over 15 years since its
initial release, the LM35 continues to be widely used in various products.
Capable of measuring temperatures from -55 degrees Celsius to 150 degrees Celsius, the LM35
achieves high accuracy under optimal temperature and humidity conditions. The conversion of
its output voltage to centigrade is straightforward.
Operating on input voltages ranging from +4 volts to 30 volts, the LM35 draws about 60
microamperes of current. The LM35 family includes various members such as LM35C,
LM35CA, LM35D, LM135, LM135A, LM235, and LM335. While these family members work
on the same principles, their temperature measuring capacities vary, and they are available in
different packages (SOIC, TO-220, TO-92, TO).
Connecting the LM35 sensor to the Arduino is simple. You just need to connect 5V power to the
sensor and you need to connect the output of the sensor to the A0 pin of the Arduino. Once the
connection is done you need to write the code to convert the output voltage of the sensor to
temperature data. Now connect the anode of LED with digital Pin 8 and the cathode with a resister
and the other end of resistor to the Ground pin on to the Arduino Board. After that, first, you need
to convert the ADC values to voltage and multiply that voltage to 10 and you will get the output
in temperature. With that, you’re now ready to upload the code to Arduino.
Code –
#define sensor_pin A0
#define led_pin 8
void setup() {
Serial.begin(9600);
pinMode(sensor_pin, INPUT);
pinMode(led_pin, OUTPUT);
}
void loop() {
int adcData = analogRead(sensor_pin);
29 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("*C");
delay(800);
}
Output –
Result –
Therefore, we have successfully develop a temperature-controlled LED system using an
Arduino board and a temperature sensor (LM 35).
30 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT-6(A)
Aim: To measure the intensity of light using an LDR and Arduino Uno R3.
Apparatus Required:
1. Arduino Uno R3 board
2. LDR (Light Dependent Resistor)
3. Resistor (10k ohms)
4. Breadboard
5. Jumper wires
6. Power source (USB cable or battery)
Theory:
An LDR, or Light Dependent Resistor, belongs to a class of semiconductors whose resistance
varies in response to incident light. Composed of a photoconductive material, typically
cadmium sulfide (CdS) or lead sulfide (PbS), LDRs exhibit higher resistance in darkness due to
minimal photon excitation. When illuminated, photons energize the semiconductor's valence
electrons, reducing the band gap and allowing more current flow, thus lowering the resistance.
This unique property renders LDRs ideal for light sensing applications, including ambient light
detection, dusk-to-dawn switches, and camera exposure control. Their spectral response,
operating temperature range, and dynamic resistance characteristics vary based on material
composition and manufacturing processes. Through voltage divider configurations, LDRs can
translate light intensity into measurable electrical signals, facilitating their integration with
microcontrollers for light-dependent control systems.
Specification:
• Maximum power dissipation is 200mW
• The maximum voltage at 0 lux is 200V
• The peak wavelength is 600nm
• Minimum resistance at 10lux is 1.8kΩ
• Maximum resistance at 10lux is 4.5kΩ
• Typical resistance at 100lux is 0.7kΩ
• Dark resistance after 1 sec is 0.03MΩ
• Dark resistance after 5 sec is 0.25MΩ
31 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Working Principle: The operation of the LDR-based light sensor revolves around the variable
resistance of the LDR in response to incident light. When exposed to light, photons excite
electrons within the semiconductor material of the LDR, reducing its resistance. Conversely, in
darkness, the absence of photons leads to higher resistance.
In this experiment, the LDR is connected to the Arduino Uno R3 in a voltage divider
configuration. As the resistance of the LDR changes with light intensity, the voltage across it
also varies. By measuring this voltage using the analog-to-digital converter (ADC) of the
Arduino, we can infer the light intensity.
Circuit Diagram:
Code:
const int ldrPin = A0; // LDR connected to analog pin A0
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value (0-1023)
32 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
// Convert LDR value to resistance (adjust the parameters accordingly)
float resistance = (float)(1023 - ldrValue) * 10 / ldrValue;
Result: Upon running the experiment, the Arduino Uno R3 reads the analog voltage from the
LDR and calculates the corresponding resistance. This resistance value is then displayed on the
serial monitor. As the intensity of light changes, the resistance of the LDR will vary, thus
providing a measure of light intensity in ohms.
Light Intensity in room is 600 lux.
EXPERIMENT-6(B)
Aim: To automatically turn on an LED when the light intensity in the room drops below a
certain level using an LDR and Arduino Uno R3.
33 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Apparatus Required:
1. Arduino Uno R3 board
2. LED (Light Emitting Diode)
3. LDR (Light Dependent Resistor)
4. Resistor (220-330 ohms)
5. Breadboard
6. Jumper wires
7. Power source (USB cable or battery)
Theory:
An LDR, or Light Dependent Resistor, belongs to a class of semiconductors whose resistance
varies in response to incident light. Composed of a photoconductive material, typically
cadmium sulfide (CdS) or lead sulfide (PbS), LDRs exhibit higher resistance in darkness due to
minimal photon excitation. When illuminated, photons energize the semiconductor's valence
electrons, reducing the band gap and allowing more current flow, thus lowering the resistance.
This unique property renders LDRs ideal for light sensing applications, including ambient light
detection, dusk-to-dawn switches, and camera exposure control. Their spectral response,
operating temperature range, and dynamic resistance characteristics vary based on material
composition and manufacturing processes. Through voltage divider configurations, LDRs can
translate light intensity into measurable electrical signals, facilitating their integration with
microcontrollers for light-dependent control systems.
Specification:
• Maximum power dissipation is 200mW
• The maximum voltage at 0 lux is 200V
• The peak wavelength is 600nm
• Minimum resistance at 10lux is 1.8kΩ
• Maximum resistance at 10lux is 4.5kΩ
• Typical resistance at 100lux is 0.7kΩ
• Dark resistance after 1 sec is 0.03MΩ
• Dark resistance after 5 sec is 0.25MΩ
34 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Working Principle: The Arduino continuously reads the analog voltage from the LDR. Based
on the voltage value, the Arduino calculates the corresponding resistance of the LDR. If the
resistance surpasses a predefined threshold, indicating low light intensity, the Arduino activates
the LED by setting the corresponding digital pin to HIGH, thereby turning on the LED. This
process ensures that the LED is automatically turned on when the light intensity in the room
drops below the specified level.
Circuit Diagram:
Code:
const int ldrPin = A0; // LDR connected to analog pin A0
const int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value (0-1023)
35 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
// Check if it's dark (adjust threshold as needed)
if (ldrValue < 500) {
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
}
Result: Upon running the experiment, the Arduino Uno R3 continuously monitors the ambient
light intensity using the LDR. When the light intensity in the room drops below the predefined
threshold (500 in this case), indicating darkness, the Arduino activates the LED, providing
illumination. Conversely, when the light intensity increases above the threshold, the Arduino
turns off the LED, ensuring efficient energy usage and automatic lighting control based on
ambient light conditions. Adjust the threshold value (500 in this case) as needed for your
specific application.
36 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT-6(C)
Aim: To create a light-dependent LED system that turns on two LEDs when the light intensity
in the room drops below a certain level and activates another two LEDs when the light intensity
rises above a certain level. Additionally, when the intensity level changes, all four LEDs will
blink three times, signaling the transition, before returning to the initial state.
Apparatus Required:
1. Arduino Uno R3 board
2. LDR (Light Dependent Resistor)
3. Four LEDs (Light Emitting Diodes)
4. Resistors (220-330 ohms)
5. Breadboard
6. Jumper wires
7. Power source (USB cable or battery)
Theory:
An LDR, or Light Dependent Resistor, belongs to a class of semiconductors whose resistance
varies in response to incident light. Composed of a photoconductive material, typically
cadmium sulfide (CdS) or lead sulfide (PbS), LDRs exhibit higher resistance in darkness due to
minimal photon excitation. When illuminated, photons energize the semiconductor's valence
electrons, reducing the band gap and allowing more current flow, thus lowering the resistance.
This unique property renders LDRs ideal for light sensing applications, including ambient light
detection, dusk-to-dawn switches, and camera exposure control. Their spectral response,
operating temperature range, and dynamic resistance characteristics vary based on material
composition and manufacturing processes. Through voltage divider configurations, LDRs can
translate light intensity into measurable electrical signals, facilitating their integration with
microcontrollers for light-dependent control systems.
Specification:
• Maximum power dissipation is 200mW
• The maximum voltage at 0 lux is 200V
• The peak wavelength is 600nm
• Minimum resistance at 10lux is 1.8kΩ
37 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
• Maximum resistance at 10lux is 4.5kΩ
• Typical resistance at 100lux is 0.7kΩ
• Dark resistance after 1 sec is 0.03MΩ
• Dark resistance after 5 sec is 0.25MΩ
Circuit Diagram:
Code:
// Define LDR pin
const int ldrPin = A0;
38 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
void setup() {
// Set LED pins as output
pinMode(ledAbove1, OUTPUT);
pinMode(ledAbove2, OUTPUT);
pinMode(ledBelow1, OUTPUT);
pinMode(ledBelow2, OUTPUT);
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read LDR value (0-1023)
// If intensity level changes, blink all LEDs and reset to initial position
if (currentIntensityLevel != previousIntensityLevel) {
blinkAllLEDs(); // Blink all LEDs
previousIntensityLevel = currentIntensityLevel; // Update previous intensity level
}
EXPERIMENT-7
Aim: To study about PIR sensor and its technical specifications and blink led upon detecting
motion.
Theory:
PIR (passive infrared) sensors utilise the detection of infrared that is radiated from all objects
that emit heat. This type of emission is not visible to the human eye, but sensors that operate
using infrared wavelengths can detect such activity. They are sometimes referred to as ‘motion-
41 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
based detectors’, as they sense the presence of people, animals and objects through the
movement of their infrared wavelengths.
They are referred to as “passive” due to the fact that no heat or energy is emitted by the sensor
itself. It is also important to remember that PIR sensors detect the emission of infrared
radiation, and not heat.
The HC-SR501 PIR Motion Sensor is a highly versatile and widely used device in the world of
electronics and home automation. It is a passive infrared sensor that is designed to detect
motion by measuring changes in infrared (heat) radiation levels within its field of view. When a
person or object moves within its range, the sensor will trigger an output signal, which can be
used to control various devices and systems.
The HC-SR501 is simple to use and requires only a few wires to connect to a microcontroller,
such as an Arduino or Raspberry Pi. It is also highly adjustable, with potentiometers that allow
users to adjust its sensitivity, trigger time, and LED indication. This makes it a great choice for
a wide range of projects, including security systems, light automation, and robotics.
42 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
1 Vcc Input voltage is +5V for typical applications. Can range from
4.5V- 12V
Features:
Technical Specifications:
• Wide range on input voltage varying from 4.V to 12V (+5V recommended)
• Output voltage is High/Low (3.3V TTL)
• Can distinguish between object movement and human movement
• Has to operating modes - Repeatable(H) and Non- Repeatable(H)
• Cover distance of about 120° and 7 meters
• Low power consumption of 65mA
• Operating temperature from -20° to +80° Celsius
• Distance Measuring Range (cm) from 300 to 700
• Dimensions (mm) LxWxH 32 x 24 x 18
• Detection Angle less than 140°
Working of PIR Motion Sensor
The PIR sensor module can be powered from voltage 4.5V to 20V but, typically 5V is used.
Once the module is powered allow the module to calibrate itself for few minutes, 2 minutes is a
well settled time. Then observe the output on the output pin. Before we analyse the output we
43 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
need to know that there are two operating modes in this sensor such as Repeatable(H) and Non -
Repeatable(L) and mode. The Repeatable mode is the default mode.
The output of the sensor can be set by shorting any two pins on the left of the module as shown
below. You can also notice two orange colour potentiometers that can be used to set the
sensitivity and time which will be explained further below.
Repeatable(H) mode
In Repeatable (H) mode the output pin Dout will go high (3.3V) when a person is detected
within range and goes low after a particular time (time is set by “Off time control”
potentiometer). In this mode the output pin will go high irrespective of whether the person is
still present inside the range or has left the area. The sensitivity can be set using the “sensitivity
control” potentiometer
Non- Repeatable(L) mode
In “I” mode the output pin Dout will go high (3.3V) when a person is detected within range
and will stay high as long as he/she stays within the limit of the Sensors range. Once the person
has left the area the pin will go low after the particular time which can be set using the
potentiometer. The sensitivity can be set using the “sensitivity control” potentiometer
There are two important materials present in the sensor one is the pyroelectric crystal which can
detect the heat signatures from a living organism (humans/animals) and the other is a Fresnel
44 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
lenses which can widen the range of the sensor. Yes the white colour things is just a lense that is
used to widen the range of the sensor, if you remove the lense you can find the Pyroelectric
sensor inside it covered inside a protective metal casing as shown above.
PIR Sensor Applications:
• Automatic Street/Garage/Warehouse or Garden Lights
• Burglar Alarms
• Security cams as motion detectors
• Industrial Automation Control
Circuit Diagram:
CODE:
#define motion_sensor A6
#define relay 5
void setup() {
Serial.begin(9600);
pinMode(motion_sensor, INPUT);
pinMode(relay, OUTPUT);
}
void loop() {
int sensor_value = analogRead(A6);
Serial.println(analogRead(A6));
45 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
if (sensor_value > 300) {
Serial.printIn("Motion detected; lights turned on");
digitalWrite(relay, HIGH)
:
}
Else {
Serial.printIn("Motion not detected\n");
digitalWrite(relay, LOW);
}
}
46 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT – 8
Aim: To study about Home Automation and LPG, Smoke and Fire Sensor.
Software: Arduino IDE
Hardware Board: Arduino Uno
Apparatus Required:
Home Automation Kit
MQ6 LPG Sensor
MQ2 Smoke Sensor
MQ6 Fire Sensor
Power source (USB cable or battery)
Theory:
Home automation refers to the integration of smart technologies into residential settings to
automate and control various aspects of the home environment. This includes lighting, heating,
ventilation, air conditioning (HVAC), security systems, entertainment systems, and more. Using
sensors, actuators, and internet connectivity, homeowners can remotely monitor and manage their
homes from anywhere with an internet connection, using smartphones, tablets, or computers.
One of the key benefits of home automation is increased convenience and efficiency. With
automated systems, tasks such as adjusting the thermostat, turning lights on and off, or even
locking doors can be done automatically or with simple voice commands, saving time and effort
for homeowners. Additionally, automation can lead to energy savings by optimizing the use of
utilities and reducing unnecessary consumption.
Moreover, home automation enhances safety and security. Smart security cameras, motion
sensors, and door/window sensors can alert homeowners to potential intruders or hazards, while
smart locks and surveillance systems offer remote access and monitoring capabilities. By
providing real-time alerts and the ability to respond promptly to emergencies, home automation
helps homeowners protect their property and loved ones, offering peace of mind even when they
are away from home.
47 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:
49 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
pinMode(LPG_sensor, INPUT);
pinMode(ROOM_LIGHT, OUTPUT);
}
void loop() {
int lpg = analogRead(A0);
float analog_value1 = lpg * (5.0 / 1023.0);
Serial.println("LPG concentration in air is");
float converted_value = (analog_value1 * 1000);
Serial.println(converted_value);
delay(2000);
if (converted_value > 3000) {
digitalWrite(ROOM_LIGHT, LOW);
digitalWrite(HORN, HIGH);
} else {
digitalWrite(ROOM_LIGHT, HIGH);
digitalWrite(HORN, LOW);
}
}
Description:
Step 1:- Connect a DIN connector from DIN port "B" of Scientech 6205SSG to DIN port "B"
of Scientech 6205SB (for Smoke sensor).
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_8_relay_lights.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.
51 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:
void setup() {
//configure sensor pin as input and lights as output
pinMode(smoke, INPUT);
pinMode(lights, OUTPUT);
Serial.begin(9600); //set baud rate
}
void loop() {
int Sensor = analogRead(A2); //read smoke sensor
Serial.println(Sensor); //print value of sensor
if (Sensor >= 300) {
digitalWrite(lights, HIGH);
Serial.println("Smoke detected"); //if value of sensor is above 250 lights are tuned on
and message is displayed on serial monitor
} else {
digitalWrite(lights, LOW); //if value of smoke sensor is below 400 lights are not turned
on
}
delay(2500);
}
52 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
MQ-2 Features
• Photosensitivity is high.
• Response time is fast.
• Simple to use.
• Sensitivity is adjustable
• Detection angle is 600,
• It is responsive to the flame range.
• Accuracy can be adjustable
• Operating voltage of this sensor is 3.3V to 5V
• Analog voltage o/ps and digital switch o/ps
• The PCB size is 3cm X 1.6cm
• Power indicator & digital switch o/p indicator
• If the flame intensity is lighter within 0.8m then the flame test can be activated, if the
flame intensity is high, then the detection of distance will be improved.
Description:
Step 1:- Connect a DIN connector from DIN port "E" of Scientech 6205SSG to DIN port "C"
of Scientech 6205SB (for Smoke sensor).
Step 2:- Connect a patch chord from pin 1 to buzzer pin of Scientech 6205 SSG.
Step 3:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 4:- Open code Assignment_9_fire_horn.ino
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.
53 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:
void setup() {
//configure sensor pin as input and lights and horn as output
pinMode(fire, INPUT);
pinMode(lights, OUTPUT);
pinMode(alarm, OUTPUT);
Serial.begin(9600); //set baud rate
}
void loop() {
int Sensor = digitalRead(A8); //read Fire sensor
Serial.println(Sensor);
if (Sensor == 1) {
digitalWrite(lights, HIGH); //if fire sensor sends a high , turn on the lights
digitalWrite(alarm, LOW); //if fire sensor sends a high , turn on the horn
Serial.println("everything is fine"); //print message
} else {
digitalWrite(lights, LOW); //if fire sensor sends a low turn off lights
digitalWrite(alarm, HIGH); //if fire sensor sends a low turn off horn
Serial.println("FIRE detected"); //print mesage
}
delay(2000);
}
54 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
EXPERIMENT - 9
Aim: To study about Home Automation and PIR, Temperature and CO 2 Sensor.
Software: Arduino IDE
Hardware Board: Arduino Uno
Apparatus Required:
Home Automation Kit
PIR Sensor
LM 35 (Temperature Sensor)
MQ2 Gas Sensor
Power source (USB cable or battery)
Theory:
55 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Code:
#define motion_sensor A6
#define relay 5 //define pin on which motion sensor is connected
56 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
void setup() {
Serial.begin(9600); //setting baud rate
pinMode(motion_sensor, INPUT); //setting motion sensor pin as a input
pinMode(relay, OUTPUT);
}
void loop() {
int sensor_value = analogRead(A6); //reading the digital value from
Serial.println(analogRead(A6));
if (sensor_value > 300) //condition
{
Serial.println("Motion detected; lights turned on");
digitalWrite(relay, HIGH);
} else {
Serial.println("Motion not detected\n");
digitalWrite(relay, LOW);
}
}
57 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Temperature Sensor(LM-35) Specifications
• Range-55°-150°C
• Accuracy < 0,1°C + NTC-spread over 0°...70°C
• Resolution 2 m°C@30°C and 25 m°C@100°C
• No. Sensors1....30
• Type 5 kOhm NTC-resistors
• Max. wire resistance 3,3 Ohm
• Conditioner Wheatstone-bridge with +15 Bits ADC
• Calibration at 0°C and 100°C _ 0,1°C
• Drift 1 m°C/°C with periodic calibration and 5 m°C/°C without calibration
• Scan freq. default max. 10 meas./s
• Amb.temp 0°...60°
• Control Micro-WireTM 5 (Di, Do, Clk en CS)
• Levels 0 and 5 Volt
• Power+12 Volt 3,5 mAmp (+5,5 .... +20 Volt)
• -5 Volt 1 mAmp (-4,5 ....-8 Volt)
• Dimensions 224 x 120 x 60 + 40 mm
Description:
Step 1:- Connect a DIN connector from DIN port "C" of Scientech 6205SSG to DIN port "E"
of Scientech 6205SB.
58 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Step 2:- Switch on the power button of Scientech 6205 SSG and Scientech 6205 SB and
connect USB cable on Scientech 6205SSG
Step 3:- Open code Assignment_temperature_humidity.ino
Step 4:- Select Board Arduino mega from "Tools->Board -> Arduino mega".
Step 5:- Select the COM-port from "Tools->Port -> .
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.
Code:
void setup() {
pinMode(led, OUTPUT);
pinMode(SensorPin, INPUT);
Serial.begin(9600);
}
void loop() {
int reading = analogRead(sensorPin);
float voltage = reading * (5.0 / 1024.0);
float tempc = (tempc * 1.8) + 32;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
3) CO2 Sensor
CO2 sensor definition is an instrument that is used to detect the CO2 gas content in the air, or its
surroundings is known as a carbon dioxide sensor. Once the instrument detects the CO2 gas
content then it generates an alarm so that appropriate action can be taken by the people. This type
59 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
of sensor plays an essential role in making a good atmospheric situation for the public. The
application areas of CO2 sensors mainly include different industries like carbonated beverage
beer, coal, agricultural planting, agricultural breeding & the daily life of people.
60 | P a g e
Name –PRINCE KHATRI Class - B. Tech, III Year Branch - AI & DS Sem – VI
Subject – Sensor Theory and Applications (EC 363)
Step 6:- Upload the Code in Arduino board by pressing Right arrow upload button from top
Left Corner.
Step 7:- Open Serial Monitor.
Code:
#define pwmPin A9
int prevVal = LOW;
long th, tl, h, l, ppm;
void setup() {
Serial.begin(9600);
pinMode(pwmPin, INPUT);
}
void loop() {
long tt = millis();
int myVal = digitalRead(pwmPin);
if (myVal == HIGH) {
// digitalWrite(LedPin, HIGH);
if (myVal != prevVal) {
h = tt;
tl = h - l;
prevVal = myVal;
}
} else {
if (myVal != prevVal) {
l = tt;
th = l - h;
prevVal = myVal;
ppm = 5000 * (th - 2) / (th + tl - 4);
if (ppm > 1000 && ppm < 4800) {
Serial.println("Co2 = " + String(ppm));
}
}
}
}
61 | P a g e