You are on page 1of 34

U21ECG04 -Internet

of Things and its


Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

UNIT III: INTERFACING SENSORS AND ACTUATORS


Programming and interfacing with sensors-Temperature, Humidity, water, MQ2, PIR, Ultrasonic –
Magnetic relay switches-Actuators-Servo motor-Stepper motor

PROGRAMING AND INTERFACING WITH SENSORS

TEMPERATURE SENSOR

A temperature sensor is a device, typically, a thermocouple or resistance temperature detector, that


provides temperature measurement in a readable form through an electrical signal.A thermometer is
the most basic form of a temperature meter that is used to measure the degree of hotness and
coolness. Temperature meters are used in the geotechnical field to monitor concrete, structures, soil,
water, bridges, etc. for structural changes in due to seasonal variations.A thermocouple (T/C) is made
from two dissimilar metals that generate an electrical voltage in direct proportion to the change in
temperature. An RTD (Resistance Temperature Detector) is a variable resistor that changes its
electrical resistance in direct proportion to the change in the temperature in a precise, repeatable, and
nearly linear manner.

What do temperature sensors do?

A temperature sensor is a device that is designed to measure the degree of hotness or coolness in an
object. The working of a temperature meter depends upon the voltage across the diode. The
temperature change is directly proportional to the diode’s resistance. The cooler the temperature, the
lesser will be the resistance, and vice-versa. The resistance across the diode is measured and
converted into readable units of temperature (Fahrenheit, Celsius, Centigrade, etc.) and, displayed in
numeric form over readout units. In the geotechnical monitoring field, these temperature sensors are
used to measure the internal temperature of structures like bridges, dams, buildings, power plants,
etc.

What are the functions of a temperature sensor?

Well, there are many types of temperature sensors, but, the most common way to categorize them is
based on the mode of connection which includes, contact and non-contact temperature
sensors.Contact sensors include thermocouples and thermistors because they are in direct contact with
the object they are to measure. Whereas, the non-contact temperature sensors measure the thermal
radiation released by the heat source. Such temperature meters are often used in hazardous
environments like nuclear power plants or thermal power plants.In geotechnical monitoring,
temperature sensors measure the heat of hydration in mass concrete structures. They can also be used
to monitor the migration of groundwater or seepage. One of the most common areas where they are
used is while curing the concrete because it has to be relatively warm in order to set and cure

Prepared By: CSE Department, KPRIET, Coimbatore. Page 1


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

properly. The seasonal variations cause structural expansion or contraction thereby, changing its
overall volume.

How does a temperature sensor work?

The basic principle of working the temperature sensors is the voltage across the diode terminals. If
the voltage increases, the temperature also rises, followed by a voltage drop between the transistor
terminals of the base and emitter in a diode.Besides this, Encardio Rite has a vibrating wire
temperature sensor that works on the principle of stress change due to temperature change.The
vibrating wire temperature meter is designed on the principle that dissimilar metals have a different
linear coefficient of expansion with temperature variation.It primarily consists of a magnetic, high
tensile strength stretched wire, the two ends of which are fixed to any dissimilar metal in a manner
that any change in temperature directly affects the tension in the wire and, thus, its natural frequency
of vibration.The dissimilar metal, in the case of the Encardio Rite temperature meter, is aluminum
(Aluminum has a larger coefficient of thermal expansion than steel.) As the temperature signal is
converted into frequency, the same read-out unit which is used for other vibrating wire sensors can
also be used for monitoring temperature also.

The change in temperature is sensed by the specially built Encardio Rite vibrating wire sensor and is
converted to an electrical signal which is transmitted as a frequency to the read-out unit.The
frequency, which is proportional to the temperature and in turn to the tension ‘σ’ in the wire, can be
determined as follows:

f = 1/2 [σg/ρ] / 2l Hz

Where:

σ = tension of the wire

g = acceleration due to gravity

ρ = density of the wire

l = length of wire

What are the different types of temperature sensors?

Temperature sensors are available in various types, shapes, and sizes. The two main types of
temperature sensors are:

Contact Type Temperature Sensors: There are a few temperature meters that measure the degree of
hotness or coolness in an object by being in direct contact with it. Such temperature sensors fall under

Prepared By: CSE Department, KPRIET, Coimbatore. Page 2


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

the category of contact type. They can be used to detect solids, liquids, or gases over a wide range of
temperatures.

Non-Contact Type Temperature Sensors: These types of temperature meters are not in direct contact
with the object rather, they measure the degree of hotness or coolness through the radiation emitted
by the heat source.

LM35 Temperature Sensor Pinout

Reference-circuit digest

VCC is the power supply pin of the LM35 temperature sensor IC that can be connected to 4V or
32V of the supply.

GND is the ground pin of the LM35 temperature sensor IC and it should be connected to the supply
ground.

OUT This is the temperature sensor analog output pin. This is the analog output pin of the
temperature sensor, the output voltage on this pin is directly proportional to the temperature.

