SlideShare a Scribd company logo
1 of 42
TYPES OF SENSORS
BY PARTHASARATHI
M
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.
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.
Arduino code for Temperature sensor
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.
Arduino code for Proximity Sensor
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.
Arduino code for Infrared sensor
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.
Arduino code for Ultrasonic sensor
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.
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);
}
}
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.
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);
}
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.
Arduino code for Alcohol sensor
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.
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);
}
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.
Arduino code for colour sensor
#define s0 8
#define s2 10
#define s3 11
#define out 12
int data=0;
void setup()
{
pinMode(s0,OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
pinMode(out,INPUT);
Serial.begin(9600);
digitalWrite(s0,HIGH);
digitalWrite(s1,HIGH);
}
void loop()
{
digitalWrite(s2,LOW);
digitalWrite(s3,LOW);
Serial.print("Red value= ");
GetData();
digitalWrite(s2,LOW);
digitalWrite(s3,HIGH);
Serial.print("Blue value= ");
GetData();
digitalWrite(s2,HIGH);
digitalWrite(s3,HIGH);
Serial.print("Green value= ");
GetData();
Serial.println();
delay(2000);
}
void GetData(){
data=pulseIn(out,LOW);
Serial.print(data);
Serial.print("t");
delay(20);
}
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).
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(
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.
Arduino code for Tilt sensor
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).
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;
}
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.
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);
}
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.
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);
}
}
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.
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);}
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.
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);
}
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.
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&lt;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&lt;pTime+10) { if (diff&gt;0)
buzState=1;
else if(diff&lt;0) buzState=2; } if (cTime&gt;pTime+buzPeriod)
{
if (diff&gt;0)
buzState=1;
else if (diff&lt;0) buzState=2; pTime=cTime; } if (buzPeriod&gt;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&lt;&lt;6; //set sumExpect to expected value long int avgsum=(sumExpect+32)&gt;&gt;6;
diff=sum-avgsum;
if (abs(diff)&gt;10)
{
sumExpect=sumExpect+sum-avgsum;
ignor=0;
}
else
ignor++;
if (ignor&gt;64)
{
sumExpect=sum&lt;&lt;6;
ignor=0;
}
if (diff==0)
buzPeriod=1000000;
else
buzPeriod=avgsum/(2*abs(diff));
}
void applyPulses()
{
for (int i=0;i&lt;3;i++)
{
digitalWrite(pulsePin,HIGH); //take 3.5 uS
delayMicroseconds(3);
digitalWrite(pulsePin,LOW); //take 3.5 uS
delayMicroseconds(3);
}
}
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.
Arduino code for biometric fingerprint sensor
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <TFT_ILI9163C.h>
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define __CS 10
#define __DC 9
static const uint8_t icon [] PROGMEM = {
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,
0x0,0x0,0x0,0x3f,0xc0,0x0,0x0,0x0,
0x0,0x0,0x3,0xff,0xf8,0x0,0x0,0x0,
0x0,0x0,0x7,0xff,0xfe,0x0,0x0,0x0,
0x0,0x0,0x1f,0xc0,0x7f,0x80,0x0,0x0,
0x0,0x0,0x3e,0x0,0x7,0xc0,0x0,0x0,
0x0,0x0,0x7c,0x0,0x3,0xe0,0x0,0x0,
0x0,0x0,0xfd,0xff,0x81,0xf0,0x0,0x0,
0x0,0x0,0xff,0xff,0xe0,0xf0,0x0,0x0,
0x0,0x1,0xff,0xff,0xf8,0x78,0x0,0x0,
0x0,0x1,0xff,0x80,0x7c,0x38,0x0,0x0,
0x0,0x3,0xfc,0x0,0xe,0x3c,0x0,0x0,
0x0,0x3,0xf0,0x0,0x7,0x1c,0x0,0x0,
0x0,0x7,0xc0,0x7f,0x83,0x8e,0x0,0x0,
0x0,0x7,0x83,0xff,0xe0,0xe,0x0,0x0,
0x0,0x7,0xf,0xff,0xf8,0xf,0x0,0x0,
0x0,0x6,0x1f,0x80,0xfc,0x7,0x0,0x0,
0x0,0x4,0x7e,0x0,0x3f,0x7,0x0,0x0,
0x0,0x0,0xf8,0x0,0xf,0x7,0x0,0x0,
0x0,0x0,0xf0,0x3e,0x7,0x87,0x0,0x0,
0x0,0x1,0xe1,0xff,0x83,0x83,0x80,0x0,
0x0,0x3,0xc3,0xff,0xc3,0xc3,0x80,0x0,
0x0,0x3,0xc7,0xc3,0xe1,0xc3,0x80,0x0,
0x0,0x3,0x8f,0x0,0xf1,0xe3,0x80,0x0,
0x0,0x7,0x1e,0x0,0x78,0xe3,0x80,0x0,
0x0,0x7,0x1e,0x3c,0x38,0xe3,0x80,0x0,
0x0,0x7,0x1c,0x7e,0x38,0xe3,0x80,0x0,
0x0,0xf,0x1c,0x7f,0x38,0xe3,0x80,0x0,
0x0,0xe,0x3c,0xf7,0x38,0x71,0x80,0x0,
0x0,0xe,0x38,0xe7,0x38,0x71,0xc0,0x0,
0x0,0xe,0x38,0xe7,0x38,0x71,0xc0,0x0,
0x0,0xe,0x38,0xe7,0x38,0x73,0xc0,0x0,
0x0,0xe,0x38,0xe3,0x98,0xe3,0xc0,0x0,
0x0,0xe,0x38,0xe3,0xb8,0xe3,0x80,0x0,
0x0,0x0,0x38,0xe3,0xf8,0xe3,0x80,0x0,
0x0,0x0,0x38,0xe3,0xf8,0xe3,0x80,0x0,
0x0,0x0,0x3c,0xf1,0xf1,0xe3,0x80,0x0,
0x0,0x6,0x1c,0x70,0x1,0xc7,0x80,0x0,
0x0,0xe,0x1c,0x78,0x3,0xc7,0x80,0x0,
0x0,0xf,0x1c,0x3e,0x7,0x87,0x0,0x0,
0x0,0xf,0x1e,0x3f,0xff,0x8f,0x0,0x0,
0x0,0xf,0x1e,0x1f,0xff,0x1f,0x0,0x0,
0x0,0xf,0xf,0x7,0xfc,0x3e,0x0,0x0,
0x0,0x7,0x87,0x80,0x0,0x7c,0x0,0x0,
0x0,0x7,0x87,0xe0,0x0,0xfc,0x0,0x0,
0x0,0x3,0xc3,0xf8,0x7,0xf8,0x0,0x0,
0x0,0x3,0xe1,0xff,0xff,0xe1,0x0,0x0,
0x0,0x1,0xe0,0x7f,0xff,0x83,0x0,0x0,
0x0,0x1,0xf8,0xf,0xfe,0x7,0x0,0x0,
0x0,0x0,0xfc,0x0,0x0,0xe,0x0,0x0,
0x0,0x0,0x3f,0x0,0x0,0x3c,0x0,0x0,
0x0,0x0,0x1f,0xe0,0x1,0xf8,0x0,0x0,
0x0,0x0,0x7,0xff,0xff,0xf0,0x0,0x0,
0x0,0x0,0x1,0xff,0xff,0xc0,0x0,0x0,
0x0,0x0,0x0,0x1f,0xfc,0x0,0x0,0x0,
TFT_ILI9163C display = TFT_ILI9163C(__CS,8, __DC);
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
int fingerprintID = 0;
void setup(void) {
startFingerprintSensor();
display.begin();
displayLockScreen();
}
void loop() {
fingerprintID = getFingerprintID();
delay(50);
if(fingerprintID == 1)
{
display.drawBitmap(30,35,icon,60,60,GREEN);
delay(2000);
displayUnlockedScreen();
displayIoanna();
delay(5000);
display.fillScreen(BLACK);
displayLockScreen();
}
if(fingerprintID == 2)
{
display.drawBitmap(30,35,icon,60,60,GREEN);
delay(2000);
displayUnlockedScreen();
displayNick();
delay(5000);
display.fillScreen(BLACK);
displayLockScreen();
}
}
void displayUnlockedScreen()
{
display.fillScreen(BLACK);
display.drawRect(0,0,128,128,WHITE);
display.setCursor(18,10);
display.setTextColor(GREEN);
display.setTextSize(2);
display.print("UNLOCKED");
display.setCursor(20,50);
display.setTextColor(WHITE);
display.setTextSize(2);
display.print("WELCOME");
}
void displayNick()
{
display.setCursor(35,75);
display.setTextColor(WHITE);
display.setTextSize(2);
display.print("NICK!");
}
void displayIoanna()
{
display.setCursor(25,75);
display.setTextColor(WHITE);
display.setTextSize(2);
display.print("IOANNA!");
}
void displayLockScreen()
{
display.drawRect(0,0,128,128,WHITE);
display.setCursor(30,10);
display.setTextColor(RED);
display.setTextSize(2);
display.print("LOCKED");
display.setCursor(10,100);
display.setTextColor(WHITE);
display.setTextSize(1);
display.print("Waiting for valid n fingerprint.");
display.drawBitmap(30,35,icon,60,60,WHITE);
}
void startFingerprintSensor()
{
Serial.begin(9600);
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor");
}
Serial.println("Waiting for valid finger...");
}
int getFingerprintID() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
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.
Arduino code for altitude sensor
#include <SFE_BMP180.h>
#include <Wire.h?
SFE_BMP180 pressure;
#define ALTITUDE 943.7 // Altitude of Electropeak Co. in meters
void setup() {
Serial.begin(9600);
if (pressure.begin())
Serial.println("BMP180 init success");
else
{
Serial.println("BMP180 init failnn");
Serial.println("Check connection");
while (1);
}
}
void loop() {
char status;
double T, P, p0, a;
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
Serial.print("temperature: ");
Serial.print(T, 2);
Serial.println(" deg C ");
status = pressure.startPressure(3);
if (status != 0)
{
delay(status);
status = pressure.getPressure(P, T);
if (status != 0)
{
Serial.print("absolute pressure: ");
Serial.print(P, 2);
Serial.print(" hpa = ");
Serial.print(P * 100, 2);
Serial.print(" pa = ");
Serial.print(P * 0.000986923, 2);
Serial.print(" atm = ");
Serial.print(P * 0.750063755, 2);
Serial.print(" mmHg = ");
Serial.print(P * 0.750061683, 2);
Serial.print(" torr = ");
Serial.print(P * 0.014503774, 2);
Serial.println(" psi");
p0 = pressure.sealevel(P, ALTITUDE); // we're at 943.7 meters
Serial.print("relative (sea-level) pressure: ");
Serial.print(p0, 2);
Serial.println(" hpa ");;
a = pressure.altitude(P, p0);
Serial.print("your altitude: ");
Serial.print(a, 0);
Serial.println(" meters ");
}
else Serial.println("error retrieving pressure measurementn");
}
else Serial.println("error starting pressure measurementn");
}
else Serial.println("error retrieving temperature measurementn");
}
else Serial.println("error starting temperature measurementn");
Serial.println("==========================================================================");
delay(5000);
}
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).
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();
}
}

