0% found this document useful (0 votes)
17 views71 pages

CO2 Notes

This document discusses sensors and their interfacing. It begins with defining sensors and transducers, describing their basic components and functions. It then covers various types of sensors and their classification. Specific temperature sensors like thermistors are explained in detail. The document concludes by outlining objectives and learning outcomes for interfacing different sensors like light, infrared, motion and gas sensors and applying them in real-world situations.

Uploaded by

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

CO2 Notes

This document discusses sensors and their interfacing. It begins with defining sensors and transducers, describing their basic components and functions. It then covers various types of sensors and their classification. Specific temperature sensors like thermistors are explained in detail. The document concludes by outlining objectives and learning outcomes for interfacing different sensors like light, infrared, motion and gas sensors and applying them in real-world situations.

Uploaded by

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

Sensors and its Interfacing

Unit 2.1 Introduction of Sensors


Definition, Types, Classification, Temperature Sensors: Thermistor, Thermistor types, LM35
Interfacing.
Unit 2.2 Sensors Interfacing and implementation for various applications
Light Dependent Resistor Interfacing, Infra-Red Sensor Interfacing, PIR Sensor Interfacing,
Ultrasonic Sensor Interfacing, Gas Sensor Interfacing.
Table of Contents:
Unit 2.1 Introduction of Sensors
Aim
Instructional Objectives
Learning Outcomes
2.1.1 What is Sensor?
2.1.1.1 What is sensor?
2.1.1.2 Sensor Characteristics:
2.1.2 Types of sensors
2.1.3 Classification
2.1.4 Temperature Sensors: Thermistor, Thermistor types.
2.1.4.1 Thermistor
2.1.4.2 Working
2.1.4.3 Advantages of a Thermistor
2.1.4.4 Disadvantages of a Thermistor
2.1.4.5 Applications of Thermistor
Summary
Terminal Questions
Answer Keys
Activity
Glossary
Aim
The aim of sensors is to enable the measurement, detection, and monitoring of various physical
properties or environmental parameters, converting these inputs into electrical or digital signals
that can be further analyzed, interpreted, and utilized in diverse applications.

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.

Fig. 2.1.1.1 Sensor

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.

2.1.1.2 Sensor Characteristics:


Sensors are specialized devices designed to detect and react to physical changes or
environmental stimuli, translating them into measurable signals or electrical output. They
possess several crucial characteristics that determine their performance and functionality. Here
are some important characteristics of sensors:
i. Static
ii. Dynamic
i. Static Characteristics:
 Accuracy: Accuracy is a fundamental characteristic of a measuring instrument,
reflecting its capacity to yield results that are in close proximity to the true value of the
measured quantity. It quantifies the extent of errors in the measurements and is evaluated
using both absolute and relative errors. Accuracy represents how effectively the
instrument's output aligns with a more precise reference system.
Absolute error = Measured value – True value
Relative error = Measured value / True value
 Range: The range of a sensor defines the upper and lower limits of the physical quantity
it is capable of detecting. If the measured quantity exceeds this range, the sensor will not
yield any meaningful response, rendering its readings unreliable or invalid. It is crucial
to operate the sensor within its specified range to obtain accurate and relevant data.
 Resolution: Resolution holds significant importance when choosing a sensor as it
denotes the smallest detectable change in the input that the sensor can identify. A higher
resolution indicates better precision. In the case of zero resolution, it is referred to as the
threshold, where the sensor will only respond to inputs that exceed a specific value.
 Precision: Precision pertains to the capability of a measuring instrument to yield
consistent and reproducible readings when measuring the same quantity under identical
conditions. It implies a level of agreement between successive measurements, but it does
not necessarily indicate how close those measurements are to the true value. Precision is
connected to the variance among a set of measurements and is essential, but not solely
enough, for ensuring accuracy.
 Sensitivity: Sensitivity represents the relationship between the incremental change in
the system's response and the incremental change in its input parameters. It can be
derived from the slope of the output characteristics curve of a sensor. Sensitivity
indicates the smallest quantity difference that will result in a discernible change in the
instrument's reading. In other words, it quantifies how responsive the sensor is to even
the slightest variations in the measured quantity.
 Linearity: Linearity evaluates the degree to which the sensor value curve adheres to a
straight line. This characteristic is established by plotting the output amplitude against
the input amplitude in a calibration curve under static conditions. Linearity quantifies
how closely the slope of the curve resembles a straight line, indicating the sensor's
ability to produce consistent and predictable readings across its operating range.
 Drift: Drift refers to the discrepancy in the sensor's measurement from a particular
reading when it remains at that value over an extended period of time. In other words, it
is the gradual change or deviation in the sensor's output when it is exposed to a constant
input for a prolonged duration. Drift can lead to inaccuracies in measurements and is an
important consideration for sensors that require stable and reliable performance over
time.
 Repeatability: Repeatability refers to the variation or deviation observed between
measurements taken in a sequence under identical conditions. These measurements
should be performed within relatively short time duration to prevent any significant
long-term drift or changes in the sensor's behavior. Repeatability is a crucial
characteristic for assessing the consistency and reliability of a sensor's output, especially
when repeated measurements are required in a short time frame.
ii. Dynamic Characteristics: System Properties,
 Zero-order system: A zero-order system exhibits an instantaneous response of the
output to the input signal without any delay. It lacks energy-storing elements and its
output is directly proportional to the input. Potentiometers utilized for measuring linear
and rotary displacements are typical examples of zero-order systems.
 First-order system: A first-order system displays a gradual approach towards its final
output value. It incorporates an energy storage and dissipation element, leading to a time
delay in its response.
 Second-order system: A second-order system demonstrates a complex output response.