LM35 Temperature Sensor

The LM35 is a low-power, low-cost, high-precision temperature sensor designed and manufactured
by Texas instruments. This IC provides a voltage output that is linearly proportional to the change in
temperature.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 3


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Reference-circuit digest

The LM35 sensor is moderately precise and its robust construction makes it suitable for various
environmental conditions. Additionally, you don't need any external component to calibrate this
circuit and it has a typical accuracy of ±0.5°C at room temperature and ±1°C over a full −55°C to
+155°C temperature range. It has an operating voltage of 4V to 30V and consumes 60-uA current
while it's in working state, this also makes it perfect for battery-powered applications.

There are two disadvantages of this sensor. The first big disadvantage of this sensor is that it cannot
measure negative temperature, for that you have to bias it with a dual polarity supply. If your project
requires negative temperature measurements, you can opt for a LM36 sensor. The second
disadvantage of this sensor is that it's very sensitive to noise because it outputs data in analog format.
If you want to learn more about this sensor you can check out the Datasheet of LM35 Temperature
Sensor IC.

How the LM35 Temperature Sensor Measures Temperature:

The LM35 temperature sensor uses the basic principle of a diode to measure known temperature
value. As we all know from semiconductor physics, as the temperature increases the voltage across a
diode increases at a known rate. By accurately amplifying the voltage change, we can easily generate
a voltage signal that is directly proportional to the surrounding temperature. The screenshot below
shows the internal schematic of LM35 temperature sensor IC according to the datasheet.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 4


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

In practice, this diode that they are using to measure the temperature is not actually a PN Junction
diode but its a diode-connected transistor. That is why the relationship between the forward voltage
and the transistor is so linear. The temperature coefficient vs collector current graph below gives you
a better understanding of the process.

How does the LM35 Temperature Sensor Works in our Circuit

Prepared By: CSE Department, KPRIET, Coimbatore. Page 5


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

The working of the LM35 Temperature Sensor is very simple and easy to understand. We just
have to connect 5V and Ground to the sensor and we need to measure the output voltage from the
output pin.

Taken from-circuit digest

According to the datasheet of the device, the sensor should give us 10mv/°C. So, if the temperature of
the room is 18°C then the sensor should give us 180mV at the output pin.

Arduino LM35 Temperature Sensor Circuit Diagram

Now that we have understood how the LM35 Temperature Sensor works we can connect all the
required wires to Arduino UNO. The arduino lm35 connection diagram is shown below-

Taken from-circuit digest

Prepared By: CSE Department, KPRIET, Coimbatore. Page 6


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Connecting the LM35 sensor to the Arduino is really simple. You just need to connect 5V power to
the sensor and you need to connect the output of the sensor to the A0 pin of the Arduino. Once the
connection is done you need to write the code to convert the output voltage of the sensor to
temperature data. For that, first, you need to convert the ADC values to voltage and multiply that
voltage to 10 and you will get the output in temperature. With that, you’re now ready to upload the
code to Arduino. An image showing the actual Arduino LM35 hardware setup is shown below.

Arduino LM35 Temperature Sensor Code

The Arduino Code for Interfacing the LM35 Temperature Sensor is very simple and easy to
understand. We just need to read the analog data out of the sensor and convert it to temperature data.

We Initialize our code by defining the pin in which the LM35 Temperature sensor is connected.

#define sensor_pin A0 // LM35 is connected to this PIN

Next, we have our setup() function, in the setup, we just need to initialize the serial monitor for
debugging.