More Related Content

Similar to sensors.pptx

Sensors - Aniket.pptx
Sensors - Aniket.pptxSensors - Aniket.pptx
Sensors - Aniket.pptxAniketKuanra
 
Complex Sensors
Complex SensorsComplex Sensors
Complex Sensorselliando dias
 
Automatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorAutomatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorRAGHUVARMA09
 
Infrared IR Sensor Circuit Diagram and Working Principle
Infrared IR Sensor Circuit Diagram and Working PrincipleInfrared IR Sensor Circuit Diagram and Working Principle
Infrared IR Sensor Circuit Diagram and Working Principleelprocus
 
Sensor technology
Sensor technologySensor technology
Sensor technologyShyamKumar415
 
Introduction to sensors & transducers by Bapi Kumar Das
Introduction to sensors & transducers by Bapi Kumar DasIntroduction to sensors & transducers by Bapi Kumar Das
Introduction to sensors & transducers by Bapi Kumar DasB.k. Das
 
Ir sensor mechanism and interfacing with a micro controllers.PPT
Ir sensor mechanism and  interfacing with  a micro controllers.PPTIr sensor mechanism and  interfacing with  a micro controllers.PPT
Ir sensor mechanism and interfacing with a micro controllers.PPTkhairunnesa2
 
introduction to transducer
introduction to transducerintroduction to transducer
introduction to transducerYasir Hashmi
 
