CO2 Notes
CO2 Notes
Instructional Objectives
The instruction objectives for Sensors Interfacing and Implementation, considering the various
sensor types (Infra-Red, PIR, Ultrasonic, and Gas Sensors), can be outlined as follows:
1. List the fundamental characteristics of sensors, including their purpose, components, and
basic operating principles.
2. Understand the significance of sensor integration for various applications, including
Infra-Red, PIR, Ultrasonic, and Gas Sensors.
3. Explore the functionalities and specific use cases of each sensor type. Learn practical
techniques for interfacing these sensors with different devices and systems.
4. Emphasize reliability, robustness, security, and data privacy considerations in sensor
implementation to ensure effective and safe operations.
Learning Outcomes
Upon completing a course on Sensors Interfacing and Implementation for various applications,
learners will be able to:
1. Understand the importance of sensor integration and its role in connecting diverse
sensors to devices and systems for data collection and analysis.
2. Apply practical knowledge to interface different sensor types, such as Infra-Red, PIR,
Ultrasonic, and Gas Sensors, with various platforms effectively.
3. Implement sensors in real-world applications, demonstrating proficiency in tasks like
motion detection, proximity sensing, object detection, distance measurement, and gas
monitoring.
4. Analyze and address challenges related to reliability, robustness, security, and data
privacy during sensor interfacing to ensure accurate and safe sensor performance.
5. Demonstrate problem-solving skills by exploring real-world use cases and applying
sensor interfacing techniques to innovate and improve various industries and
applications.
2.1 Introduction of Sensors
2.1.1.1 What is sensor?
A sensor is a specialized device that detects and measures various physical quantities, such as
pressure, light, heat, temperature, and humidity, among others, in the surrounding environment.
Upon sensing these inputs, the sensor generates an electric signal as its output. This signal can
be further processed and presented in a user-friendly format, displayed on a screen, transmitted
through a network, or used by other devices for various applications. Common examples of
sensors include temperature sensors, pressure sensors, humidity sensors, proximity sensors,
photo sensors, motion sensors, and more.
A transducer is a device designed to convert energy from one form to another. It can also
transform non-electrical physical quantities into electric signals. The essential components of a
transducer include the input device, processing device, and output device. The conversion
process of energy from one form to another within a transducer is called transduction. Where,
the transduction is complete in following two steps,
i. It first senses the input signal,
ii. Strengthen the input signal for further processing to produce output.
In the context of a transducer, the input device is responsible for measuring the physical
quantity and subsequently transmitting an analog signal, which is proportional to the measured
quantity, to the processing device. The processing device, also known as the conditioning
device, alters or filters the analog signal to make it suitable for the output device's acceptance.
Transducers find widespread application in converting various forms of energy, including
mechanical energy, light energy, acoustic energy, thermal energy, electromagnetic energy, and
more. Some common examples of transducers include microphones, light bulbs, loudspeakers,
and many others.
19. Which temperature sensor is based on the principle of the change in electrical resistance
with temperature?
a. Thermocouple
b. Thermistor
c. RTD (Resistive Temperature Detector)
d. LM35
20. True or False: Thermocouples are highly accurate temperature sensors and do not require
calibration.
a. True
b. False
21. The LM35 temperature sensor provides an analog output voltage that is linearly proportional
to:
a. Temperature in degrees Celsius
b. Temperature in degrees Fahrenheit
c. Temperature in Kelvin
d. Temperature in Ohms
22. Which temperature sensor is more suitable for precise and accurate temperature
measurements in laboratory and industrial applications?
a. Thermocouple
b. Thermistor
c. RTD (Resistive Temperature Detector)
d. LM35
Summary
Sensors play a vital role in Arduino projects, enabling interaction between the physical world
and the Arduino microcontroller. They are devices that measure various physical properties and
convert them into electrical signals that Arduino can interpret and process. Sensors allow
Arduino projects to respond to changes in the environment, making them more interactive and
responsive.
Key Points:
Function of Sensors: Sensors are used to detect and measure a wide range of physical
properties, including temperature, light intensity, motion, proximity, humidity, gas
concentration, and more.
Importance of Sensors: Sensors are essential for creating smart and automated systems. They
provide data inputs that can trigger actions or decisions, making Arduino projects more
intelligent and capable of real-world interactions.
Arduino Compatibility: Many sensors are designed to work seamlessly with Arduino boards.
Arduino's analog and digital input/output pins make it easy to interface with various types of
sensors.
Types of Sensors: Sensors can be categorized based on the physical properties they measure.
Some common types of sensors used with Arduino include temperature sensors, light sensors,
motion sensors, proximity sensors, gas sensors, and humidity sensors.
Sensor Interfacing: To use a sensor with Arduino, it needs to be connected properly to the
appropriate pins on the Arduino board. Analog sensors usually connect to analog input pins,
while digital sensors connect to digital input pins.
Reading Sensor Data: Arduino provides functions like analogRead() and digitalRead() to read
sensor data. Analog sensors provide continuous values that need to be converted to meaningful
units, while digital sensors provide discrete on/off values.
Applications: Sensors with Arduino find applications in a wide range of projects, including
home automation, weather stations, smart security systems, robotics, environmental monitoring,
and more.
In summary, sensors are integral components of Arduino-based projects, providing the means to
gather data from the physical world and enabling the creation of interactive and responsive
applications. By utilizing various sensors, Arduino projects can be customized to meet specific
requirements, making them versatile and adaptable to different environments and scenarios.
Terminal Questions
1. What is the primary role of sensors in Arduino projects?
2. How do sensors allow Arduino to interact with the physical world?
3. Name three common types of sensors used with Arduino and the physical properties
they measure.
4. Explain the difference between analog and digital sensors with respect to Arduino
interfacing.
5. How does the analogRead() function in Arduino work, and when is it used?
6. Briefly explain the process of interfacing an analog temperature sensor (e.g., LM35)
with Arduino.
7. Discuss the importance of sensors in home automation projects with Arduino.
8. What is the role of humidity sensors in environmental monitoring applications with
Arduino?
Answer Keys
Self-Assessment Questions
Question No Answer
1 B
2 D
3 C
4 C
5 C
6 B
7 C
8 C
9 C
10 D
11 B
12 A
13 A
14 B
15 A
16 A
17 B
18 D
19 B
20 B
21 A
22 C
Activity
1. Creating a Simple Temperature Monitoring System with Arduino and LM35 Sensor
Arduino: An open-source microcontroller platform that provides a flexible and accessible way to
create interactive electronic projects.
Analog Sensor: A sensor that provides continuous output values, typically in the form of analog
voltage, corresponding to the measured physical quantity.
Digital Sensor: A sensor that provides discrete output values, such as binary signals (HIGH or
LOW), indicating the presence or absence of a specific condition.
Analog Input Pins: Pins on the Arduino board that are used to read analog voltage values from
analog sensors.
Digital Input Pins: Pins on the Arduino board that are used to read digital signals from digital
sensors.
Temperature Sensor: A sensor that measures changes in temperature, commonly used in weather
monitoring, home automation, and industrial applications.
LM35: An analog temperature sensor that provides a linear voltage output proportional to
temperature, widely used for temperature measurement.
Interfacing: The process of connecting and configuring a sensor to work with an Arduino board.
Serial Monitor: A tool in the Arduino IDE that allows real-time communication between the
Arduino board and a computer, used for debugging and data visualization.
Input: Data or signals received by the Arduino from sensors or other devices.
Output: Actions or signals generated by the Arduino in response to inputs from sensors or
programming logic.
Table of Contents:
Unit 2.2 Sensors Interfacing and implementation for various applications
Aim
Instructional Objectives
Learning Outcomes
2.2.1 LM35 Interfacing
2.2.2 Light Dependent Resistor Interfacing
2.2.3 Infra-Red Sensor Interfacing
2.2.4 PIR Sensor Interfacing
2.2.5 Ultrasonic Sensor Interfacing
2.2.6 Gas Sensor Interfacing
Summary
Terminal Questions
Self-Assessment Questions
Answer Keys
Activity
Glossary
2.2 Sensors interfacing and implementation for various applications
2.2.1 Overview of LM35 Temperature Sensor:
The LM35 is a highly popular analog, general-purpose temperature sensor renowned for its
linear sensor gain, which ensures straightforward and precise temperature measurements. It
offers temperature values using a simple two-variable equation. Both the LM35 and LM35A
variants can measure temperatures within a wide range from -55°C to 150°C, boasting an
accuracy of +/- 0.25°C at room temperature and +/- 0.75°C at its full-scale range.
The LM35 family comprises LM35C and LM35CA, with a temperature range of -40°C to
110°C, while LM35D operates in the range of 0°C to 100°C. This sensor produces an output
voltage that increases by 10mV for every degree Celsius change in temperature. Regardless
of the specific packaging, the LM35 temperature sensor is designed with three pins, making it
easy to interface in a circuit. Among these pins, two are utilized for power supply, while the
third one functions as the output. The sensor can be powered by either a single supply or a
plus-minus power supply, within the range of 4 to 30V.
The preceding details provide a comprehensive description of the thermistor and the process
of connecting an LM35 to an Arduino board. This highlights the crucial role of temperature
sensors in autonomous robotic projects for temperature detection. Acquiring this knowledge
and understanding empowers you to showcase practical experience with temperature sensors
and excel in project management by integrating mechanics, electronics, and programming for
enhanced outcomes.
Interfacing LM35 with Arduino:
Fig. 2.2.1.3 Interfacing Diagram of LM35 Temperature Sensor with Arduino
Program:
// include the library code for LCD display:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Defining pin
#define temp A5
#define led 13
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
pinMode(led, OUTPUT);
pinMode(temp, INPUT);
Serial.begin(9600);
lcd.clear();
lcd.print("Temperature: ");
}
//Global Variable
float pre_temp = 0;
void loop() {
float temperature = 0;
temperature = (analogRead(temp) * 0.48828125) - 49.95;
if(pre_temp != temperature)
{
lcd.setCursor(0,1);
lcd.print(" ");
}
lcd.setCursor(0,1);
lcd.print(temperature);
lcd.print(" C");
pre_temp = temperature;
}
Response:
1. The LM35 Temperature Sensor provides an analog output voltage that is linearly
proportional to:
a. Temperature in degrees Celsius
b. Temperature in degrees Fahrenheit
c. Temperature in Kelvin
d. Temperature in Ohms
2. The LM35 Temperature Sensor is commonly used in applications that require:
a. High accuracy and a wide temperature range
b. Low accuracy and a narrow temperature range
c. High accuracy and a narrow temperature range
d. Low accuracy and a wide temperature range
3. What is the sensitivity of the LM35 Temperature Sensor in mV/°C?
a. 1 mV/°C
b. 10 mV/°C
c. 100 mV/°C
d. 1000 mV/°C
4. How can the LM35 Temperature Sensor be powered when used with an Arduino board?
a. It requires a separate power supply.
b. It can be powered directly from the 5V pin on the Arduino board.
c. It can be powered from any digital pin on the Arduino board.
d. It can only be powered using a USB cable.
5. To read the output of the LM35 Temperature Sensor with an Arduino, which analog input
pin is commonly used?
a. A0
b. A1
c. A2
d. A3
2.2.2 Light Dependent Resistor
A light-dependent resistor (LDR) is a passive electronic component capable of altering its
resistance based on the intensity of light it receives on its surface. LDRs are alternatively
known as photo resistors, photocells, or photoconductors. They are composed of
semiconductor materials that exhibit high resistance in the absence of light and low resistance
when exposed to light. LDRs serve as light sensors and find widespread use in numerous
applications, including street lighting, alarm clocks, burglar alarms, and light intensity
meters.
2.2.2.1 What is a Light Dependent Resistor?
A light-dependent resistor is characterized as a device that exhibits a decrease in resistance
with increasing light intensity and an increase in resistance with decreasing light intensity.
The resistance of an LDR can vary widely, ranging from a few ohms to several mega ohms,
based on factors such as the type and quality of the material used and the ambient
temperature.
The symbol for a light-dependent resistor is shown below. The arrow indicates the direction
of light falling on it.
These devices rely on light; when light illuminates the LDR, its resistance decreases, and it
increases when in the dark. In a dark environment, the LDR exhibits high resistance, whereas
in the presence of light, its resistance decreases.
In the figure provided, the sense/data pin is one of the three pins of the sensor, alongside the
power pins labeled VCC and GND. This sense/data pin incorporates a signal LED and a
power LED. The signal LED activates when the circuit is triggered, while the power LED
illuminates when power is applied to the board.
The board includes a comparator Op-amp responsible for converting the analog signal from
the photodiode into a digital signal. Furthermore, it features a sensitivity adjustment
potentiometer that enables users to modify the sensitivity. The photodiode and IR emitting
LED constitute the complete IR Proximity Sensor Module when combined.
The intensity of the reflected light relies on the proximity of the object to the sensor. Upon
activation, the sensor delivers a corresponding Low signal through the output pin, which can
be sensed by an Arduino or other microcontroller to perform a designated task. An intriguing
aspect of this module is its inclusion of two built-in LEDs—one illuminates when power is
ON, while the other activates when the circuit is triggered.
Advantages:
1. Due to the line-of-sight or point-to-point communication mode, it offers secure
communication.
2. Since infrared devices consume less power, their batteries last a long time.
3. Motion is successfully detected by infrared motion sensors both during the day and at
night.
4. Ultrasound equipment may have trouble picking up soft things, while infrared devices
can estimate their distance.
5. They are more reasonably priced and smaller in size.
6. It responds more quickly than a thermocouple.
7. Over time, it offers good stability.
Disadvantages:
1. It can only control one device at a time in the monitor and control application.
2. Additionally, controlling objects that are out of the line of sight is challenging. Line of
sight between the transmitter and receiver is necessary for communication. It supports
a smaller range, therefore its performance suffers at greater distances.
3. Compared to cable transmission, it supports lesser data rate transmission.
4. Smoke, dust, fog, sunlight, etc. all have an impact on infrared frequencies. It therefore
cannot pass through walls or doors.
5. High-powered infrared radiation can harm the eyes.
Applications:
IR sensors find applications in various fields, including:
Proximity Sensing: IR sensors are used in touchless switches, automatic faucets, and
elevators to detect the presence of objects or people.
Temperature Measurement: Infrared thermometers use IR sensors to measure the temperature
of objects without direct contact, making them suitable for medical, industrial, and scientific
purposes.
Night Vision: IR sensors are employed in night vision devices to detect and amplify infrared
radiation from the environment, enabling users to see in low-light conditions.
Home Automation: IR sensors play a crucial role in smart home systems, enabling the control
of appliances and devices based on the presence or absence of occupants.
Overall, infrared sensors have become an integral part of modern technology, contributing to
improved automation, efficiency, and convenience in various applications.
Conventional principal uses for infrared sensors are basically in as well:
1. Meteorology
2. Climatology
3. Using photo bio modulation
4. Examination of Water
5. detectors for gas
6. Anesthesiology testing
7. Investigating petroleum
8. Security of Rails
Program:
#include <IRremote.h>
const int IR = 2;
IRrecv recv(IR);
decode_results signals;
void setup()
{
Serial.begin(9600);
recv.enableIRIn();
Serial.println("Starting IR sensor program...");
}
void loop()
{
if (recv.decode(&signals))
{
Serial.println(signals.value, HEX);
recv.resume();
}
delay(100);
}
Response:
The PIR sensor comprises two primary components: the pyroelectric sensor and the fresnel
lens. The sensor resembles a spherical metal object with a rectangular crystal at its center. A
special lens known as a fresnel lens concentrates infrared (IR) signals onto the pyroelectric
sensor, allowing it to detect various infrared radiation intensities.
The pyroelectric sensor is constructed with coated silicon material and features a window
with two rectangular slots, allowing only IR radiation to pass through. Beyond this window,
two distinct IR sensor electrodes are present—one responsible for producing the positive
output and the other for producing the negative output. When there is no movement in the
sensor's field of view, both slots detect an equal quantity of IR radiation, resulting in a zero
output signal.
Fig. 2.2.4.2 Functional diagram of PIR sensor
When an animal or human approaches the sensor, it interrupts one-half of the sensor, leading
to a positive differential change between the two halves. Similarly, when the human body
obstructs the other half of the sensor, a negative differential change is produced. Motion is
detected by measuring this voltage variation. The Fresnel lens within the sensor expands its
field of view and range of detection. This lens boasts impressive light gathering capabilities, a
lightweight design, and a thin profile.
Characteristics of PIR Sensors:
PIR sensors' versatility and effectiveness make them essential components in numerous IoT
applications. They contribute to enhancing the comfort and convenience of smart homes,
strengthening security measures, and optimizing resource management. PIR sensors have
revolutionized our interaction with the surroundings in the IoT era.
Advantages of PIR sensors
Following are the advantages of PIR Sensors
Small in size
Wide lens range
Easy to interface
Low Cost
Low-power
Easy to use
Do not wear out
Self-Assessment Questions
16. What is the primary function of a PIR sensor?
a. Measuring the distance between objects.
b. Detecting changes in temperature.
c. Sensing motion and presence of objects.
d. Measuring the intensity of light.
Description:
The functioning of an ultrasonic sensor involves the use of high-frequency sound waves to
detect objects and measure distances. It consists of a transmitter and a receiver that work
together to emit and receive ultrasonic waves. The sensor's operation is comparable to
echolocation, similar to how bats navigate and locate objects in their surroundings. The
transmitter of the ultrasonic sensor produces ultrasonic waves by inducing vibrations in a
piezoelectric crystal through an electrical current. These waves have frequencies beyond the
audible range of human hearing, typically ranging from 20 kilohertz to several tens of
kilohertz.
Working Principle:
Ultrasonic sensors are equipped with a transducer that emits high-frequency sound waves,
usually in the ultrasonic range (above 20 kHz). These sound waves travel through the air and
bounce off objects in their path. The sensor's receiver detects the reflected sound waves and
calculates the time it takes for the waves to return. By knowing the speed of sound in the
medium, the sensor can accurately determine the distance between the sensor and the object.
The Ultrasonic transmitter emits an ultrasonic wave that travels through the air. Upon
encountering an object, the wave reflects off the object's surface and returns towards the
sensor. The Ultrasonic receiver module, as shown in the Figure, detects and captures the
reflected wave for further analysis.
When the reflected wave reaches the sensor, the Echo pin registers a high signal for a specific
duration. This duration corresponds to the time taken for the ultrasonic wave to travel back to
the sensor after reflecting off the object. The Microcontroller/Microprocessor Unit
(MCU/MPU) measures the length of time that the Echo pin remains high, providing valuable
information about the distance between the sensor and the object. This technique enables
precise distance measurement.
The HC-SR04 sensor is incredibly versatile and compatible with various platforms, such as
Arduino, AMC, PIC, Raspberry Pi, and more, making it a popular choice for microcontroller
and microprocessor applications. Its user-friendly design and broad compatibility contribute
to its widespread adoption in numerous projects and applications.
Interfacing Ultrasonic Sensor with Arduino
Serial.print(cm);
Serial.print("cm");
Serial.println();
// Turn on the LED if the object is too close:
if(cm < 100) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(100);
}
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2;
}
Response:
Fig.
2.2.6.1 Gas sensors
Description:
The gas sensor circuit consists of input and output terminals, labeled A and B, respectively,
and terminal H, which connects to the Heater coil. A variable resistor is integrated into the
circuit, serving two vital functions: adjusting the output voltage and ensuring high sensitivity.
Without applying any input voltage to the Heater coil, the output current remains extremely
low, almost negligible, approximately 0. Nevertheless, when adequate voltage is supplied to
the input terminal and Heater coil, the sensing layer becomes active, ready to detect any
nearby combustible gases.
When toxic gas is present in the vicinity, the pre-heated Heater coil facilitates the detection of
combustible gases in the environment. Upon contact with gases, the sensing layer experiences
a change in resistance, resulting in a variation in the current flowing through the circuit. This
change is observable at the load resistance (RL), which can have a value ranging from 10KΩ
to 47KΩ, depending on the specific requirements and application of the gas sensor circuit. By
adjusting the load resistance, the sensor's sensitivity and response to different gas
concentrations can be finely tuned.
Interfacing MQ2 Sensor with Arduino:
Program:
int LED = A1;
const int gas = 0;
int MQ2pin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
float sensorValue,MQ2pin;
sensorValue = analogRead(MQ2pin); // read analog input pin 0
if(sensorValue >= 470){
digitalWrite(LED,LOW);
Serial.print(sensorValue);
Serial.println(" |SMOKE DETECTED");
}
else{
digitalWrite(LED,HIGH);
Serial.println("Sensor Value: ");
Serial.println(sensorValue);
}
delay(1000);
}
float getsensorValue(int pin){
return (analogRead(pin));
}
Response:
Self-Assessment Questions
27. Gas sensors are commonly used to detect gases such as:
a. Oxygen and nitrogen
b. Carbon dioxide and oxygen
c. Carbon monoxide and methane
d. Nitrogen and methane
28. Which Arduino function is commonly used to read the output from a gas sensor?
a. gasRead()
b. analogRead()
c. digitalRead()
d. gasSense()
Here is a summary of sensors interfacing with Arduino and their implementation in various
applications:
Question No Answer
1 A
2 C
3 B
4 B
5 A
6 C
7 B
8 B
9 B
10 C
11 D
12 C
13 A
14 B
15 C
16 C
17 C
18 A
19 C
20 B
21 D
22 A
23 D
24 C
25 C
26 D
27 C
28 B
29 B
30 C
Activity
1. Create an automatic light control system: Use the PIR sensor to turn on lights when
motion is detected and turn them off after a certain period of inactivity.
3. Integrate with a camera: When motion is detected, capture images or record a video
using a camera module and save it to an SD card or send it to a remote server.
Sensor: A device or transducer that detects and measures physical properties or changes in the
environment.
Actuator: A device that converts electrical signals into physical action or movement, often
used in response to sensor data.
Analog Sensor: A sensor that provides continuous and proportional output, typically in the
form of voltage, current, or resistance.
Digital Sensor: A sensor that provides discrete outputs, usually in the form of binary data (0s
and 1s).
Input/Output (I/O) Pins: Pins on the Arduino board used for interfacing with external devices
such as sensors and actuators.
Interfacing: The process of connecting and configuring sensors to work with the Arduino
board.
AnalogRead(): A built-in Arduino function used to read analog sensor values from analog
input pins.
DigitalRead(): A built-in Arduino function used to read digital sensor values from digital
input pins.
Applications:
Home Automation: Sensors like temperature, humidity, and motion sensors are used to
control lighting, heating, and cooling systems based on environmental conditions and
occupancy.
Environmental Monitoring: Sensors such as gas sensors and air quality sensors are used to
monitor pollutants and ensure a safe environment.
Security Systems: Motion sensors, light sensors, and door/window sensors are utilized in
security applications to detect intrusion and trigger alarms.
Smart Agriculture: Soil moisture sensors and weather sensors are employed for efficient
irrigation and crop management.
Robotics: Distance sensors, motion sensors, and touch sensors are used for obstacle detection
and navigation in robotic applications.
Healthcare: Sensors like temperature sensors and heart rate sensors are integrated into
medical devices for patient monitoring and health tracking.
Industrial Automation: Various sensors are utilized in industrial settings for process control,
monitoring equipment conditions, and ensuring workplace safety.
Sensors interfacing with Arduino offer endless possibilities for innovative projects and
practical applications across different domains, making them a crucial aspect of the Internet
of Things (IoT) and embedded systems development.