Sensors: Sensors Are The Key Components For Perceiving The Environment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Sensors

Sensors are the key components for perceiving the


environment.

Sensors vary according to


○ Physical principle
○ Resolution
○ Price
○ Energy needed etc.

1. Smoke Sensor:
A smoke detector is a device that senses smoke, typically as an
indicator of fire.
Pin Configuration:
It has four pins as follows:
 GND:Supplied with ground.
 VCC:Supplied with supply positive point.
 D0:This pin is not connected.
 A0: Pin used for to interface with the arduino.
Working:
If smoke sensor sense the smoke then it produced high voltage which is
recognized by the arduino.Otherwise if there is no smoke then it produce low voltage.
Advantage:
 It can be used for to identify the leakage of LPG,Butane.
 It can also be used for to identify the alcohol.

Code For Arduino:

float sensor=A0;

float gas_value;
void setup()

{pinMode(sensor,INPUT);

Serial.begin(9600);

void loop()

gas_value=analogRead(sensor);

Serial.println(gas_value);

2. Passive infrared sensor:


A passive infrared sensor (PIR sensor) is an
electronic sensor that measures infrared (IR) light radiating from objects in its field of
view.

Pin Configuration:
PIR sensor have total 3 pins. The configuration of each pin is given
below:

 Pin#1 is of supply pin and it is used to connect +5 DC voltages.


 Pin#2 is of output pin and this pin is used to collect the output signal which is collected
by PIR sensor.
 Pin#3 is marked as GND pin. This pin is used to provide ground to internal circuit of PIR
sensor.
Working:

The modern studies in the field of quantum physics tells us the fact each and
every object when it is placed at a temperature above absolute zero, emits some energy
in the form of heat and this heat energy is in fact the form of infrared radiations. So an
other question comes into mind that why our eyes can’t see these waves? It is because
that these waves have infrared wavelengths and his wavelength is invisible to human eyes.
if you want to detect these waves then, you have to design a proper electronic circuit.If
you see closely the name of PIR sensor which is Passive Infrared Sensor. Passive elements
are those elements that don’t generate their own voltages or energy.

Applications:

PIR sensors possess a no of applications and due to their low cost and
much advanced features:
 They are able to sense the detection of people and other objects.
 PIR sensors are also used in automatic lightening systems. In these type of systems,
when a person comes in the vicinity of the sensor then, the lights are automatically
turned ON.
 They are used in outdoor lightening systems and also in some lift lobbies. You may
have observed that when a person comes in front of the lift and if the doors are
being closed then, the doors are opened again. This is all due to PIR sensors.

Code For Arduino:

The code is as follows:

int sensor=7; //The output of PIR sensor connected to pin 7

int sensor_value; //variable to hold read sensor value

void setup()

pinMode(sensor,INPUT); // configuring pin 7 as Input

Serial.begin(9600); // To show output value of sensor in serial monitor

}
void loop()

sensor_value=digitalRead(sensor); // Reading sensor value from pin 7

Serial.println(sensor_value); // Printing output to serial monitor

3. Pulse Sensor:
Pulse Sensor is a plug-and-play heart-rate sensor for Arduino. It can
be used by students, artists, makers, and developers who want live heart-rate data
into their projects.
Pin Configuration:
We have to hold the sensor so that noise elimination circuitry is
not in front of us.It has three pins are as follows:
 Extreme right for ground.
 Extreme left for signal
 Mid one is for supply volt i.e., 5V.
Working:
When a heartbeat occurs blood is pumped through the human body and
gets squeezed into the capillary tissues. The volume of these capillary tissues
increases as a result of the heartbeat. But in between the heartbeats (the
time between two consecutive heartbeats,) this volume inside capillary tissues
decreases.
Advantage:
 It can be used in heart monitoring.
 It can be used in exercise

Code For Arduino:


#include <LiquidCrystal.h>
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 8; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


volatile int BPM; // int that holds raw Analog in 0. updated every 2mS
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // int that holds the time interval between beats!
Must be seeded!
volatile boolean Pulse = false; // "True" when User's live heartbeat is
detected. "False" when not a "live beat".
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

// Regards Serial OutPut -- Set This Up to your needs


static boolean serialVisual = true; // Set to 'false' by Default. Re-set to 'true' to
see Arduino Serial Monitor ASCII Visual Pulse

volatile int rate[10]; // array to hold last ten IBI values