Upon application of an input signal, the output oscillates before eventually reaching a
steady state.
Self-Assessment Questions
1. What is a sensor?
a. A device that converts electrical energy into mechanical energy.
b. A device that measures physical properties and converts them into electrical signals.
c. A device that amplifies electrical signals for better Arduino performance.
d. A device that communicates wirelessly with other Arduino boards.
2. How does a sensor work with an Arduino?
a. The sensor sends commands to the Arduino board to execute specific tasks.
b. The sensor receives data from the Arduino board and processes it.
c. The Arduino board sends electrical signals to the sensor to activate it.
d. The sensor provides electrical output to the Arduino based on the physical property it
measures.
3. Which of the following best describes the role of a sensor in an Arduino project?
a. Generating random data for testing purposes.
b. Providing power to the Arduino board.
c. Enabling the Arduino to interact with the physical world by detecting changes in its
environment.
d. Storing data and variables used by the Arduino program.
4. What is sensitivity in the context of sensors?
a. The ability of a sensor to measure multiple physical properties simultaneously.
b. The range of physical quantities a sensor can measure.
c. The ability of a sensor to detect small changes in the measured quantity.
d. The ability of a sensor to communicate wirelessly with other devices.
5. Which sensor characteristic defines the smallest change in the measured quantity that a sensor
can detect?
a. Sensitivity
b. Range
c. Resolution
d. Accuracy
6. True or False: A sensor with higher resolution is always more accurate than a sensor with
lower resolution.
a. True
b. False
2.1.2 Types of Sensors
A diverse range of sensors is available, each meticulously designed to detect and measure
specific physical parameters or environmental conditions. Some of the various types of sensors
can be categorized based on their functionalities as follows:
i. Temperature Sensors: A Temperature Sensor is a device employed to measure the heat
or temperature of an operating machine part. It utilizes a component called a
Thermocouple for temperature sensing. The thermocouple is a temperature-measuring
device consisting of two dissimilar conductors in contact at one or more points. When
the temperature at one of these points changes in comparison to the reference
temperature at other parts of the circuit, it generates a voltage.

Fig. 2.1.2.1 Temperature Sensor

ii. Pressure Sensors: A pressure sensor is an instrument fitted with a pressure-sensitive


element intended to gauge the pressure of liquids or gases acting on a diaphragm
composed of materials like silicon or stainless steel. The measured value is subsequently
converted into an electrical signal, serving as the output. These sensors have diverse
applications, including measuring water flow in pipes or tanks and issuing alerts when
repairs or adjustments are required. Nowadays, pressure sensors are extensively
employed in aircraft and vehicles to continuously ascertain altitude and force.

Fig. 2.1.2.2 Pressure Sensor


iii. Proximity Sensors: A proximity sensor is a motion-detecting device widely used in
retail shops. This technology allows retailers to detect a customer's proximity to a
specific product and, in response, send coupons and deals to their mobile devices or
email. In contemporary applications, proximity sensors are also employed to monitor the
availability of free spaces, such as parking spots and seating areas in sports stadiums,
malls, and airports.

Fig. 2.1.2.3 Proximity Sensor


iv. Light Sensors: Light sensors are electronic devices capable of detecting and measuring
light intensity. They transform light energy into electrical signals and are widely utilized
in various applications such as automatic lighting, camera exposure control, display
brightness adjustment, solar panels, color sensing, and flame detection. These sensors
play a pivotal role in enhancing energy efficiency and optimizing numerous processes in
modern technology.

Fig. 2.1.2.4 Light Sensor


v. Motion Sensors: Motion sensors, also referred to as motion detectors, are devices
utilized to identify movement or changes in an object's position within their detection
range. Equipped with technologies such as infrared, ultrasonic, microwave, or passive
infrared (PIR), these sensors can effectively detect motion. Motion sensors find
extensive applications in security systems, lighting control, automatic doors, smart home
devices, gaming consoles, and other areas where motion detection is crucial. They
activate responses such as triggering alarms, turning on lights, or sending notifications to
alert users about detected movements. Motion sensors significantly contribute to
enhancing safety, convenience, and energy efficiency in diverse environments.
Fig. 2.1.2.5 Motion Sensor
vi. Gas Sensors: Gas sensors are specialized devices designed to detect and measure the
presence and concentration of specific gases in the surrounding environment. They
employ various technologies such as electrochemical, semiconductor, infrared, or
catalytic to identify gas molecules effectively. These sensors find extensive application
in various industries for safety and process control, environmental monitoring, and
indoor air quality assessment. Gas sensors play a critical role in detecting hazardous
gases, preventing accidents, and ensuring compliance with safety and environmental
standards. They are essential tools for safeguarding both human lives and the
environment.

Fig. 2.1.2.6 Gas Sensor


Self-Assessment Questions
7. Which type of sensor is commonly used to detect changes in light intensity?
a. Temperature sensor
b. Ultrasonic sensor
c. Light sensor
d. IR sensor
8. What type of sensor is commonly used to measure distances by emitting sound waves and
measuring their reflection?
a. Light sensor
b. Temperature sensor
c. Ultrasonic sensor
d. IR sensor
9. Which sensor is ideal for detecting the presence or absence of an object without physical
contact?
a. Light sensor
b. Ultrasonic sensor
c. Proximity sensor
d. IR sensor
10. Which type of sensor can measure changes in temperature and is commonly used for
weather monitoring?
a. Light sensor
b. Proximity sensor
c. Ultrasonic sensor
d. Temperature sensor
11. True or False: An accelerometer is a type of sensor that measures the Earth's magnetic field
and is used in compass applications.
a. True
b. False
2.1.3 Classification of Sensors
Sensors can be categorized using different criteria, including the type of quantity they measure,
their operating principles, or their specific applications. Here are some common classifications
of sensors:
1. Passive & Active
2. Analog & Digital
3. Scalar & Vector
 Passive Sensors: These sensors do not have inherent capability to sense the input; they