Sensors-and-Actuators-working principle and types of sensors
Sensors-and-Actuators-working principle and types of sensorsSensors-and-Actuators-working principle and types of sensors
Sensors-and-Actuators-working principle and types of sensorsRameshBabu920476
 
Wireless sensors
Wireless sensorsWireless sensors
Wireless sensorsHirtiek Sudan
 
MBCPS 425_163_2122_22_26062022_679.pdf
MBCPS 425_163_2122_22_26062022_679.pdfMBCPS 425_163_2122_22_26062022_679.pdf
MBCPS 425_163_2122_22_26062022_679.pdfJosephDanquah6
 
Final year Engineering project
Final year Engineering project Final year Engineering project
Final year Engineering project VaibhavShukla740413
 
PIR sensors day
PIR sensors day PIR sensors day
PIR sensors day sivagamitec
 

Similar to sensors.pptx (20)

Sensors - Aniket.pptx
Sensors - Aniket.pptxSensors - Aniket.pptx
Sensors - Aniket.pptx
 
sensors BG.pdf
sensors BG.pdfsensors BG.pdf
sensors BG.pdf
 
Complex Sensors
Complex SensorsComplex Sensors
Complex Sensors
 
omega ppt 1.new.pptx
omega ppt 1.new.pptxomega ppt 1.new.pptx
omega ppt 1.new.pptx
 