volatile unsigned long sampleCounter = 0; // used to determine pulse
timing
volatile unsigned long lastBeatTime = 0; // used to find IBI
volatile int P = 512; // used to find peak in pulse wave, seeded
volatile int T = 512; // used to find trough in pulse wave, seeded
volatile int thresh = 525; // used to find instant moment of heart beat,
seeded
volatile int amp = 100; // used to hold amplitude of pulse waveform,
seeded
volatile boolean firstBeat = true; // used to seed rate array so we startup
with reasonable BPM
volatile boolean secondBeat = false; // used to seed rate array so we startup
with reasonable BPM

void setup()
{
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200); // we agree to talk fast!
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// IF YOU ARE POWERING The Pulse Sensor AT VOLTAGE
LESS THAN THE BOARD VOLTAGE,
// UN-COMMENT THE NEXT LINE AND APPLY THAT
VOLTAGE TO THE A-REF PIN
// analogReference(EXTERNAL);
}
// Where the Magic Happens
void loop()
{
serialOutput();

if (QS == true) // A Heartbeat Was Found


{
// BPM and IBI have been Determined
// Quantified Self "QS" true when arduino finds a heartbeat
fadeRate = 255; // Makes the LED Fade Effect Happen, Set 'fadeRate' Variable
to 255 to fade LED with pulse
serialOutputWhenBeatHappens(); // A Beat Happened, Output that to serial.
QS = false; // reset the Quantified Self flag for next time
}

ledFadeToBeat(); // Makes the LED Fade Effect Happen


delay(20); // take a break
}

void ledFadeToBeat()
{
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going
into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}

void interruptSetup()
{
// Initializes Timer2 to throw an interrupt every 2mS.
TCCR2A = 0x02; // DISABLE PWM ON DIGITAL PINS 3 AND 11, AND GO
INTO CTC MODE
TCCR2B = 0x06; // DON'T FORCE COMPARE, 256 PRESCALER
OCR2A = 0X7C; // SET THE TOP OF THE COUNT TO 124 FOR 500Hz
SAMPLE RATE
TIMSK2 = 0x02; // ENABLE INTERRUPT ON MATCH BETWEEN TIMER2 AND
OCR2A
sei(); // MAKE SURE GLOBAL INTERRUPTS ARE ENABLED
}

void serialOutput()
{ // Decide How To Output Serial.
if (serialVisual == true)
{
arduinoSerialMonitorVisual('-', Signal); // goes to function that makes Serial
Monitor Visualizer
}
else
{
sendDataToSerial('S', Signal); // goes to sendDataToSerial function
}
}

void serialOutputWhenBeatHappens()
{
if (serialVisual == true) // Code to Make the Serial Monitor Visualizer Work
{
Serial.print("*** Heart-Beat Happened *** "); //ASCII Art Madness
Serial.print("BPM: ");
Serial.println(BPM);
lcd.clear();
lcd.print("BPM: ");
lcd.print(BPM);
}
else
{
sendDataToSerial('B',BPM); // send heart rate with a 'B' prefix
sendDataToSerial('Q',IBI); // send time between beats with a 'Q' prefix
}
}

4. LM35(Temprature Sensor):

LM35 is a three pin temperature sensor which is used to measure temperature variations
as an analog output. The operating range of the sensor is about -55 to 150C.

Pin Configuration:

It has three pins.With the flat surface in front of your face

 Right most pin is of ground.


 Left one is pin where you apply input.
 Mid pin is where you got your output.

Working:

Temperature sensor is a device which senses variations in temperature across it. LM35 is
a basic temperature sensor that can be used for experimental purpose.It give the readings
in centigrade (degree Celsius) since its output voltage is linearly proportional to
temperature. It uses the fact that as temperature increases, the voltage across diode
increases at known rate (actually the drop across base-emitter junction of transistor).

Applications:

 It can be used for perfect coffee.


 It can be used for to measure the heat of the soil.
 Measuring temperature of a particular environment and HVAC applications
 Providing thermal shutdown for a component/ circuit
 Checking Battery Temperature

Code For Arduino:


5. HC-05 Bluetooth Module:
HC‐05 module is an easy to use Bluetooth module,
designed for transparent wireless serial connection setup .The HC-05 Bluetooth
Module can be used in a Master or Slave configuration, making it a great solution for
wireless communication.