rely on external stimulus to generate a response.
Examples include accelerometers, soil moisture sensors, water level sensors, and
temperature sensors.
 Active Sensors: In contrast, active sensors are capable of independently sensing the
input and generating a response without requiring external stimulation.
Examples of active sensors are radar sensors, sounders, and laser altimeter sensors.
 Analog Sensors: Analog sensors generate a continuous output that changes in direct
proportion to the measured input parameter.
Examples include temperature sensors, Light Dependent Resistors (LDRs), analog
pressure sensors, and analog hall effect sensors.
 Digital Sensors: Digital sensors offer binary output responses and are engineered to
surpass the limitations of analog sensors. They incorporate additional electronics for bit
conversion. Examples of digital sensors include Passive Infrared (PIR) sensors and
digital temperature sensors like DS1620.
 Scalar Sensors: Scalar sensors detect input parameters solely based on their magnitude.
The sensor's response is entirely dependent on the magnitude of the input, and it remains
unaffected by the direction of the input parameter.
Examples include temperature sensors, gas sensors, strain sensors, color sensors, and
smoke sensors.
 Vector Sensors: Conversely, vector sensors' response is contingent on both the
magnitude and the direction or orientation of the input parameter.
Examples of vector sensors are accelerometers, gyroscopes, magnetic field sensors, and
motion detector sensors.
Self-Assessment Questions
12. What is the primary classification of sensors based on their output signal?
a. Analog sensors
b. Digital sensors
c. Serial sensors
d. I2C sensors
13. Which type of sensor provides continuous output values that can vary over a range?
a. Analog sensors
b. Digital sensors
c. Serial sensors
d. I2C sensors
14. Sensors that provide output in the form of discrete levels (e.g., ON/OFF) are classified as:
a. Analog sensors
b. Digital sensors
c. Serial sensors
d. I2C sensors
15. What is the primary classification of sensors based on the physical quantity they measure?
a. Environmental sensors
b. Motion sensors
c. Proximity sensors
d. Actuators
16. Which type of sensor is used to detect changes in temperature, humidity, pressure, etc.?
a. Environmental sensors
b. Motion sensors
c. Proximity sensors
d. Actuators
17. Sensors that detect movement or acceleration are categorized as:
a. Environmental sensors
b. Motion sensors
c. Proximity sensors
d. Actuators
2.1.4 Temperature Sensors
2.1.4.1 Thermistor: A thermistor operates as a temperature-sensitive resistor and is frequently
employed for temperature measurement.

Fig. 2.1.4.1 Thermistor Symbol — US and Japan


The term "thermistor" is a combination of "thermal" and "resistor." All resistors exhibit some
temperature dependency, represented by their temperature coefficient. While conventional
resistors aim to minimize this coefficient, thermistors are intentionally designed with a high
temperature coefficient. Unlike regular resistors, thermistors usually have a negative
temperature coefficient (NTC), resulting in a decrease in resistance as the temperature rises.
Such thermistors are referred to as NTC thermistors. Conversely, thermal resistors with a
positive temperature coefficient are termed PTC thermistors (Positive Temperature Coefficient).
Types of Thermistors: Thermistors can be classified into two main types: Negative
Temperature Coefficient (NTC) thermistors and Positive Temperature Coefficient (PTC)
thermistors.
i. Negative Temperature Coefficient (NTC) Thermistor: In NTC thermistors, the
resistance decreases as the temperature rises. These thermistors possess a relatively high
resistance, making them sensitive to even minor temperature changes. As the
temperature increases, the resistance drops, resulting in a decrease in the electrical
impedance of the thermistor.

Fig. 2.1.4.2 NTC Thermistor & Characteristics


NTC thermistors find widespread use in temperature sensing applications due to their
negative temperature coefficient, enabling precise measurements across a broad
temperature range. Their capacity to detect subtle temperature changes makes them
well-suited for diverse applications, such as temperature control systems and
environmental monitoring.
ii. Positive Temperature Coefficient (PTC) Thermistor: On the other hand, PTC
thermistors exhibit an increase in resistance as temperatures rise. As the temperature
elevates, the resistance of the PTC thermistor increases proportionally. This distinctive
attribute makes PTC thermistors valuable in applications where their resistance change
can be harnessed for specific purposes.

Fig. 2.1.4.3 PTC Thermistor & Characteristics


PTC thermistors find frequent application in areas like overcurrent protection and self-
regulating heating elements. For instance, in certain heating devices, the PTC thermistor
functions as a self-regulating element that restricts current flow as the temperature
increases, thus preventing overheating.
2.1.4.2 Working Principle of Thermistors
The thermistor operates based on the fundamental principle of resistance change in response to
temperature fluctuations. As the ambient temperature shifts, the thermistor undergoes self-
heating of its elements, leading to alterations in its resistance value. This change in resistance
varies depending on the type of thermistor employed. The resistance temperature characteristics
of different thermistor types are detailed in the following section.

Fig. 2.1.4.4 NTC & PTC Characteristics


Difference between NTC and PTC:

2.1.4.3 Advantages of Thermistor:


Here are some advantages of thermistor
 It has a quick response time
 It has a higher degree of accuracy and high precision.
 They operate at a wide range of temperatures especially NTC thermistors.
 They are far more stable in long-term use.
 It can be designed to withstand any mechanical stress and it can be designed in any
shape.
 It has higher sensitivity than other temperature sensors.
 It has a smaller size and cheaper than other sensors
 They have robust designs.
 It can be used in remote locations.