Sensor.pptx
Sensor.pptxSensor.pptx
Sensor.pptx
 
ir sensor.docx
ir sensor.docxir sensor.docx
ir sensor.docx
 
Sensors.pptx
Sensors.pptxSensors.pptx
Sensors.pptx
 
Automatic Door Opener using PIR Sensor
Automatic Door Opener using PIR SensorAutomatic Door Opener using PIR Sensor
Automatic Door Opener using PIR Sensor
 
Infrared IR Sensor Circuit Diagram and Working Principle
Infrared IR Sensor Circuit Diagram and Working PrincipleInfrared IR Sensor Circuit Diagram and Working Principle
Infrared IR Sensor Circuit Diagram and Working Principle
 
Sensor technology
Sensor technologySensor technology
Sensor technology
 
Introduction to sensors & transducers by Bapi Kumar Das
Introduction to sensors & transducers by Bapi Kumar DasIntroduction to sensors & transducers by Bapi Kumar Das
Introduction to sensors & transducers by Bapi Kumar Das
 
Ir sensor mechanism and interfacing with a micro controllers.PPT
Ir sensor mechanism and  interfacing with  a micro controllers.PPTIr sensor mechanism and  interfacing with  a micro controllers.PPT
Ir sensor mechanism and interfacing with a micro controllers.PPT
 
Arduino
ArduinoArduino
Arduino
 
introduction to transducer
introduction to transducerintroduction to transducer
introduction to transducer
 
Sensors-and-Actuators-working principle and types of sensors
Sensors-and-Actuators-working principle and types of sensorsSensors-and-Actuators-working principle and types of sensors
Sensors-and-Actuators-working principle and types of sensors
 
Wireless sensors
Wireless sensorsWireless sensors
Wireless sensors
 
MBCPS 425_163_2122_22_26062022_679.pdf
MBCPS 425_163_2122_22_26062022_679.pdfMBCPS 425_163_2122_22_26062022_679.pdf
MBCPS 425_163_2122_22_26062022_679.pdf
 
Final year Engineering project
Final year Engineering project Final year Engineering project
Final year Engineering project
 