Pin Configuration:
Pin configuration is as follows:
ENABLE: When enable is pulled LOW, the module is disabled. When enable
is left open or connected to 3.3V, the module is enabled
Vcc: Supply Voltage 3.3V to 5V
GND: Ground pin
TXD & RXD: These two pins acts as communication
STATE: It acts as a status indicator.When the module is not connected to /
paired with any other bluetooth device,signal goes Low.At this low state,the led
flashes continuously which denotes that the module is not paired with other
device.When this module is connected to/paired with any other bluetooth
device,the signal goes High.At this high state,the led blinks with a constant
delay say for example 2s delay which indicates that the module is paired.
BUTTON SWITCH: This is used to switch the module into AT command mode
Working:
Bluetooth is a wireless technology standard for exchanging data over
short distances (using short-wavelength UHF radio waves in the ISM band from
2.4 to 2.485 GHz) from fixed and mobile devices, and building personal area
networks (PANs). Range is approximately 10 Meters (30 feet). HC-05 is a more
capable module that can be set to be either Master or Slave.

Applications:

 It can be used for to wirelessly operate the car.


 It can be used in wireless speakers.
 It can be used in wireless devices.

Code For Arduino:

#define ledPin 7
int state = 0;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(38400); // Default communication rate of the Bluetooth module
}

void loop() {
if(Serial.available() > 0){ // Checks whether data is comming from the serial port
state = Serial.read(); // Reads the data from the serial port
}

if (state == '0') {
digitalWrite(ledPin, LOW); // Turn LED OFF
Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
state = 0;
}
else if (state == '1') {
digitalWrite(ledPin, HIGH);
Serial.println("LED: ON");;
state = 0;
}
}
6. Microphone Sound Sensor:
The microphone sound sensor, as the name says, detects sound. It gives a measurement of
how loud a sound is.

Pin Configuration:

Its pins are as follows:


A0:This pin is connected to the analogue pin of arduino.
D0: This pin is connected to the analogue pin of arduino.
GND:At this pin we provided with ground.
VCC:At this pin we provided +5V.

Working:It consist of microphone.A microphone is an acoustic to electric transducer or


sensor that detects sound signals and converts them into an electrical signal. Most of the
microphones employ light modulation, piezoelectric generation, capacitance change and
electromagnetic induction to produce an electrical voltage signal from mechanical vibration.

Applications:

 Hearing aids
 Telephones
 Tape recorders and karaoke
 Live and recorded audio engineering
 Radio and television broadcasting
 Speech recognition technology

Code For Arduino:

int ledPin=13;
int sensorPin=7;
boolean val =0;

void setup(){
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin (9600);
}

void loop (){


val =digitalRead(sensorPin);
Serial.println (val);
// when the sensor detects a signal above the threshold value, LED flashes
if (val==HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

7. Digital Humidity and Temperature Sensor :


A humidity sensor (or
hygrometer) senses, measures and reports the relative humidity in the air. It therefore
measures both moisture and air temperature.

Pin Configuration:
It has three pins are as follows:
 Extreme right for ground.
 Extreme left for signal
 Mid one is for supply volt i.e., 5V.

Working:
DHT11 digital temperature and humidity sensor is a composite Sensor
contains a calibrated digital signal output of the temperature and humidity. Application of
a dedicated digital modules collection technology and the temperature and humidity
sensing technology, to ensure that the product has high reliability and excellent long-term
stability. The sensor includes a resistive sense of wet components and an NTC temperature
measurement devices, and connected with a high-performance 8-bit microcontroller.
Application:
 People with illnesses affected by humidity, monitoring and preventive measure
in homes employ humidity sensors
 A humidity sensor is also found as part of home heating, ventilating and air
conditioning systems (HVAC systems).
 These are also used in offices, cars, humidors, museums, industrial spaces and
greenhouses and are also used in meteorology stations to report and predict
weather.

Code For Arduino:


#include "DHT.h"

#define DHTPIN 4 // a pin which is connected to the sensor

//This program can be used to DHT11 and DHT22 sensors


#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22

// Connect pin 1 of the sensor to the pin as you defined at the beginning of the code
(DHTPIN)
// Connect pin 2 sensor to + 5V
// Connect Pin 3 to GROUND
// Connect the 10K resistor between pins 1 and 2

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("DHTxx testing");

dht.begin();
}

void loop() {
// For reading the values it takes about 250ms
float h = dht.readHumidity();
float t = dht.readTemperature();

// If you have a wrong reading (NaN), check it again if everything is well connected.
if (isnan(t) || isnan(h)) {
Serial.println("The sensor can not be read");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
}

8. Piezoelectric Sensor:

A Piezoelectric sensor is used to measure the changes in


parameters like pressure, temperature, acceleration, and force, by converting them into the
electrical charge.

Pin Configuration:

 It has two pins.Red one is positive which is supplied with VCC.


 Other is supplied with ground.

Working:

This sensor works on the principle of the piezoelectric effect. The effect in
which mechanical energy is converted to an electrical form with applied pressure is called
the piezoelectric effect. When a pressure is applied to a polarized crystal, the mechanical
deformation created results in an electric charge. Conversely, when a voltage is applied
across the piezoelectric crystal, then the pressure will be possed on the atoms of crystal
creating deformation.

Applications:

 They can be used to study high-speed phenomena like explosions and blast waves.
 They are used in seismograph.
 The piezoelectric sensors are used along with the strain gauges to measure force,
stress, vibration, etc.
 Automotive companies detect detonations in the engine blocks using a piezoelectric
sensor.

Code For Arduino:

The following sketch is used to turn the LED ON for 5 seconds when the Piezo sensor
detects the knock.

const int sensorPin=0;


const int ledPin= 13;
const int threshold= 100;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int val= analogRead(sensorPin);
if (val >= threshold)
{
digitalWrite(ledPin, HIGH);
delay(5000);
digitalWrite(ledPin, LOW);
}
else
digitalWrite(ledPin, LOW);
}

9. Rotary encoder:
A rotary encoder, also called a shaft encoder, is an electro-
mechanical device that converts the angular position or motion of a shaft or axle to an
analog or digital signal. There are two main types: absolute and incremental (relative).
Pin Configuration:
It has four pins as follows:
 GND:Supplied with ground.
 +:Supplied with supply positive point.
 SW:At this we connect any kind of button.
 CLK & DT: These are output points.
Working:
The encoder has a disk with evenly spaced contact zones that are connected
to the common pin C and two other separate contact pins A and B. When the disk will
start rotating step by step, the pins A and B will start making contact with the common
pin and the two square wave output signals will be generated accordingly.
Advantage:
 It can be used for precise measurement of position in robots.
 It can be used in induction motor.

Code For Arduino:


#define outputA 6
#define outputB 7

int counter = 0;
int aState;
int aLastState;

void setup() {
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);

Serial.begin (9600);
// Reads the initial state of the outputA
aLastState = digitalRead(outputA);
}