void setup() {

// Init serial at 9600 baud

Serial.begin(9600);

Next we have our loop function, in the loop function we read the pin and store the ADC data in
adcData variable. Next, we convert the ADC data to the voltage value and store it in a local variable
named voltage, and finally, we convert the voltage value to temperature and store it in a variable
named temperature and print that in the serial monitor window. At last, we added 800ms and finished
the code.

void loop() {

//Read Raw ADC Data

int adcData = analogRead(sensorPin);

// Convert that ADC Data into voltage

float voltage = adcData * (5.0 / 1024.0);

// Convert the voltage into temperature

Prepared By: CSE Department, KPRIET, Coimbatore. Page 7


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

float temperature = voltage * 100;

// Print the temperature data

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println("*C");

delay(800); // wait a second between readings

Humidity Sensor is one of the most important devices that has been widely in consumer, industrial,
biomedical, and environmental etc. applications for measuring and monitoring Humidity.Humidity is
defined as the amount of water present in the surrounding air. This water content in the air is a key
factor in the wellness of mankind. For example, we will feel comfortable even if the temperature is
00C with less humidity i.e. the air is dry.But if the temperature is 100C and the humidity is high i.e.
the water content of air is high, then we will feel quite uncomfortable. Humidity is also a major factor
for operating sensitive equipment like electronics, industrial equipment, electrostatic sensitive devices
and high voltage devices etc. Such sensitive equipment must be operated in a humidity environment
that is suitable for the device.

Important Terms Related to Humidity

Moisture: Generally, the term Moisture means water content of any material or substance. But
practically, the term Moisture refers to the water content in solids and liquids. The term Humidity
refers to the water content in gases (air).Absolute Humidity: Absolute Humidity (AH) is the ratio of
mass of the water vapour to the volume of the air. If m is the mass of the water vapour and V is the
total volume i.e. volume of air and water vapour mixture, then Absolute Humidity AH is given by

AH = m/V

Absolute Humidity doesn’t take temperature in to account but it changes with temperature and
pressure.
Relative Humidity: Whenever we talk about measuring Humidity, it usually Relative Humidity that
we are talking about (unless otherwise specified).Relative Humidity or RH is the ratio of the actual
water vapour pressure present in the air at a temperature to the maximum water vapour pressure
present in the air at the same temperature.In weather reports and forecasts, the probability of
precipitation or dew or fog is indicated using Relative Humidity and hence, it is considered an
important metric.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 8


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Relative Humidity takes both temperature and pressure in to consideration. Hence, the Humidity
Sensors which measure Relative Humidity, measure both the moisture content as well as the air
temperature.

Specific Humidity: Specific Humidity (SH) is the ratio of mass of the water vapor to the total mass of
the air.
Mixing Ratio or Humidity Ratio: Mixing Ratio is the ratio of mass of the water vapor to mass of the
dry air.

Dew Point Temperature: Dew Point Temperature is the temperature at with the water vapor content is
saturated in the air. At Dew Point temperature, the Relative Humidity RH is 100%. In other words,
for the air to hold maximum amount of water vapor (or moisture), it has to reach Dew Point
Temperature.

Humidity Sensors – Classification and Working Principles

Humidity Sensors are very important devices that help in measuring the environmental humidity.
Technically, the device used to measure the humidity of the atmosphere is called Hygrometer.
Humidity Sensors or Hygrometers can be classified based on the type of humidity it is used for
measuring i.e.

Absolute Humidity (AH) sensors or Relative Humidity (RH) sensors. Humidity Sensors can also be
classified based on the parameter used for measuring Humidity i.e. Capacitive Humidity Sensors,
Electrical Conductivity (or Resistive) Humidity Sensors and Thermal Conductivity Humidity
Sensors.

There are other types of Humidity Sensors or Hygrometers like Optical Hygrometer, Oscillating
Hygrometer and Gravimetric Hygrometer.

Let us see about different types of Humidity Sensors or Hygrometers along with their working
principles.

Capacitive Humidity Sensors

Humidity Sensors based on capacitive effect or simply Capacitive Humidity Sensors are one of the
basic types of Humidity Sensors available.

They are often used in applications where factors like cost, rigidity and size are s of concern. In
Capacitive Relative Humidity (RH) Sensors, the electrical permittivity of the dielectric material
changes with change in humidity.

Working of Capacitive RH Sensors

Prepared By: CSE Department, KPRIET, Coimbatore. Page 9


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

A simple Capacitive RH Sensor can be made from an air filled capacitor as the moisture in the
atmosphere changes its permittivity. But for practical applications, air as a dielectric is not feasible.

Hence, the space between the capacitor plates is usually filled with an appropriate dielectric material
(isolator), whose dielectric constant varies when it is subjected to change in humidity.

The common method of constructing a capacitive RH sensor is to use a hygroscopic polymer film as
dielectric and depositing two layers of electrodes on the either side.

Another way to use the capacitive RH sensors is to observe the changes in the frequency of the
oscillator constructed using a capacitor with RH sensitive test subject as dielectric. This setup is often
employed in pharmaceutical products.

The test samples like medical tablets are placed between two plates (which form the capacitor
electrodes) to form a capacitor in the LC Oscillator circuit. The frequency of the oscillator changes
with humidity surrounding the test sample.

Let us see the construction of a thin thermostat polymer film based capacitive RH Sensor. It is
fabricated on a silicon substrate. On this substrate, two metal electrodes made of either aluminium,
platinum or chromium are deposited. The shape of these electrodes is carved out such that, the
electrodes form an interdigitized pattern.

On top of this layer, a dielectric layer is deposited. The following image shows a top and cross
section view of the capacitive humidity sensor. Note that two temperature sensitive resistors are
deposited on the same substrate to provide temperature compensation.

Advantages of Capacitive Humidity Sensors

The output voltage is near linear.

They provide stable results over long usage.

Can detect wide range of RH.

Disadvantages of Capacitive Humidity Sensors

The distance from the sensor and signalling circuit is very limited.

Applications of Capacitive Humidity Sensors

Capacitive Humidity Sensors are used in a wide range of applications including but not limited to:

HVAC Systems

Prepared By: CSE Department, KPRIET, Coimbatore. Page 10


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Printers and Fax Machines

Weather Stations

Automobiles

Food Processing

Refrigerators, Ovens and Dryers

Resistive Humidity Sensors (Electrical Conductivity Sensors)

Resistive Humidity Sensors are another important type of Humidity Sensors that measure the
resistance (impedance) or electrical conductivity. The principle behind resistive humidity sensors is
the fact that the conductivity in non – metallic conductors is dependent on their water content.

Working of Resistive Humidity Sensors

The Resistive Humidity Sensor is usually made up of materials with relatively low resistivity and this
resistivity changes significantly with changes in humidity. The relationship between resistance and
humidity is inverse exponential. The low resistivity material is deposited on top of two electrodes.

The electrodes are placed in interdigitized pattern to increase the contact area. The resistivity between
the electrodes changes when the top layer absorbs water and this change can be measured with the
help of a simple electric circuit.

Some of the commonly used materials are salt, specially treated substrates, solid polyelectrolytes and
conductive polymers. Modern Resistive Humidity Sensors are coated with ceramic substance to
provide extra protection. The electrodes in the sensor are usually made of noble metals like gold,
silver or platinum.

Advantages of Resistive Humidity Sensors

Low cost

Small Size

The distance between the sensor and signal circuit can be large (suitable for remote operations).

Highly interchangeable as there are no calibration standards.

Disadvantages of Resistive Humidity Sensors

Resistive Humidity Sensors are sensitive to chemical vapors and other contaminants

Prepared By: CSE Department, KPRIET, Coimbatore. Page 11


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

The output readings may shift if used with water soluble products.

Applications of Resistive Humidity Sensors

Resistive or Electrical Conductive Humidity sensors are low cost sensors with relatively small size.
They are often used in several industrial, domestic or residential and commercial applications.

Thermal Conductivity Humidity Sensors

Thermal Conductivity Humidity Sensors are also known as Absolute Humidity (AH) Sensors as they
measure the Absolute Humidity. Thermal Conductivity Humidity Sensors measure the thermal
conductivity of both dry air as well as air with water vapor. The difference between the individual
thermal conductivities can be related to absolute humidity.

Working of Thermal Conductivity Humidity Sensors

The best component to accomplish thermal conductivity based humidity sensor is thermistor. Hence,
two tiny thermistors with negative temperature coefficient are used to for a bridge circuit.

In that, one thermistor is hermetically sealed in a chamber filled with dry Nitrogen while the other is
exposed to open environment through small venting holes. When the circuit is powered on, the
resistance of the two thermistors are calculated and the difference between those two values is
directly proportional to Absolute Humidity (AH).

Advantages of Thermal Conductivity Humidity Sensors

Suitable for high temperature environments and high corrosive situations.

Very durable

Higher resolution compared to other types

Disadvantage of Thermal Conductivity Humidity Sensors

Exposure to any gas with thermal properties different than Nitrogen might affect reading
measurement.

Applications of Thermal Conductivity Humidity Sensors

Some of the common applications of Thermal Conductivity Humidity Sensors are:

Drying kilns

Pharmaceutical plants

Owens

Prepared By: CSE Department, KPRIET, Coimbatore. Page 12


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Clothes dryers and drying machines

Food dehydration

Important Considerations when Selecting a Humidity Sensor

The following are some of the factor that must be taken into consideration when selecting a Humidity
Sensor.

Accuracy of the sensor.

Calibration – requirements and methods

Size of the sensor

Cost of the sensor and cost of replacement

Output repeatability

Circuit complexity

Resistance to contamination

Reliability of the sensor

water level sensor

The water level sensor is a device that measures the liquid level in a fixed container that is too high or
too low. According to the method of measuring the liquid level, it can be divided into two types:
contact type and non-contact type. The input type water level transmitter we call is a contact
measurement, which converts the height of the liquid level into an electrical signal for output. It is
currently a widely used water level transmitter.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 13


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

How does the water level sensor work?

The working principle of the water level sensor is that when it is put into a certain depth in the liquid
to be measured, the pressure on the sensor’s front surface is converted into the liquid level height.
The calculation formula is Ρ=ρ.g.H+Po, in the formula P is the pressure on the liquid surface of the
sensor, ρ is the density of the liquid to be measured, g is the local acceleration of gravity, Po is the
atmospheric pressure on the liquid surface, and H is the depth at which the sensor drops into the
liquid.

The level sensor is a device designed to monitor and measure liquid (and sometimes solid) levels.
When the liquid level is detected, the sensor converts the sensed data into an electrical signal. Level
sensors are mainly used for monitoring reservoirs, oil tanks or rivers

Where to use water level sensors?

The uses of water level sensors include the following applications:


1. Water level measurement of pools and water tanks
2. Water level measurement of rivers and lakes
3. Marine level measurement
4. Level measurement of acid-base liquids
5. Oil level measurement of oil trucks and mailboxes
6. Swimming pool water level control
7. Tsunami warning and sea-level monitoring
8. Cooling tower water level control
9. Sewage pump level control
10. Remote monitoring of the liquid level

What are the benefits of water level sensors?

1. Simple structure: There are no movable or elastic elements, so the reliability is extremely high,
and there is no need for regular maintenance during use. The operation is simple and convenient.
2. Convenient installation: When using, first connect one end of the wire correctly, and then put the
other end of the water level probe into the solution to be measured.
3. Ranges are optional: you can measure the water level in the range of 1-200 meters, and other
measurement ranges can also be customized.
4. Wide range of applications: suitable for liquid level measurement of high temperature and high
pressure, strong corrosion, high pollution, and other media. Building an electronic water level
gauge on the river bank can be used for tide monitoring.
5. Wide range of measuring medium: High-precision measurement can be carried out from the
water, oil to paste with high viscosity, and wide-range temperature compensation is not affected by

Prepared By: CSE Department, KPRIET, Coimbatore. Page 14


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

the foaming, deposition, and electrical characteristics of the measured medium.


6. Long service life: Generally, the liquid level sensor can be used for 4-5 years in a normal
environment, and it can also be used for 2-3 years in a harsh environment.
7. Strong function: It can be directly connected to the digital display meter to display the value in
real-time, or it can be connected to a variety of controllers and set the upper and lower limits to
control the water volume in the container.
8. Accurate measurement: The built-in high-quality sensor has high sensitivity, fast response, and
accurately reflects the subtle changes of the flowing or static liquid level, and the measurement
accuracy is high.
9. Variety of types: liquid level sensors have various structural designs such as input type, straight
rod type, flange type, thread type, inductive type, screw-in type, and float type. It can meet the
measurement needs of all different places.

What are the types of water level sensors?

Here are 7 types of liquid level sensors for your reference:

1. Optical water level sensor

The optical sensor is solid-state. They use infrared LEDs and phototransistors, and when the sensor is
in the air, they are optically coupled. When the sensor head is immersed in the liquid, the infrared
light will escape, causing the output to change. These sensors can detect the presence or absence of
almost any liquid. They are not sensitive to ambient light, are not affected by foam when in air, and
are not affected by small bubbles when in liquid. This makes them useful in situations where state
changes must be recorded quickly and reliably, and in situations where they can operate reliably for
long periods without maintenance.

Advantages: non-contact measurement, high accuracy, and fast response.


Disadvantages: Do not use under direct sunlight, water vapor will affect the measurement accuracy.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 15


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

2. Capacitance liquid level sensor

Capacitance level switches use 2 conductive electrodes (usually made of metal) in the circuit, and the
distance between them is very short. When the electrode is immersed in the liquid, it completes the
circuit.

Advantages: can be used to determine the rise or fall of the liquid in the container. By making the
electrode and the container the same height, the capacitance between the electrodes can be measured.
No capacitance means no liquid. A full capacitance represents a complete container. The measured
values of “empty” and “full” must be recorded, and then 0% and 100% calibrated meters are used to
display the liquid level.
Disadvantages: The corrosion of the electrode will change the capacitance of the electrode, and it
needs to be cleaned or recalibrated.

3. Tuning fork level sensor

The tuning fork level gauge is a liquid point level switch tool designed by the tuning fork principle.
The working principle of the switch is to cause its vibration through the resonance of the piezoelectric
crystal.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 16


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Every object has its resonant frequency. The resonant frequency of the object is related to the size,
mass, shape, force… of the object. A typical example of the resonant frequency of the object is: the
same glass cup in a row Filling with water of different heights, you can perform instrumental music
performance by tapping.

Advantages: It can be truly unaffected by flow, bubbles, liquid types, etc., and no calibration is
required.
Disadvantages: Cannot be used in viscous media.

4. Diaphragm liquid level sensor

The diaphragm or pneumatic level switch relies on air pressure to push the diaphragm, which engages
with a micro switch inside the main body of the device. As the liquid level increases, the internal
pressure in the detection tube will increase until the microswitch is activated. As the liquid level
drops, the air pressure also drops, and the switch opens.

Advantages: There is no need for power in the tank, it can be used with many types of liquids, and
the switch will not come into contact with liquids.
Disadvantages: Since it is a mechanical device, it will need maintenance over time.

5.Float water level sensor

The float switch is the original level sensor. They are mechanical equipment. The hollow float is
connected to the arm. As the float rises and falls in the liquid, the arm will be pushed up and down.
The arm can be connected to a magnetic or mechanical switch to determine on/off, or it can be
connected to a level gauge that changes from full to empty when the liquid level drops.

The use of float switches for pumps is an economical and effective method to measure the water level
in the pumping pit of the basement.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 17


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Advantages: The float switch can measure any type of liquid and can be designed to operate without
any power supply.
Disadvantages: They are larger than other types of switches, and because they are mechanical, they
must be used more frequently than other level switches.

6. Ultrasonic liquid level sensor

The ultrasonic level gauge is a digital level gauge controlled by a microprocessor. In the
measurement, the ultrasonic pulse is emitted by the sensor (transducer). The sound wave is reflected
by the liquid surface and received by the same sensor. It is converted into an electrical signal by a
piezoelectric crystal. The time between the transmission and reception of the sound wave is used to
calculate the Measure of the distance to the surface of the liquid.

The working principle of the ultrasonic water level sensor is that the ultrasonic transducer (probe)
sends out a high-frequency pulse sound wave when it encounters the surface of the measured level
(material), is reflected, and the reflected echo is received by the transducer and converted into an
electrical signal. The propagation time of the sound wave. It is proportional to the distance from the
sound wave to the surface of the object. The relationship between the sound wave transmission
distance S and the sound speed C and the sound transmission time T can be expressed by the formula:
S=C×T/2.

Advantages: non-contact measurement, the measured medium is almost unlimited, and it can be
widely used for measuring the height of various liquids and solid materials.
Disadvantages: The measurement accuracy is greatly affected by the temperature and dust of the
current environment.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 18


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

7. Radar level gauge

A radar liquid level is a liquid level measuring instrument based on the principle of time travel. The
radar wave runs at the speed of light, and the running time can be converted into a level signal by
electronic components. The probe sends out high-frequency pulses that travel at the speed of light in
space, and when the pulses meet the surface of the material, they are reflected and received by the
receiver in the meter, and the distance signal is converted into a level signal.

Hardware Overview

The sensor has ten exposed copper traces, five of which are power traces and the remaining five are
sense traces. These traces are interlaced so that there is one sense trace between every two power
traces.Normally, power and sense traces are not connected, but when immersed in water, they are
bridged.

There is a Power LED on the board, which will light up when the board is powered.

Working Principle:

Prepared By: CSE Department, KPRIET, Coimbatore. Page 19


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

The power and sense traces form a variable resistor (much like a potentiometer) whose resistance
varies based on how much they are exposed to water.

This resistance varies inversely with the depth of immersion of the sensor in water:

The more water the sensor is immersed in, the better the conductivity and the lower the resistance.

The less water the sensor is immersed in, the poorer the conductivity and the higher the resistance.

The sensor generates an output voltage proportional to the resistance; by measuring this voltage, the
water level can be determined.

Water Sensor Pin out :

Taken from-lastminuteengineer.com

S (Signal) is an analog output pin that will be connected to one of your Arduino’s analog inputs.

+ (VCC) pin provides power to the sensor. It is recommended that the sensor be powered from 3.3V
to 5V. Please keep in mind that the analog output will vary depending on the voltage supplied to the
sensor.

– (GND) is the ground pin.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 20


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

// Sensor pins pin D6 LED output, pin A0 analog Input

#define ledPin 6

#define sensorPin A0

void setup() {

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

void loop() {

int sensorValue = analogRead(sensorPin);

if (sensorValue > 570) {

int outputValue = map(sensorValue, 570, 800, 0, 255);

Prepared By: CSE Department, KPRIET, Coimbatore. Page 21


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

Serial.println(outputValue);

analogWrite(ledPin, outputValue); // generate PWM signal

Arduino Project – Water Level Indicator

For our next example, we’ll build a simple water level indicator that will light up LEDs based on the
level of the water.

Wiring

We’ll reuse the previous example’s circuit. We only need to add some LEDs this time.

Connect three LEDs to digital pins #2, #3, and #4 using 220 ohm resistors.

Connect your circuit as shown below:

Taken from-lastminuteengineer.com

/* Change these values based on your calibration values */

int lowerThreshold = 420;

Prepared By: CSE Department, KPRIET, Coimbatore. Page 22


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

int upperThreshold = 520;

// Sensor pins

#define sensorPower 7

#define sensorPin A0

// Value for storing water level

int val = 0;

// Declare pins to which LEDs are connected

int redLED = 2;

int yellowLED = 3;

int greenLED = 4;

void setup() {

Serial.begin(9600);

pinMode(sensorPower, OUTPUT);

digitalWrite(sensorPower, LOW);

// Set LED pins as an OUTPUT

pinMode(redLED, OUTPUT);

pinMode(yellowLED, OUTPUT);

pinMode(greenLED, OUTPUT);

Prepared By: CSE Department, KPRIET, Coimbatore. Page 23


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

// Initially turn off all LEDs

digitalWrite(redLED, LOW);

digitalWrite(yellowLED, LOW);

digitalWrite(greenLED, LOW);

void loop() {

int level = readSensor();

if (level == 0) {

Serial.println("Water Level: Empty");

digitalWrite(redLED, LOW);

digitalWrite(yellowLED, LOW);

digitalWrite(greenLED, LOW);

else if (level > 0 && level <= lowerThreshold) {

Serial.println("Water Level: Low");

digitalWrite(redLED, HIGH);

digitalWrite(yellowLED, LOW);

digitalWrite(greenLED, LOW);

else if (level > lowerThreshold && level <= upperThreshold) {

Serial.println("Water Level: Medium");

digitalWrite(redLED, LOW);

Prepared By: CSE Department, KPRIET, Coimbatore. Page 24


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

digitalWrite(yellowLED, HIGH);

digitalWrite(greenLED, LOW);

else if (level > upperThreshold) {

Serial.println("Water Level: High");

digitalWrite(redLED, LOW);

digitalWrite(yellowLED, LOW);

digitalWrite(greenLED, HIGH);

delay(1000);

//This is a function used to get the reading

int readSensor() {

digitalWrite(sensorPower, HIGH);

delay(10);

val = analogRead(sensorPin);

digitalWrite(sensorPower, LOW);

return val;

MQ2 Gas Sensor

The MQ2 sensor is one of the most widely used in the MQ sensor series. It is a MOS (Metal Oxide
Semiconductor) sensor. Metal oxide sensors are also known as Chemiresistors because sensing is
based on the change in resistance of the sensing material when exposed to gasses.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 25


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

The MQ2 gas sensor operates on 5V DC and consumes approximately 800mW. It can
detect LPG, Smoke, Alcohol, Propane, Hydrogen, Methane and Carbon Monoxide concentrations
ranging from 200 to 10000 ppm.

Working Principle

The MQ-2 sensor works on the principle of resistance changes in the presence of different gases.
When the target gas comes in contact with the heated MOS(Metal Oxide Semiconductor) material, it
undergoes oxidation or reduction reactions that change the resistance of the MOS material. It is
noteworthy that the MQ2 gas sensor is capable of detecting multiple gases, but lacks the ability to
differentiate between them. This is a common characteristic of most gas sensors.

The sensor has a built-in potentiometer that allows you to adjust the sensor digital output (D0)
threshold. When the concentration of gas in the air exceeds a certain threshold value, the resistance of
the sensor changes. This change in resistance is then converted into an electrical signal that can be
read by an Arduino board.

// Define the pin numbers for the Gas Sensor

Prepared By: CSE Department, KPRIET, Coimbatore. Page 26


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

const int sensorPin = A0;

void setup() {

Serial.begin(9600); // Start serial communication at 9600 baud rate

void loop() {

Serial.print("Analog output: ");

Serial.println(analogRead(sensorPin)); // Read the analog value of the gas sensor and print it to the
//serial monitor

delay(50); // Wait for 50 milliseconds}

What is a PIR Sensor?

A passive infrared sensor is an electronic sensor that measures infrared light radiating
from objects. PIR sensors mostly used in PIR-based motion detectors. Also, it used in security alarms
and automatic lighting applications. The below image shows a typical pin configuration of the PIR
sensor, which is quite simple to understand the pinouts. The PIR sensor consist of 3 pins,

 Pin1 corresponds to the drain terminal of the device, which connected to the positive supply
5V DC.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 27


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

 Pin2 corresponds to the source terminal of the device, which connects to the ground terminal
via a 100K or 47K resistor. The Pin2 is the output pin of the sensor. The pin 2 of the sensor
carries the detected IR signal to an amplifier from the
 Pin3 of the sensor connected to the ground.

PIR Sensor detect?

Generally, PIR sensor can detect animal/human movement in a requirement range. PIR is made of a
pyroelectric sensor, which is able to detect different levels of infrared radiation. The detector itself
does not emit any energy but passively receives it.

It detects infrared radiation from the environment. Once there is infrared radiation from the human
body particle with temperature, focusing on the optical system causes the pyroelectric device to
generate a sudden electrical signal.

Simply, when a human body or any animal passes by, then it intercepts the first slot of the PIR
sensor. This causes a positive differential change between the two bisects. When a human body
leaves the sensing area,the sensor generates a negative differential change between the two bisects.

PIR Sensor Working Principle

Prepared By: CSE Department, KPRIET, Coimbatore. Page 28


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

The passive infrared sensor does not radiate energy to space. It receives the infrared radiation from
the human body to make an alarm. Any object with temperature is constantly radiating infrared rays
to the outside world. The surface temperature of the human body is between 36° C - 27 ° C and most
of its radiant energy concentrated in the wavelength range of 8 um-12 um.

Passive infrared alarms classified into infrared detectors (infrared probes) and alarm control
sections. The most widely used infrared detector is a pyroelectric detector. It uses as a sensor for
converting human infrared radiation into electricity. If the human infrared radiation is directly
irradiated on the detector, it will, of course, cause a temperature change to output a signal. But in
doing all this, the detection distance will not be more. In order to lengthen the detection distance of
the detector, an optical system must be added to collect the infrared radiation. Usually, plastic optical
reflection system or plastic Fresnel lens used as a focusing system for infrared radiation.

In the detection area, the lens of the detector receives the infrared radiation energy of the human body
through the clothing and focused on the pyroelectric sensor. When the human body moves in this
surveillance mode, it enters a certain field of view in sequence and then walks out of the field of
view. The pyroelectric sensor sees the moving human body for a while and then does not see it, so the
infrared radiation of human body constantly changes the temperature of the pyroelectric material. So
that it outputs a corresponding signal, which is the alarm signal.

What is the Range of PIR Sensor?

Prepared By: CSE Department, KPRIET, Coimbatore. Page 29


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

 Indoor passive infrared: Detection distances range from 25 cm to 20 m.


 Indoor curtain type: The detection distance ranges from 25 cm to 20 m.
 Outdoor passive infrared: The detection distance ranges from 10 meters to 150 meters.
 Outdoor passive infrared curtain detector: distance from 10 meters to 150 meters

const int PIR_SENSOR_OUTPUT_PIN = 4;/* PIR sensor O/P pin */


int warm_up;
void setup() {
pinMode(PIR_SENSOR_OUTPUT_PIN, INPUT);
Serial.begin(9600); /* Define baud rate for serial communication */
delay(20000); /* Power On Warm Up Delay */
}
void loop() {
int sensor_output;
sensor_output = digitalRead(PIR_SENSOR_OUTPUT_PIN);
if( sensor_output == LOW )
{
if( warm_up == 1 )
{
Serial.print("Warming Up\n\n");
warm_up = 0;
delay(2000);
}
Serial.print("No object in sight\n\n");
delay(1000);

Prepared By: CSE Department, KPRIET, Coimbatore. Page 30


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

}
else
{
Serial.print("Object detected\n\n");
warm_up = 1;
delay(1000);
}
}

With Interupt
const int PIR_SENSOR_OUTPUT_PIN = 2; /* PIR sensor O/P pin */

void setup() {
pinMode(PIR_SENSOR_OUTPUT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), pir, FALLING); /* Interrupt on rising edge on pin 2 */
Serial.begin(9600); /* Define baud rate for serial communication */
delay(20000); /* Power On Warm Up Delay */
}

void loop() {
}
void pir(){
Serial.println("Object Detected");
}

Ultrasonic Sensor

Ultrasonic sensors work by emitting sound waves at a frequency which is too high for humans to hear.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 31


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

An above image shows the HC-SR-04 ultrasonic sensor which has a transmitter, receiver. The pin
configuration is,

 VCC - +5 V supply
 TRIG – Trigger input of the sensor. Microcontroller applies 10 us trigger pulse to the HC-SR04
ultrasonic module.
 ECHO–Echo output of the sensor. Microcontroller reads/monitors this pin to detect the obstacle
or to find the distance.
 GND – Ground

Sound is a mechanical wave travelling through the mediums, which may be a solid, or liquid or gas.
Sound waves can travel through the mediums with specific velocity depends on the medium of
propagation. The sound waves which are having high frequency reflect from boundaries and produce
distinctive echo patterns.

Ultrasonic Sensor Working Principle

Ultrasonic sensors emit short, high-frequency sound pulses at regular intervals. These propagate in the
air at the velocity of sound. If they strike an object, then they reflected back as an echo signal to the
sensor, which itself computes the distance to the target based on the time-span between emitting the
signal and receiving the echo.

Ultrasonic sensors are excellent at suppressing background interference. Virtually all materials which
reflect sound can be detected, regardless of their colour. Even transparent materials or thin foils
represent no problem for an ultrasonic sensor.

microsonic ultrasonic sensors are suitable for target distances from 20 mm to 10 m and as they measure
the time of flight they can ascertain a measurement with pinpoint accuracy. Some of our sensors can
even resolve the signal to an accuracy of 0.025 mm. Ultrasonic sensors can see through dust-laden air
and ink mists. Even thin deposits on the sensor membrane do not impair its function.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 32


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

#define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04


#define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04
// defines variables

long duration; // variable for the duration of sound wave travel


int distance; // variable for the distance measurement
void setup()
{
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT

Serial.begin(9600); // Serial Communication is starting with 9600 of baudrate speed


Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor
Serial.println("with Arduino UNO R3");
}
void loop()
{ // Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) for 10 microseconds digitalWrite(trigPin,
HIGH);
delayMicroseconds(10);

Prepared By: CSE Department, KPRIET, Coimbatore. Page 33


U21ECG04 -Internet
of Things and its
Applications [UNIT III – INTERFACING SENSORS AND ACTUATORS]

digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time //in microseconds
duration = pulseIn(echoPin, HIGH); // Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)

// Displays the distance on the Serial Monitor


Serial.print("Distance: "); Serial.print(distance); Serial.println(" cm");
}

Prepared By: CSE Department, KPRIET, Coimbatore. Page 34

You might also like