2.1.4.4 Disadvantages of Thermistor:
Here are some disadvantages of thermistor,
 Most thermistors have a limited temperature range, especially precision thermistors
having high accuracy.
 The resistance varies non-linearly with respect to temperature.
 Due to the self-heating effect, error may get induced in the reading.
 They are fragile.
2.1.4.5 Applications of Thermistor:
Here are some applications of thermistor,
 Digital Thermometers (thermostats)
 Automotive applications (to measure oil and coolant temperatures in cars & trucks)
 Household appliances (like microwaves, fridges, and ovens)
 Circuit protection (i.e., surge protection) and Rechargeable batteries (Ensure the correct
battery temperature is maintained)
 To measure the thermal conductivity of electrical materials
 Temperature compensation (i.e., maintain resistance to compensate for effects caused by
changes in temperature in another part of the circuit.
Self-Assessment Questions
18. What type of temperature sensor provides a voltage output that changes linearly with
temperature?
a. Thermocouple
b. Thermistor
c. RTD (Resistive Temperature Detector)
d. LM35

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

2. Introduction to Sensor Concepts with Arduino


Glossary
Sensors: Devices that measure physical properties or changes in the environment and convert them
into electrical signals that Arduino can interpret and process.

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.

Fig. 2.2.1.1 LM35 Temperature sensor


The LM35 offers notable benefits, including its low power consumption, drawing merely 60
uA from the supply. Moreover, it exhibits low self-heating, resulting in minimal impact on
temperature readings, with a self-heating value of 0.08°C. To obtain temperature readings
from the LM35 sensor, its output should be connected to an Analog-to-Digital Converter
(ADC) or the analog input of a controller. This process converts the analog signal to a digital
reading. The sensor can be interfaced to provide a basic centigrade reading within the range
of 2°C to 150°C or a full-scale reading spanning from -55°C to 150°C.

Fig. 2.2.1.2 Connection Diagram of LM35 Temperature Sensor with Arduino

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:

Fig. 2.2.1.4 Response Diagram of LM35 Temperature Sensor with Arduino


Self-Assessment Questions

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.

Fig. 2.2.2.1 Light dependent resistor symbol


2.2.2.2 Working Principle of LDR:
This resistor operates on the principle of photoconductivity. When light strikes its surface, the
material's conductivity decreases, and the electrons in the valence band of the device are
elevated to the conduction band. For this process to occur, the photons in the incident light
must possess energy greater than the band gap of the semiconductor material. Consequently,
the electrons make a transition from the valence band to the conduction band.
Fig. 2.2.2.2 Illustration of Light dependent resistor

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.

Fig. 2.2.2.3 Variation of LDR Resistance with Variation in Light Intensity


When a constant voltage "V" is applied to the LDR, an increase in light intensity leads to a
corresponding increase in current. The figure below illustrates the curve depicting the
relationship between resistance and illumination for a specific light-dependent resistor.

Fig. 2.2.2.4 Light Intensity vs LDR Resistance


The amount of resistance change depends on several factors, such as:
 The wavelength and intensity of the incident light
 The band gap (the energy difference between the valence band and the conduction
band) of the semiconductor material
 The doping level (the number of impurities added to modify the electrical properties)
of the semiconductor material
 The surface area and thickness of the LDR
 The ambient temperature and humidity.
2.2.2.3 What are the Characteristics of a Light Dependent Resistor?
The main characteristics of a light-dependent resistor are:
 Nonlinearity: The relationship between resistance and light intensity is not linear;
instead, it follows an exponential pattern. This implies that even a slight alteration in
light intensity can lead to a substantial change in resistance, or vice versa.
 Spectral response: The sensitivity of an LDR fluctuates with the wavelength of light.
Certain LDRs may not respond at all to specific wavelength ranges. The spectral
response curve illustrates how the resistance changes in relation to different
wavelengths for a particular LDR.
 Response time: The response time refers to the duration it takes for an LDR to change
its resistance when subjected to or withdrawn from light. It consists of two
components: rise time and decay time. The rise time denotes the time required for the
LDR to decrease its resistance when exposed to light, while the decay time represents
the time taken for the LDR to increase its resistance when removed from light.
Generally, the rise time is quicker than the decay time, with both typically in the order
of milliseconds.
 Recovery rate: The recovery rate indicates how rapidly an LDR returns to its original
resistance level after being exposed to or removed from light. The recovery rate is
influenced by factors such as temperature, humidity, and aging effects.
 Sensitivity: The sensitivity of an LDR represents the ratio of change in resistance to
the change in light intensity. This characteristic is typically expressed in percentages
or decibels (dB). Higher sensitivity implies that an LDR can effectively detect even
minor alterations in light intensity.
 Power rating: The power rating of an LDR indicates the maximum power that the
LDR can handle without sustaining damage. This parameter is typically denoted in
watts (W) or milliwatts (mW). A higher power rating signifies that an LDR can
withstand higher voltages and currents without malfunctioning.
2.2.2.4 What are the Types of Light Dependent Resistors?
Light-dependent resistors can be classified into two types based on the materials used to
construct them:
1. Intrinsic photo resistors: These sensors are crafted from pure semiconductor materials
like silicon or germanium. With a considerable band gap, they demand high-energy
photons to stimulate electron movement across it. Notably, they exhibit higher
sensitivity to short wavelengths (e.g., ultraviolet) as opposed to long wavelengths
(e.g., infrared).
2. Extrinsic photo resistors: These sensors are constructed using semiconductor
materials doped with impurities, resulting in the formation of new energy levels above
the valence band. These energy levels contain electrons that can efficiently transition
to the conduction band using lower-energy photons. Extrinsic photo resistors are
notably more sensitive to long wavelengths (e.g., infrared) than short wavelengths
(e.g., ultraviolet).
2.2.2.5 Advantages and Disadvantages of Light Dependent Resistors:
Advantages:
Some of the advantages of light-dependent resistors are:.
 They are low-cost and simple to use.
 They have a wide range of resistance values and sensitivity levels.
 They do not require any external power source or biasing.
 They are compatible with many circuits and devices.
Disadvantages:
Some of the disadvantages of light-dependent resistors are:
 They have low accuracy and precision due to their nonlinear and temperature-
dependent characteristics.
 They have slow response and recovery times due to their latency
 They have low sensitivity and accuracy compared to other light sensors such as
photodiodes and phototransistors.
 They are affected by environmental factors such as temperature, humidity, and aging.
2.2.2.6 Applications of Light Dependent Resistors:
Light-dependent resistors have many applications in various fields, such as:
 Security systems: LDRs can be used to detect the presence or absence of light, such as
in a camera light meter, a burglar alarm, or an electronic eye.
 Lighting control: LDRs can be used to control the brightness or color of lights, such
as in street lighting, outdoor lighting, or mood lighting.
 Audio compression: LDRs can be used to smooth the response of audio signals by
reducing the dynamic range, such as in compressors, limiters, or noise gates.
 Optical communication: LDRs can be used to modulate or demodulate optical signals,
such as in fiber optic cables, lasers, or photodiodes.
 Measurement and instrumentation: LDRs can be used to measure or indicate light
intensity, such as in light meters, spectrometers, or photometers.

Interfacing LDR with Arduino

Fig. 2.2.2.5 Interfacing diagram of LDR with Arduino


Program:
int value=0;
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT);
pinMode(A0, INPUT);
}
void loop()
{
value= analogRead(A0);
if(value<10)
{
digitalWrite(11, HIGH);
Serial.println("Light ON");
Serial.println(value);
}
else
{
digitalWrite(11, LOW);
Serial.println("Light OFF");
Serial.println(value);
}
}
Response:

Fig. 2.2.2.6 Response of LDR with Arduino


Self-Assessment Questions

6. What is the key characteristic of a Light Dependent Resistor (LDR)?


a. It changes its resistance with changes in temperature.
b. It changes its resistance with changes in humidity.
c. It changes its resistance with changes in light intensity.
d. It changes its resistance with changes in pressure.
7. What happens to the resistance of an LDR when exposed to bright light?
a. It increases.
b. It decreases.
c. It remains constant.
d. It fluctuates randomly.
8. How can an LDR be connected to an Arduino to measure light intensity?
a. Connect the LDR to a digital input pin of the Arduino.
b. Connect the LDR to an analog input pin of the Arduino.
c. Connect the LDR to the 5V pin of the Arduino.
d. Connect the LDR to the ground (GND) pin of the Arduino.
9. Which Arduino function is commonly used to read the analog value from an LDR
connected to an analog input pin?
a. digitalRead()
b. analogRead()
c. digitalWrite()
d. analogWrite()
10. Which of the following could be a suitable application for an LDR with Arduino?
a. Measuring temperature
b. Measuring humidity
c. Light-controlled automatic street lighting
d. Measuring distance
2.2.3 IR Sensor
IR technology serves numerous functions in both daily life and various sectors. For example,
TVs use an IR sensor to interpret signals transmitted by a remote control. The key advantages
of IR sensors lie in their low power consumption, simple construction, and practical
functionality. Although the human eye cannot perceive IR waves, the electromagnetic
spectrum includes IR radiation within the visible and microwave portions. These waves
typically have wavelengths ranging from 0.7 μm to 1000 μm.
An infrared proximity sensor, commonly referred to as an IR sensor, is an electrical device
that emits infrared light to sense certain aspects of its surroundings and detect object
movements. Being a passive sensor, it can only measure infrared radiation passively. If you
have ever attempted to build an obstacle avoidance robot or any other proximity detection-
based system, you are probably already familiar with this sensor.
Description:

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.

Fig. 2.2.3.1 IR Sensor


IR receivers are available in various types, differing in wavelength, voltage, and packaging.
For an infrared transmitter-receiver pair, it is crucial that the receiver's wavelength matches
that of the transmitter. In this setup, an IR LED functions as the emitter, while an IR
photodiode acts as the detector. The IR photodiode can detect the IR light emitted by the IR
LED.
In proportion to the amount of IR light received, the photo-diode's output voltage and
resistance change. This is how the IR sensor functions fundamentally.

Fig. 2.2.3.2 Functional diagram of IR sensor


The IR transmitter emits radiation that reaches the object, and a portion of the radiation
reflects back to the IR receiver. The output of the sensor is determined based on the intensity
of the reception by the IR receiver.
IR sensor types
There are two different kinds of IR sensors available:
1. Infrared Sensor Active
2. Sensor for Passive Infrared

1. Infrared Sensor Active


An active infrared sensor consists of two components: the infrared source and the infrared
detector. Infrared sources include LEDs and infrared laser diodes, while infrared detectors
come in the form of photodiodes and phototransistors. When an object reflects the infrared
energy emitted by the infrared source, it subsequently falls on the infrared detector for further
detection.
2. Sensor for Passive Infrared
Passive infrared sensors rely on infrared detectors. In contrast, they do not utilize infrared
sources. There are two main types of infrared detectors: thermal and quantum. Thermal
infrared sensors utilize infrared energy as the heat source and include thermocouples,
pyroelectric detectors, and bolometers. On the other hand, infrared quantum sensors offer
superior detection performance compared to thermal infrared detectors and are faster. The
sensitivity of quantum type detectors is influenced by the wavelength of the infrared energy.
Fig. 2.2.3.3 Illustration diagram of IR sensor
Working principle:
The operation of the IR sensor module is quite simple, comprising only two main
components: the IR transmitter and the IR receiver. In the receiver section, a photodiode is
employed to receive the infrared signal, while an IR LED is utilized in the transmitter part to
transmit it. After undergoing signal processing and conditioning, the output is obtained. The
IR proximity sensor generates infrared light by supplying voltage to the onboard infrared
light-emitting diode. This emitted light travels through the atmosphere, interacts with an
object, and is subsequently reflected into the photodiode sensor.