Basic Sensors Technology
Basic Sensors TechnologyBasic Sensors Technology
Basic Sensors Technology
 
PIR sensors day
PIR sensors day PIR sensors day
PIR sensors day
 

Recently uploaded

Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacingjaychoudhary37
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoĂŁo Esperancinha
 

Recently uploaded (20)

Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
microprocessor 8085 and its interfacing
microprocessor 8085  and its interfacingmicroprocessor 8085  and its interfacing
microprocessor 8085 and its interfacing
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

sensors.pptx

  • 1. TYPES OF SENSORS BY PARTHASARATHI M
  • 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.
  • 4. Arduino code for Temperature sensor
  • 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.
  • 6. Arduino code for Proximity Sensor
  • 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.
  • 8. Arduino code for Infrared sensor
  • 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.
  • 10. Arduino code for Ultrasonic sensor
  • 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.
  • 16. Arduino code for Alcohol sensor
  • 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.
  • 20. Arduino code for colour sensor #define s0 8 #define s2 10 #define s3 11 #define out 12 int data=0; void setup() { pinMode(s0,OUTPUT); pinMode(s1,OUTPUT); pinMode(s2,OUTPUT); pinMode(s3,OUTPUT); pinMode(out,INPUT); Serial.begin(9600); digitalWrite(s0,HIGH); digitalWrite(s1,HIGH); } void loop() { digitalWrite(s2,LOW); digitalWrite(s3,LOW); Serial.print("Red value= "); GetData(); digitalWrite(s2,LOW); digitalWrite(s3,HIGH); Serial.print("Blue value= "); GetData(); digitalWrite(s2,HIGH); digitalWrite(s3,HIGH); Serial.print("Green value= "); GetData(); Serial.println(); delay(2000); } void GetData(){ data=pulseIn(out,LOW); Serial.print(data); Serial.print("t"); delay(20); }
  • 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.
  • 24. Arduino code for Tilt sensor
  • 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&lt;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&lt;pTime+10) { if (diff&gt;0) buzState=1; else if(diff&lt;0) buzState=2; } if (cTime&gt;pTime+buzPeriod) { if (diff&gt;0) buzState=1; else if (diff&lt;0) buzState=2; pTime=cTime; } if (buzPeriod&gt;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&lt;&lt;6; //set sumExpect to expected value long int avgsum=(sumExpect+32)&gt;&gt;6; diff=sum-avgsum; if (abs(diff)&gt;10) { sumExpect=sumExpect+sum-avgsum; ignor=0; } else ignor++; if (ignor&gt;64) { sumExpect=sum&lt;&lt;6; ignor=0; } if (diff==0) buzPeriod=1000000; else buzPeriod=avgsum/(2*abs(diff)); } void applyPulses() { for (int i=0;i&lt;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.
  • 38. Arduino code for biometric fingerprint sensor #include <SPI.h> #include <Adafruit_GFX.h> #include <TFT_ILI9163C.h> #include <Adafruit_Fingerprint.h> #include <SoftwareSerial.h> // Color definitions #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF #define __CS 10 #define __DC 9 static const uint8_t icon [] PROGMEM = { 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x3f,0xc0,0x0,0x0,0x0, 0x0,0x0,0x3,0xff,0xf8,0x0,0x0,0x0, 0x0,0x0,0x7,0xff,0xfe,0x0,0x0,0x0, 0x0,0x0,0x1f,0xc0,0x7f,0x80,0x0,0x0, 0x0,0x0,0x3e,0x0,0x7,0xc0,0x0,0x0, 0x0,0x0,0x7c,0x0,0x3,0xe0,0x0,0x0, 0x0,0x0,0xfd,0xff,0x81,0xf0,0x0,0x0, 0x0,0x0,0xff,0xff,0xe0,0xf0,0x0,0x0, 0x0,0x1,0xff,0xff,0xf8,0x78,0x0,0x0, 0x0,0x1,0xff,0x80,0x7c,0x38,0x0,0x0, 0x0,0x3,0xfc,0x0,0xe,0x3c,0x0,0x0, 0x0,0x3,0xf0,0x0,0x7,0x1c,0x0,0x0, 0x0,0x7,0xc0,0x7f,0x83,0x8e,0x0,0x0, 0x0,0x7,0x83,0xff,0xe0,0xe,0x0,0x0, 0x0,0x7,0xf,0xff,0xf8,0xf,0x0,0x0, 0x0,0x6,0x1f,0x80,0xfc,0x7,0x0,0x0, 0x0,0x4,0x7e,0x0,0x3f,0x7,0x0,0x0, 0x0,0x0,0xf8,0x0,0xf,0x7,0x0,0x0, 0x0,0x0,0xf0,0x3e,0x7,0x87,0x0,0x0, 0x0,0x1,0xe1,0xff,0x83,0x83,0x80,0x0, 0x0,0x3,0xc3,0xff,0xc3,0xc3,0x80,0x0, 0x0,0x3,0xc7,0xc3,0xe1,0xc3,0x80,0x0, 0x0,0x3,0x8f,0x0,0xf1,0xe3,0x80,0x0, 0x0,0x7,0x1e,0x0,0x78,0xe3,0x80,0x0, 0x0,0x7,0x1e,0x3c,0x38,0xe3,0x80,0x0, 0x0,0x7,0x1c,0x7e,0x38,0xe3,0x80,0x0, 0x0,0xf,0x1c,0x7f,0x38,0xe3,0x80,0x0, 0x0,0xe,0x3c,0xf7,0x38,0x71,0x80,0x0, 0x0,0xe,0x38,0xe7,0x38,0x71,0xc0,0x0, 0x0,0xe,0x38,0xe7,0x38,0x71,0xc0,0x0, 0x0,0xe,0x38,0xe7,0x38,0x73,0xc0,0x0, 0x0,0xe,0x38,0xe3,0x98,0xe3,0xc0,0x0, 0x0,0xe,0x38,0xe3,0xb8,0xe3,0x80,0x0, 0x0,0x0,0x38,0xe3,0xf8,0xe3,0x80,0x0, 0x0,0x0,0x38,0xe3,0xf8,0xe3,0x80,0x0, 0x0,0x0,0x3c,0xf1,0xf1,0xe3,0x80,0x0, 0x0,0x6,0x1c,0x70,0x1,0xc7,0x80,0x0, 0x0,0xe,0x1c,0x78,0x3,0xc7,0x80,0x0, 0x0,0xf,0x1c,0x3e,0x7,0x87,0x0,0x0, 0x0,0xf,0x1e,0x3f,0xff,0x8f,0x0,0x0, 0x0,0xf,0x1e,0x1f,0xff,0x1f,0x0,0x0, 0x0,0xf,0xf,0x7,0xfc,0x3e,0x0,0x0, 0x0,0x7,0x87,0x80,0x0,0x7c,0x0,0x0, 0x0,0x7,0x87,0xe0,0x0,0xfc,0x0,0x0, 0x0,0x3,0xc3,0xf8,0x7,0xf8,0x0,0x0, 0x0,0x3,0xe1,0xff,0xff,0xe1,0x0,0x0, 0x0,0x1,0xe0,0x7f,0xff,0x83,0x0,0x0, 0x0,0x1,0xf8,0xf,0xfe,0x7,0x0,0x0, 0x0,0x0,0xfc,0x0,0x0,0xe,0x0,0x0, 0x0,0x0,0x3f,0x0,0x0,0x3c,0x0,0x0, 0x0,0x0,0x1f,0xe0,0x1,0xf8,0x0,0x0, 0x0,0x0,0x7,0xff,0xff,0xf0,0x0,0x0, 0x0,0x0,0x1,0xff,0xff,0xc0,0x0,0x0, 0x0,0x0,0x0,0x1f,0xfc,0x0,0x0,0x0, TFT_ILI9163C display = TFT_ILI9163C(__CS,8, __DC); SoftwareSerial mySerial(2, 3); Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); int fingerprintID = 0; void setup(void) { startFingerprintSensor(); display.begin(); displayLockScreen(); } void loop() { fingerprintID = getFingerprintID(); delay(50); if(fingerprintID == 1) { display.drawBitmap(30,35,icon,60,60,GREEN); delay(2000); displayUnlockedScreen(); displayIoanna(); delay(5000); display.fillScreen(BLACK); displayLockScreen(); } if(fingerprintID == 2) { display.drawBitmap(30,35,icon,60,60,GREEN); delay(2000); displayUnlockedScreen(); displayNick(); delay(5000); display.fillScreen(BLACK); displayLockScreen(); } } void displayUnlockedScreen() { display.fillScreen(BLACK); display.drawRect(0,0,128,128,WHITE); display.setCursor(18,10); display.setTextColor(GREEN); display.setTextSize(2); display.print("UNLOCKED"); display.setCursor(20,50); display.setTextColor(WHITE); display.setTextSize(2); display.print("WELCOME"); } void displayNick() { display.setCursor(35,75); display.setTextColor(WHITE); display.setTextSize(2); display.print("NICK!"); } void displayIoanna() { display.setCursor(25,75); display.setTextColor(WHITE); display.setTextSize(2); display.print("IOANNA!"); } void displayLockScreen() { display.drawRect(0,0,128,128,WHITE); display.setCursor(30,10); display.setTextColor(RED); display.setTextSize(2); display.print("LOCKED"); display.setCursor(10,100); display.setTextColor(WHITE); display.setTextSize(1); display.print("Waiting for valid n fingerprint."); display.drawBitmap(30,35,icon,60,60,WHITE); } void startFingerprintSensor() { Serial.begin(9600); finger.begin(57600); if (finger.verifyPassword()) { Serial.println("Found fingerprint sensor!"); } else { Serial.println("Did not find fingerprint sensor"); } Serial.println("Waiting for valid finger..."); } int getFingerprintID() { uint8_t p = finger.getImage(); if (p != FINGERPRINT_OK) return -1; p = finger.image2Tz(); if (p != FINGERPRINT_OK) return -1; p = finger.fingerFastSearch(); if (p != FINGERPRINT_OK) return -1; // found a match! Serial.print("Found ID #"); Serial.print(finger.fingerID); Serial.print(" with confidence of "); Serial.println(finger.confidence); return finger.fingerID; }
  • 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.
  • 40. Arduino code for altitude sensor #include <SFE_BMP180.h> #include <Wire.h? SFE_BMP180 pressure; #define ALTITUDE 943.7 // Altitude of Electropeak Co. in meters void setup() { Serial.begin(9600); if (pressure.begin()) Serial.println("BMP180 init success"); else { Serial.println("BMP180 init failnn"); Serial.println("Check connection"); while (1); } } void loop() { char status; double T, P, p0, a; status = pressure.startTemperature(); if (status != 0) { delay(status); status = pressure.getTemperature(T); if (status != 0) { Serial.print("temperature: "); Serial.print(T, 2); Serial.println(" deg C "); status = pressure.startPressure(3); if (status != 0) { delay(status); status = pressure.getPressure(P, T); if (status != 0) { Serial.print("absolute pressure: "); Serial.print(P, 2); Serial.print(" hpa = "); Serial.print(P * 100, 2); Serial.print(" pa = "); Serial.print(P * 0.000986923, 2); Serial.print(" atm = "); Serial.print(P * 0.750063755, 2); Serial.print(" mmHg = "); Serial.print(P * 0.750061683, 2); Serial.print(" torr = "); Serial.print(P * 0.014503774, 2); Serial.println(" psi"); p0 = pressure.sealevel(P, ALTITUDE); // we're at 943.7 meters Serial.print("relative (sea-level) pressure: "); Serial.print(p0, 2); Serial.println(" hpa ");; a = pressure.altitude(P, p0); Serial.print("your altitude: "); Serial.print(a, 0); Serial.println(" meters "); } else Serial.println("error retrieving pressure measurementn"); } else Serial.println("error starting pressure measurementn"); } else Serial.println("error retrieving temperature measurementn"); } else Serial.println("error starting temperature measurementn"); Serial.println("=========================================================================="); delay(5000); }
  • 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(); } }