2. Introduction
• A sensor is a device that detects and responds to some type of input from the physical environment.
• The input can be light, heat, motion, moisture, pressure or any number of other environmental phenomena.
• The output is generally a signal that is converted to a human-readable display at the sensor location or transmitted
electronically over a network for reading or further processing.
3. Temperature sensor
• A Temperature Sensor senses the temperature i.e., it measures the changes in the
temperature.
• There are different types of Temperature Sensors like Temperature Sensor ICs (like LM35,
DS18B20), Thermistors, Thermocouples, RTD (Resistive Temperature Devices), etc.
• LM35 is a classic Analog Temperature Sensor.
• Temperature Sensors are used everywhere like computers, mobile phones, automobiles, air
conditioning systems, industries etc.
5. Proximity sensor
•A Proximity Sensor is a non-contact type sensor that detects the presence of an object.
Proximity Sensors can be implemented using different techniques like Optical (like Infrared or
Laser), Sound (Ultrasonic), Magnetic (Hall Effect), Capacitive, etc.
•Some of the applications of Proximity Sensors are Mobile Phones, Cars (Parking Sensors),
industries (object alignment), Ground Proximity in Aircrafts, etc.
7. Infrared Sensor
• IR Sensors or Infrared Sensor are light based sensor that are used in various applications like
Proximity and Object Detection.
• IR Sensors are used as proximity sensors in almost all mobile phones.
• There are two types of Infrared or IR Sensors: Transmissive Type and Reflective Type.
• In Transmissive Type IR Sensor, the IR Transmitter (usually an IR LED) and the IR Detector
(usually a Photo Diode) are positioned facing each other so that when an object passes between
them, the sensor detects the object.
• Different applications where IR Sensor is implemented are Mobile Phones, Robots, Industrial
assembly, automobiles etc.
9. Ultrasonic Sensor
• An Ultrasonic Sensor is a non-contact type device that can be used to measure distance as
well as velocity of an object.
• An Ultrasonic Sensor works based on the properties of the sound waves with frequency
greater than that of the human audible range.
• Using the time of flight of the sound wave, an Ultrasonic Sensor can measure the distance
of the object (similar to SONAR).
• The Doppler Shift property of the sound wave is used to measure the velocity of an object.
11. Light sensor
• A simple Light Sensor available today is the Light Dependent Resistor or LDR.
• The property of LDR is that its resistance is inversely proportional to the intensity of the
ambient light i.e., when the intensity of light increases, its resistance decreases and vice -
versa.
• By using LDR is a circuit, we can calibrate the changes in its resistance to measure the
intensity of Light.
• There are two other Light Sensors (or Photo Sensors) which are often used in complex
electronic system design. They are Photo Diode and Photo Transistor.
12. Arduino code for Light sensor
const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
int ldrStatus = analogRead(ldrPin);
if (ldrStatus <= 400)
{
digitalWrite(ledPin, HIGH);
Serial.print("Its Dark, Turn on the LED:");
Serial.println(ldrStatus);
}
else
{
digitalWrite(ledPin, LOW);
Serial.print("Its Bright, Turn off the LED:");
Serial.println(ldrStatus);
}
}
13. Smoke and Gas sensor
• One of the very useful sensors in safety related applications are Smoke
and Gas Sensors.
• Almost all offices and industries are equipped with several smoke
detectors, which detect any smoke (due to fire) and sound an alarm.
• Gas Sensors are more common in laboratories, large scale kitchens
and industries. They can detect different gases like LPG, Propane,
Butane, Methane (CH4), etc.
14. Arduino code for Smoke and gas sensor
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}
15. Alcohol Sensor
• As the name suggests, an Alcohol Sensor detects alcohol. Usually,
alcohol sensors are used in breathalyzer devices, which determine
whether a person is drunk or not.
• Law enforcement personnel uses breathalyzers to catch drunk-and-
drive culprits.
17. Touch sensor
•Touch Sensors, as the name suggests, detect touch of a finger or a
stylus.
•Often touch sensors are classified into Resistive and Capacitive type.
Almost all modern touch sensors are of Capacitive Types as they are
more accurate and have better signal to noise ratio.
•all touch screen devices (Mobile Phones, Tablets, Laptops, etc.) have
touch sensors in them. Another common application of touch sensor is
trackpads in our laptops.
18. Arduino code for Touch sensor
void setup() {
pinMode(2, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(2) == HIGH);
Serial.println("Sensor is touched");
delay(500);
}
19. Colour sensor
• A Colour Sensor is an useful device in building colour sensing
applications in the field of image processing, colour identification,
industrial object tracking etc.
• The TCS3200 is a simple Colour Sensor, which can detect any color and
output a square wave proportional to the wavelength of the detected
colour.
21. Humidity sensor
• If you see Weather Monitoring Systems, they often provide temperature as well as humidity
data. So, measuring humidity is an important task in many applications and Humidity Sensors
help us in achieving this.
• Often all humidity sensors measure relative humidity (a ratio of water content in air to
maximum potential of air to hold water). Since relative humidity is dependent on temperature
of air, almost all Humidity Sensors can also measure Temperature.
• Humidity Sensors are classified into Capacitive Type, Resistive Type and Thermal Conductive
Type. DHT11 and DHT22 are two of the frequently used Humidity Sensors in DIY Community
(the former is a resistive type while the latter is capacitive type).
22. Arduino code for humidity sensor
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
void setup(){
Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensornn");
delay(1000);//Wait before accessing Sensor
}//end "setup()"
void loop(){
//Start of Program
DHT.read11(dht_apin);
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(5000);//Wait 5 seconds before accessing sensor again.
//Fastest should be once every two seconds.
}// end loop(
23. Tilt Sensor
• Often used to detect inclination or orientation, Tilt Sensors are one of the
simplest and inexpensive sensors out there.
• Previously, tilt sensors are made up of Mercury (and hence they are sometimes
called as Mercury Switches) but most modern tilt sensors contain a roller ball.
25. Accelerometer sensor
•An accelerometer is an electronic sensor that measures the acceleration forces acting on an
object, in order to determine the object’s position in space and monitor the object’s
movement.
•Piezoelectric accelerometers are most commonly used in vibration and shock measurement.
•Piezoresistance accelerometers are much less sensitive than piezoelectric accelerometers,
and they are better suited to vehicle crash testing.
•Because of their size and affordability, they are embedded in a myriad of hand-held
electronic devices (such as phones, tablets, and video game controllers).
26. Arduino code for accelerometer sensor
const int xInput = A0;
const int yInput = A1;
const int zInput = A2;
// initialise minimum and maximum Raw Ranges for each axis
int RawMin = 0;
int RawMax = 1023;
// Take multiple samples to reduce noise
const int sampleSize = 10;
void setup()
{
analogReference(EXTERNAL);
Serial.begin(9600);
}
void loop()
{
//Read raw values
int xRaw = ReadAxis(xInput);
int yRaw = ReadAxis(yInput);
int zRaw = ReadAxis(zInput);
// Convert raw values to 'milli-Gs"
long xScaled = map(xRaw, RawMin, RawMax, -3000, 3000);
long yScaled = map(yRaw, RawMin, RawMax, -3000, 3000);
long zScaled = map(zRaw, RawMin, RawMax, -3000, 3000);
// re-scale to fractional Gs
float xAccel = xScaled / 1000.0;
float yAccel = yScaled / 1000.0;
float zAccel = zScaled / 1000.0;
Serial.print("X, Y, Z :: ");
Serial.print(xRaw);
Serial.print(", ");
Serial.print(yRaw);
Serial.print(", ");
Serial.print(zRaw);
Serial.print(" :: ");
Serial.print(xAccel,0);
Serial.print("G, ");
Serial.print(yAccel,0);
Serial.print("G, ");
Serial.print(zAccel,0);
Serial.println("G");
delay(200);
}
// Take samples and return the average
int ReadAxis(int axisPin)
{
long reading = 0;
analogRead(axisPin);
delay(1);
for (int i = 0; i < sampleSize; i++)
{
reading += analogRead(axisPin);
}
return reading/sampleSize;
}
27. Pressure sensor
• A pressure sensor is an electronic device that detects, regulates, or
monitors pressure, and converts perceived physical data into an electronic
signal.
• Pressure sensors often utilize piezoelectric technology, as piezoelectric
elements give off an electric charge proportional to the stress (brought on
by pressure) they experience.
28. Arduino code for pressure sensor
// TCS230 or TCS3200 pins wiring to Arduino
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
// Stores frequency read by the photodiodes
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
// Setting the sensorOut as an input
pinMode(sensorOut, INPUT);
// Setting frequency scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
// Begins serial communication
Serial.begin(9600);
}
void loop() {
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
redFrequency = pulseIn(sensorOut, LOW);
// Printing the RED (R) value
Serial.print("R = ");
Serial.print(redFrequency);
delay(100);
// Setting GREEN (G) filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
greenFrequency = pulseIn(sensorOut, LOW);
// Printing the GREEN (G) value
Serial.print(" G = ");
Serial.print(greenFrequency);
delay(100);
// Setting BLUE (B) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
blueFrequency = pulseIn(sensorOut, LOW);
// Printing the BLUE (B) value
Serial.print(" B = ");
Serial.println(blueFrequency);
delay(100);
}
29. Magnetic sensor
•A magnetic sensor usually refers to a sensor that converts the magnitude
and variations of a magnetic field into electric signals.
•Magnetic sensors that convert invisible magnetic fields into electric signals
and into visible effects have long been the subject of research.
•It started decades ago with sensors using the electromagnetic induction
effect and these efforts were extended to applications of the
galvanomagnetic effect, magnetoresistance effect, Josephson effect and
other physical phenomena.
30. Arduino code for magnetic sensor
#define Led A3
#define Reed 13
void setup() {
pinMode(Led, OUTPUT);
pinMode(Reed, INPUT);
Serial.begin(9600);
}
void loop() {
Serial.println(digitalRead(Reed));
if (digitalRead(Reed)==0 ) {
digitalWrite(Led,HIGH) ;
else
digitalWrite(Led, LOW);
}
}
31. Sound sensor (microphone)
•The sound sensor is one type of module used to notice the sound. Generally,
this module is used to detect the intensity of sound.
•The applications of this module mainly include switch, security, as well as
monitoring. The accuracy of this sensor can be changed for the ease of usage.
32. Arduino code for Sound sensor
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup(){ lcd.begin(16, 2);
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop(){int val;
val=analogRead(0); //connect mic sensor to Analog 0
Serial.print("Sound=");
Serial.println(val,DEC);//print the sound value to serial
lcd.setCursor(0, 0);
lcd.print("Sound=");
lcd.print(val);
lcd.print(" ");
delay(1000);}
33. Vibration sensor
•A vibration sensor is a device that measures the amount and frequency
of vibration in a given system, machine, or piece of equipment.
•Those measurements can be used to detect imbalances or other issues
in the asset and predict future breakdowns.
34. Arduino code for vibration sensor
int vib_pin=7;
int led_pin=13;
void setup() {
pinMode(vib_pin,INPUT);
pinMode(led_pin,OUTPUT);
}
void loop() {
int val;
val=digitalRead(vib_pin);
if(val==1)
{
digitalWrite(led_pin,HIGH);
delay(1000);
digitalWrite(led_pin,LOW);
delay(1000);
}
else
digitalWrite(led_pin,LOW);
}
35. Metal detectors or sensors
•Metal Detectors are electronic or electro-mechanical devices used to sense the
presence of metal in a variety of situations ranging from packages to people.
•Metal detectors can be permanent or portable and rely on a number of sensor
technologies with electromagnetics being popular.
•Metal detectors can be tailored to explicitly detect metal in specific manufacturing
operations such as sawmilling or injection molding.
36. Arduino code for Metal sensors
#include
#define capPin A5
#define buz 9
#define pulsePin A4
#define led 10
long sumExpect=0; //running sum of 64 sums
long ignor=0; //number of ignored sums
long diff=0; //difference between sum and avgsum
long pTime=0;
long buzPeriod=0;
void setup()
{
Serial.begin(9600);
pinMode(pulsePin, OUTPUT);
digitalWrite(pulsePin, LOW);
pinMode(capPin, INPUT);
pinMode(buz, OUTPUT);
digitalWrite(buz, LOW);
pinMode(led, OUTPUT);
}
void loop()
{
int minval=1023;
int maxval=0;
long unsigned int sum=0;
for (int i=0; i<256; i++)
{
//reset the capacitor
pinMode(capPin,OUTPUT);
digitalWrite(capPin,LOW);
delayMicroseconds(20);
pinMode(capPin,INPUT);
applyPulses();
//read the charge of capacitor
int val = analogRead(capPin); //takes 13x8=104 microseconds
minval = min(val,minval);
maxval = max(val,maxval);
sum+=val;
long unsigned int cTime=millis();
char buzState=0;
if (cTime<pTime+10) { if (diff>0)
buzState=1;
else if(diff<0) buzState=2; } if (cTime>pTime+buzPeriod)
{
if (diff>0)
buzState=1;
else if (diff<0) buzState=2; pTime=cTime; } if (buzPeriod>300)
buzState=0;
if (buzState==0)
{
digitalWrite(led, LOW);
noTone(buz);
}
else if (buzState==1)
{
tone(buz,100);
digitalWrite(led, HIGH);
}
else if (buzState==2)
{
tone(buz,500);
digitalWrite(led, HIGH);
}
}
//subtract minimum and maximum value to remove spikes
sum-=minval;
sum-=maxval;
if (sumExpect==0)
sumExpect=sum<<6; //set sumExpect to expected value long int avgsum=(sumExpect+32)>>6;
diff=sum-avgsum;
if (abs(diff)>10)
{
sumExpect=sumExpect+sum-avgsum;
ignor=0;
}
else
ignor++;
if (ignor>64)
{
sumExpect=sum<<6;
ignor=0;
}
if (diff==0)
buzPeriod=1000000;
else
buzPeriod=avgsum/(2*abs(diff));
}
void applyPulses()
{
for (int i=0;i<3;i++)
{
digitalWrite(pulsePin,HIGH); //take 3.5 uS
delayMicroseconds(3);
digitalWrite(pulsePin,LOW); //take 3.5 uS
delayMicroseconds(3);
}
}
37. Biometric fingerprint sensor
•A Biometric sensor is an identification and authentication device.
•These devices use automated methods of verifying or recognizing the identity, of a
living person, based on a physical attribute.
•These attributes include fingerprints, facial images, iris and voice recognition.
39. Altitude sensor
•The altitude (height) can be accurately measured using a number of
different physical methods.
•These include optical (laser measuring instruments), electronic
(microwave detectors), and barometric procedures.
•The following article outlines how altitude can be measured with a high
level of precision using a miniaturized, silicon-based pressure sensor,
the MS5611.
41. Gyroscope sensors
• Gyro sensors, also known as angular rate sensors or angular velocity sensors, are
devices that sense angular velocity.
• Angular velocity. In simple terms, angular velocity is the change in rotational
angle per unit of time.
• Angular velocity is generally expressed in deg/s (degrees per second).
42. Arduino code for gyroscope sensor
/* Get tilt angles on X and Y, and rotation angle on Z
* Angles are given in degrees, displays on SSD1306 OLED
*
* License: MIT
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MPU6050_light.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
MPU6050 mpu(Wire);
unsigned long timer = 0;
void setup()
{
Serial.begin(115200); // Ensure serial monitor set to this value also
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) // Address 0x3C for most of these displays, if doesn't work try 0x3D
{
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE); // Draw white text
display.clearDisplay();
Wire.begin();
mpu.begin();
display.println(F("Calculating gyro offset, do not move MPU6050"));
display.display();
mpu.calcGyroOffsets(); // This does the calibration
display.setTextSize(2);
}
void loop()
{
mpu.update();
if((millis()-timer)>10) // print data every 10ms
{
display.clearDisplay(); // clear screen
display.setCursor(0,0);
display.print("P : ");
display.println(mpu.getAngleX());
display.print("R : ");
display.println(mpu.getAngleY());
display.print("Y : ");
display.print(mpu.getAngleZ());
display.display(); // display data
timer = millis();
}
}