Fig. 2.2.3.4 Interfacing diagram of IR sensor with Arduino

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

Interfacing IR Sensor with Arduino:

Fig. 2.2.3.5 Illustration diagram of IR sensor with Arduino

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:

Fig. 2.2.3.6 Response diagram of IR sensor with Arduino


Self-Assessment Questions

11. Infrared (IR) sensors are commonly used to detect:


a. Changes in temperature
b. Changes in humidity
c. Changes in light intensity
d. Presence or absence of objects
12. What is the primary working principle of an IR sensor?
a. It emits infrared light to detect objects.
b. It detects changes in temperature using infrared radiation.
c. It emits and receives infrared light to detect the presence or absence of objects.
d. It measures changes in humidity using infrared signals.
13. Which Arduino function is commonly used to read the digital output from an IR sensor?
a. digitalRead()
b. analogRead()
c. digitalWrite()
d. analogWrite()
14. The output of an IR sensor is typically in the form of:
a. Analog voltage
b. Digital voltage (HIGH or LOW)
c. Temperature readings in degrees Celsius
d. Sound signals
15. IR sensors are commonly used in remote controls because they:
a. Emit infrared light to control devices.
b. Emit radiofrequency signals to control devices.
c. Detect infrared signals from the device being controlled.
d. Measure the temperature of the device being controlled.
2.2.4 PIR Sensors
In the dynamic and ever-changing world of the Internet of Things (IoT), various sensors play
a vital role in data collection and enabling intelligent interactions among devices. One such
sensor that has gained significant popularity is the Passive Infrared (PIR) sensor. PIR sensors
are widely embraced in IoT applications due to their ability to detect human presence and
movement. The PIR sensor, short for "passive infrared sensor," is specifically designed to
measure infrared light emitted by objects like the human body or animals, enabling it to
effectively detect living beings' movement within a fixed range.
Essentially, all objects with temperatures above absolute zero emit heat energy in the form of
infrared (IR) radiation. The hotter the object, the more IR radiation it emits. As IR radiation
falls outside the spectrum visible to the human eye, it remains unnoticed. The PIR sensor is
meticulously designed to detect and measure these levels of infrared radiation. As a result,
PIR sensors are widely utilized in motion detectors, security alarms, and automatic lighting-
based applications, making them an indispensable component in the realm of IoT.

Fig. 2.2.4.1 PIR sensor

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:

Fig. 2.2.4.3 Characteristics of PIR sensor


a. Detection Range and Angle: PIR sensors come with a restricted detection range and field of
view. The range may vary from a few meters to tens of meters, while the detection angle
typically ranges from 90 to 180 degrees.
b. Sensitivity and Sensing Modes: PIR sensors provide the convenience of adjustable
sensitivity levels, enabling them to detect both subtle and robust movements. They can be
operated in different sensing modes, such as single-element, dual-element, and quad-element
configurations, offering varying levels of accuracy and reliability.
Fig. 2.2.4.4 Working of PIR sensor
c. Response Time: PIR sensors demonstrate a rapid response time, usually spanning from a
few milliseconds to a few seconds, depending on the sensor's design and the application's
requirements.
d. Power Consumption: PIR sensors are intentionally engineered to be energy-efficient,
consuming minimal power during operation. This quality makes them ideal for integration
into battery-powered IoT devices, ensuring extended battery life and reducing the need for
frequent replacements or recharging.
Applications of PIR Sensors in IoT:
a. Smart Homes: PIR sensors are essential for energy-efficient lighting control in smart
homes. By detecting human presence, they adjust lighting intensity, reducing energy
consumption and providing convenient automation.
b. Security Systems: PIR sensors play a crucial role in intruder detection systems, triggering
alarms, activating surveillance cameras, and sending alerts to homeowners or security
personnel when unauthorized movements are detected. This enhances the security of both
residential and commercial properties.
c. Occupancy Monitoring: PIR sensors are extensively used in commercial buildings to
monitor occupancy in areas like meeting rooms, restrooms, and parking lots. This data helps
optimize space utilization and resource management, leading to improved efficiency and cost
savings.
d. Healthcare: PIR sensors have practical applications in healthcare settings for patient
monitoring, fall detection, and activity tracking. They can be integrated into wearable devices
or smart home setups to provide real-time health-related information and enhance patient
care.
e. Retail Analytics: PIR sensors are employed in retail environments to analyze customer
behavior, footfall, and dwell time. This data aids in optimizing store layouts, product
placements, and marketing strategies, ultimately improving customer experiences and overall
store performance.
f. Smart Lighting in Public Spaces: PIR sensors are utilized in streetlights and public areas to
control lighting based on human presence. By providing adequate illumination only when
required, these sensors ensure energy efficiency and enhance safety in public spaces.

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

Disadvantages of PIR sensor


 They have lower sensitivity and less coverage compare to microwave sensors.
 It works effectively in LOS (Line of Sight) and will have problems in the
corner regions.
 It is insensitive to very slow motion of the objects.
Interfacing PIR SENSOR with Arduino Uno:

Fig. 2.2.4.5 Interfacing of PIR sensor with Arduino


