Sensors: Sensors Are The Key Components For Perceiving The Environment
Sensors: Sensors Are The Key Components For Perceiving The Environment
Sensors: Sensors Are The Key Components For Perceiving The Environment
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.
float sensor=A0;
float gas_value;
void setup()
{pinMode(sensor,INPUT);
Serial.begin(9600);
void loop()
gas_value=analogRead(sensor);
Serial.println(gas_value);
Pin Configuration:
PIR sensor have total 3 pins. The configuration of each pin is given
below:
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.
void setup()
}
void loop()
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
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();
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:
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:
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:
#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:
Applications:
Hearing aids
Telephones
Tape recorders and karaoke
Live and recorded audio engineering
Radio and television broadcasting
Speech recognition technology
int ledPin=13;
int sensorPin=7;
boolean val =0;
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin (9600);
}
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.
// 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
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:
Pin Configuration:
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.
The following sketch is used to turn the LED ON for 5 seconds when the Piezo sensor
detects the knock.
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.
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
}
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:
#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);}