void loop() {
aState = digitalRead(outputA); // Reads the "current" state of the outputA
// If the previous and the current state of the outputA are different, that means a Pulse
has occured
if (aState != aLastState){
// If the outputB state is different to the outputA state, that means the encoder is
rotating clockwise
if (digitalRead(outputB) != aState) {
counter ++;
} else {
counter --;
}
Serial.print("Position: ");
Serial.println(counter);
}
aLastState = aState; // Updates the previous state of the outputA with the current state
}

10. Ultrasonic Sensor:


Ultrasonic Sensor HC-SR04 is a simple sensor which
emits Ultrasonic Radiations from its transmitter and is used for measuring the distance
between sensor itself and any obstacle in front of it. The sensor has a transmitter and a
receiver on it.

Pin Configuration:
This sensor consists of four pins, which are:

 Vcc (+5V) : You need to provide +5V at this Ultrasonic Sensor HC-SR04 Pin.
 Trig (Trigger) : It’s a trigger Pin where we need to provide a trigger after which
this sensor emits ultrasonic waves.
 Echo : When Ultrasonic waves emitted y the transmitter, hit some object then they
are bounced back and are received by the receiver and at that moment this echo Pin
goes HIGH.
 GND : We need to provide ground to this PIN of HC-SR04 Ultrasonic Sensor.

Working:

A signal of +5V is sent over to Trigger pin for around 10 microseconds in order to trigger
the sensor.When ultrasonic sensor gets a trigger signal on its trigger pin then it emits an
ultrasonic signal from the transmitter.This ultrasonic senor, then goes out and reflected
back after hitting some object in front.This reflected ultrasonic signal is then captured by
the receiver of ultrasonic sensor.As the sensor gets this reflected signal, it automatically
make the Echo pin high.The time for which the Echo pin will remain HIGH, depends on
the reflected signal.What we need to do is, we need to read this time for which the echo
pin is high.

Applications:

 Ultrasonic Distance Measurement


 Ultrasonic transducer for water level detection
 Ultrasonic Obstacle Detection

Code For Arduino

The code is as follows:

#define trigPin1 8
#define echoPin1 7
long duration, distance, UltraSensor;
void setup()
{
Serial.begin (9600);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
}
void loop() {
SonarSensor(trigPin1, echoPin1);
UltraSensor = distance;
Serial.println(UltraSensor);
}
void SonarSensor(int trigPin,int echoPin)
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
delay(100);}

You might also like