Program:
int sensorState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
// read the state of the sensor/digital input
sensorState = digitalRead(2);
// check if sensor pin is HIGH. if it is, set the
// LED on.
if (sensorState == HIGH) {
digitalWrite(LED_BUILTIN, HIGH);
} else {
digitalWrite(LED_BUILTIN, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Response:

Fig. 2.2.4.6 Response of PIR sensor with Arduino

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.

17. How does a PIR sensor detect motion?


a. It emits infrared light and measures the time it takes for the light to return after
reflecting off an object.
b. It emits ultrasonic waves and measures their reflection from objects.
c. It detects changes in the ambient temperature caused by the motion of objects.
d. It emits and receives infrared radiation to detect moving objects.
18. Which Arduino function is commonly used to read the digital output from a PIR sensor?
a. digitalRead()
b. analogRead()
c. digitalWrite()
d. analogWrite()

19. PIR sensors are commonly used in applications such as:


a. Weather monitoring
b. Line-following robots
c. Intrusion detection systems and automatic lighting
d. Distance measurement

20. The output of a PIR sensor is typically in the form of:


a. Analog voltage
b. Digital voltage (HIGH or LOW)
c. Temperature readings in degrees Celsius
d. Sound signals
2.2.5 Ultrasonic Sensors
Ultrasonic sensors have become highly versatile and extensively adopted sensing
technologies, revolutionizing how we interact with our surroundings. These sensors use
sound waves beyond the human hearing range to detect and measure distances to objects. The
non-contact nature and adaptability of ultrasonic technology make it invaluable across
various applications, spanning from automotive to healthcare and industrial automation.
Types of Ultrasonic Sensors
There are two main types of ultrasonic sensors commonly used:
1. Ultrasonic Proximity Sensors: Ultrasonic sensors are used to detect the presence of objects
within a specific range. They find widespread applications in various fields, including object
detection, collision avoidance in robotics, and automatic door systems.
2 Ultrasonic Distance Sensors: Ultrasonic sensors are highly precise in measuring the
distance between the sensor and an object. Their applications are diverse and span across
industries, including automotive parking assistance, level measurement, and distance
monitoring in industrial automation.

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.

Fig. 2.2.5.1 Ultrasonic sensor


After emission, the ultrasonic waves travel through the air in a straight path until they
encounter an object. Upon striking the object, they bounce back and return to the sensor. The
receiver within the sensor captures these reflected waves and converts them back into
electrical signals.
Ultrasonic Sensor Pin Configuration

Pin Symbol Function


1 Vcc Power Supply
2 Trig Triggering Signal
3 Echo Echo Receiver
4 GND Signal Ground

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.

Fig. 2.2.5.2 Functioning of Ultrasonic sensor

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

Fig. 2.2.5.3 Interfacing of Ultrasonic sensor with Arduino

Applications of Ultrasonic Sensors


The versatility and precision of ultrasonic sensors have sparked their integration into various
industries, transforming processes, and improving safety and efficiency. Notably, they find
applications in:
Automotive and Autonomous Vehicles: Ultrasonic sensors are crucial in modern automotive
technology. In parking assistance systems, they aid drivers in safely maneuvering their
vehicles by offering real-time distance feedback and obstacle warnings. In autonomous
vehicles, these sensors work in conjunction with LiDAR and cameras to ensure accurate
object detection and collision avoidance.
Industrial Automation: Ultrasonic sensors are employed in industrial settings for level
measurement, detecting liquid levels in tanks, and object positioning. They offer precise and
reliable monitoring of materials, optimizing processes, and preventing storage tank overflows
or shortages.
Healthcare and Medical Devices: In the healthcare sector, ultrasonic sensors play a crucial
role in various medical devices and applications. Ultrasound technology allows doctors to
visualize internal organs and tissues in medical imaging. Additionally, these sensors are used
in non-invasive blood flow measurement and distance monitoring during surgical procedures,
enhancing patient care and safety.
Smart Home and Consumer Electronics: Ultrasonic sensors contribute to enhanced user
experiences in smart homes and consumer electronics. They enable gesture recognition in
touchless control devices, interactive gaming, and virtual reality applications. Additionally,
ultrasonic proximity sensors are utilized in automatic hand sanitizers and soap dispensers,
promoting hygienic practices in public spaces.
Robotics and Automation: Ultrasonic sensors are extensively used in robotics to detect
objects and avoid collisions, enhancing safety in robotic operations. They enable robots to
navigate complex environments with accuracy, efficiency, and reduced human intervention.

Interfacing Ultrasonic Sensor with Arduino

Fig. 2.2.5.4 Working model of Ultrasonic sensor with Arduino


Program:
const int pingPin = 7;
const int ledPin = 13;
void setup() {
// initialize serial communication:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
long duration, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
Serial.print("Distance: ");

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.5.4 Response of Ultrasonic sensor with Arduino


Self-Assessment Questions
21. What is the primary function of an Ultrasonic Sensor?
a. Measuring the intensity of light.
b. Detecting changes in temperature.
c. Sensing motion and presence of objects.
d. Measuring the distance between objects.
22. How does an Ultrasonic Sensor measure distance?
a. It emits ultrasonic waves and measures the time it takes for the waves to return after
reflecting off an object.
b. It emits infrared light and measures the time it takes for the light to return after
reflecting off an object.
c. It detects changes in the ambient temperature caused by the motion of objects.
d. It emits and receives radiofrequency signals to detect moving objects.
23. Which Arduino function is commonly used to read the distance measurement from an
Ultrasonic Sensor?
a. ultrasonicRead()
b. analogRead()
c. digitalRead()
d. pulseIn()
24. Ultrasonic sensors are commonly used in applications such as:
a. Weather monitoring
b. Line-following robots
c. Distance measurement and object avoidance
d. Intrusion detection systems

25. The output of an Ultrasonic Sensor is typically in the form of:


a. Analog voltage
b. Digital voltage (HIGH or LOW)
c. Distance measurement in centimeters or inches
d. Sound signals
2.2.6 Gas Sensors
Gas sensors play a vital role in the Internet of Things (IoT) as they facilitate the detection and
monitoring of various gases in the environment. These sensors are essential elements in smart
systems, ensuring safety, environmental monitoring, and industrial automation. In IoT
applications, gas sensors provide real-time data on air quality, hazardous gas leaks, and
emissions, enabling prompt responses and informed decision-making.
Working with IoT:
Gas sensors integrated into IoT devices employ diverse detection technologies, including
electrochemical, semiconductor, and infrared sensors. Each sensor type is tailored to detect
specific gases based on their distinct properties. When the sensor comes into contact with the
target gas, it undergoes a chemical or physical transformation, generating an electrical signal
proportional to the gas concentration.
The gathered data from gas sensors is subsequently transmitted to IoT platforms and cloud-
based systems for analysis and visualization. IoT applications can utilize this information to
activate alerts, regulate ventilation systems, and implement safety protocols, establishing gas
sensors as indispensable devices in guaranteeing air quality and safety.

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.

Fig. 2.2.6.2 Operational diagram of Gas sensor

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:

Fig. 2.2.6.3 Interfacing diagram of MQ2 Gas sensor with Arduino


Applications of Gas Sensors in IoT
Gas sensors are widely employed in the Internet of Things (IoT) across diverse industries and
domains. Some notable applications include:
Environmental Monitoring: Gas sensors in IoT systems are utilized for environmental
monitoring to detect pollutants, including carbon monoxide (CO), nitrogen dioxide (NO2),
ozone (O3), and volatile organic compounds (VOCs). Monitoring air quality in urban areas,
industrial zones, and indoor spaces helps identify pollution sources and devise strategies for
improved air quality.
Industrial Safety and Automation: In industrial settings, gas sensors play a critical role in
ensuring workplace safety by detecting toxic, flammable, and explosive gases. Early
detection of gas leaks can prevent accidents and potential hazards, safeguarding workers and
facilities. Additionally, gas sensors assist in automating ventilation systems and other safety
measures for enhanced industrial operations.
Smart Homes and Buildings: Gas sensors are integrated into smart home and building
systems for monitoring indoor air quality. They detect harmful gases and trigger alerts or
actions to maintain a healthy and comfortable living environment. IoT-based gas sensors in
smart homes ensure timely responses to potential gas leaks or hazardous conditions,
promoting peace of mind for occupants.
Healthcare and Medical Applications: In medical facilities, gas sensors play a crucial role in
monitoring anesthesia gases during surgical procedures and detecting the presence of gases in
patients' breath, providing valuable insights into respiratory health. IoT-enabled gas sensors
contribute to improved patient safety and enable accurate diagnosis in medical settings. These
sensors enhance the monitoring and management of gas concentrations, ensuring optimal
patient care and safety during medical procedures.
Agricultural and Environmental Monitoring: Gas sensors also find significant applications in
agricultural and environmental monitoring. In agriculture, these sensors aid in monitoring
greenhouse gases and other environmental factors to optimize crop growth and reduce
emissions. By providing real-time data on gas concentrations in the soil and atmosphere,
farmers can make informed decisions for sustainable agriculture practices and ensure efficient
resource management. These sensors contribute to environmentally friendly farming practices
and play a vital role in promoting sustainable agriculture.
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:

Fig. 2.2.6.4 Output of MQ2 Gas sensor with Arduino

Self-Assessment Questions

26. What is the primary function of a Gas Sensor?


a. Measuring the intensity of light.
b. Detecting changes in temperature.
c. Sensing motion and presence of objects.
d. Detecting the presence of specific gases in the environment.

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()

29. Gas sensors are commonly used in applications such as:


a. Weather monitoring
b. Air quality monitoring and gas leakage detection
c. Distance measurement and object avoidance
d. Intrusion detection systems

30. The output of a gas sensor is typically in the form of:


a. Analog voltage
b. Digital voltage (HIGH or LOW)
c. Gas concentration in parts per million (ppm) or percentage (%)
d. Sound signals
Summary
By connecting sensors to an Arduino board, users can gather data from the surrounding
environment and use it for automation, monitoring, or control purposes.

Here is a summary of sensors interfacing with Arduino and their implementation in various
applications:

1. Light Sensors (e.g., LDR, TSL2561, BH1750):

Detect ambient light intensity.

Applications: Smart lighting, automatic street lighting, daylight harvesting.

2. Motion Sensors (e.g., PIR, HC-SR501):

Detect movement or motion in their vicinity.

Applications: Security systems, automatic lighting, intruder detection.

3. Gas Sensors (e.g., MQ-2, MQ-7, MQ-135):

Detect specific gases like LPG, CO, CO2, etc.

Applications: Gas leakage detection, air quality monitoring, safety alarms.

4. Distance Sensors (e.g., Ultrasonic HC-SR04, Infrared Sharp GP2Y0A21YK0F):

Measure the distance between the sensor and an object.

Applications: Proximity detection, obstacle avoidance, robotics.


Terminal Questions
Answer Keys
Self-Assessment Questions

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.

2. IR sensor interfacing with actuators, such as motors or LEDs

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.

4. Build a security alarm: If motion is detected, trigger an audible alarm or send a


notification to your smartphone using additional components like a buzzer or Wi-Fi
module
Glossary
Arduino: An open-source microcontroller platform that enables easy programming and
interfacing with various sensors and actuators.

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.

You might also like