SlideShare a Scribd company logo
1 of 14
UNIT-III Interfacing Sensors and Actuators
Programming and Interfacing with sensors – Temperature, Humidity,
Water, MQ2,PIR and Ultrasonic – Magnetic relay switches, Actuators –
Servo motor, Stepper Motor
1
2
Programming and Interfacing with sensors
Temperature Sensor
3
Temperature Sensor
4
Temperature Sensor
float temp;
int tempPin = A1;
void setup() {
Serial.begin(9600);
}
void loop() {
temp = analogRead(tempPin);
// takes analog volt from sensor and save to
variable temp
temp = temp * 0.48828125;
// change the analog volt to its temperature
equivalent
Serial.print("TEMPERATURE = ");
Serial.print(temp); // display temperature
value
Serial.print("*C");
Serial.println();
delay(1000); // update sensor reading each one
second
}
5
Humidity Sensor
6
Humidity Sensor
7
Humidity Sensor
#include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected
to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
8
Humidity Sensor
void loop() {
delay(2000); // Wait a few seconds between
measurements
float h = dht.readHumidity();
// Reading temperature or humidity takes about 250
milliseconds!
float t = dht.readTemperature();
// Read temperature as Celsius (the default)
float f = dht.readTemperature(true);
// Read temperature as Fahrenheit (isFahrenheit = true)
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
9
Humidity Sensor
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print ("Humidity: ");
Serial.print (h);
Serial.print (" %t");
Serial.print ("Temperature: ");
Serial.print (t);
Serial.print (" *C "); Serial.print (f);
Serial.print (" *Ft"); Serial.print ("Heat index: "); Serial.print (hic); Serial.print (" *C ");Serial.print (hif);
Serial.println (" *F");
}
10
PIR Sensor
11
PIR Sensor
12
PIR Sensor
#define pirPin 2
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT);
}
13
PIR Sensor
void loop() {
PIRSensor();
}
void PIRSensor() {
if(digitalRead(pirPin) == HIGH) {
if(lockLow) {
PIRValue = 1;
lockLow = false;
Serial.println("Motion detected.");
delay(50);
}
takeLowTime = true;
}
14
PIR Sensor
if(digitalRead(pirPin) == LOW) {
if(takeLowTime){
lowIn = millis();takeLowTime = false;
}
if(!lockLow && millis() - lowIn > pause) {
PIRValue = 0;
lockLow = true;
Serial.println("Motion ended.");
delay(50);
}
}
}

More Related Content

Similar to IoTA Unit 3.pptx programming and interfaces sensor

GreenHouse_v1
GreenHouse_v1GreenHouse_v1
GreenHouse_v1
Suraj S
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
SIGMATAX1
 
QuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdfQuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdf
JohnEerl
 
CODING IN ARDUINO
CODING IN ARDUINOCODING IN ARDUINO
CODING IN ARDUINO
S Ayub
 

Similar to IoTA Unit 3.pptx programming and interfaces sensor (20)

Electronz_Chapter_3.pptx
Electronz_Chapter_3.pptxElectronz_Chapter_3.pptx
Electronz_Chapter_3.pptx
 
Humidity and Temperature Measurement Using Arduino
Humidity and Temperature Measurement Using ArduinoHumidity and Temperature Measurement Using Arduino
Humidity and Temperature Measurement Using Arduino
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Physical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digitalPhysical prototyping lab2-analog_digital
Physical prototyping lab2-analog_digital
 
Arduino Code
Arduino CodeArduino Code
Arduino Code
 
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka StreamsFast Fourier Transform (FFT) of Time Series in Kafka Streams
Fast Fourier Transform (FFT) of Time Series in Kafka Streams
 
GreenHouse_v1
GreenHouse_v1GreenHouse_v1
GreenHouse_v1
 
FINISHED_CODE
FINISHED_CODEFINISHED_CODE
FINISHED_CODE
 
Program flowchart
Program flowchartProgram flowchart
Program flowchart
 
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
8051 TIMER COUNTER SERIAL COMM. INTERUPT PROGRAMMING.pdf
 
What will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdfWhat will be quantization step size in numbers and in voltage for th.pdf
What will be quantization step size in numbers and in voltage for th.pdf
 
INT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdfINT4073 L07(Sensors and AcutTORS).pdf
INT4073 L07(Sensors and AcutTORS).pdf
 
Didactum SNMP Manual
Didactum SNMP ManualDidactum SNMP Manual
Didactum SNMP Manual
 
Interfacing with Arduino
Interfacing with ArduinoInterfacing with Arduino
Interfacing with Arduino
 
Temperature sensor with buzzer and led
Temperature sensor with buzzer and ledTemperature sensor with buzzer and led
Temperature sensor with buzzer and led
 
QuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdfQuecPython_Weather_Station_Demo_Tutorial.pdf
QuecPython_Weather_Station_Demo_Tutorial.pdf
 
CODING IN ARDUINO
CODING IN ARDUINOCODING IN ARDUINO
CODING IN ARDUINO
 
Anup2
Anup2Anup2
Anup2
 
Microprocessor project
Microprocessor projectMicroprocessor project
Microprocessor project
 
Wireless humidity and temperature monitoring system
Wireless humidity and temperature monitoring systemWireless humidity and temperature monitoring system
Wireless humidity and temperature monitoring system
 

Recently uploaded

Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
MohammadAliNayeem
 
Lecture_8-Digital implementation of analog controller design.pdf
Lecture_8-Digital implementation of analog controller design.pdfLecture_8-Digital implementation of analog controller design.pdf
Lecture_8-Digital implementation of analog controller design.pdf
mohamedsamy9878
 

Recently uploaded (20)

RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdfRESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
RESORT MANAGEMENT AND RESERVATION SYSTEM PROJECT REPORT.pdf
 
Planetary Gears of automatic transmission of vehicle
Planetary Gears of automatic transmission of vehiclePlanetary Gears of automatic transmission of vehicle
Planetary Gears of automatic transmission of vehicle
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Online book store management system project.pdf
Online book store management system project.pdfOnline book store management system project.pdf
Online book store management system project.pdf
 
Supermarket billing system project report..pdf
Supermarket billing system project report..pdfSupermarket billing system project report..pdf
Supermarket billing system project report..pdf
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
The battle for RAG, explore the pros and cons of using KnowledgeGraphs and Ve...
 
internship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOTinternship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOT
 
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...Software Engineering - Modelling Concepts + Class Modelling + Building the An...
Software Engineering - Modelling Concepts + Class Modelling + Building the An...
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
Complex plane, Modulus, Argument, Graphical representation of a complex numbe...
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdfONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
ONLINE CAR SERVICING SYSTEM PROJECT REPORT.pdf
 
2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge2024 DevOps Pro Europe - Growing at the edge
2024 DevOps Pro Europe - Growing at the edge
 
Lect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptxLect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptx
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Lecture_8-Digital implementation of analog controller design.pdf
Lecture_8-Digital implementation of analog controller design.pdfLecture_8-Digital implementation of analog controller design.pdf
Lecture_8-Digital implementation of analog controller design.pdf
 

IoTA Unit 3.pptx programming and interfaces sensor

  • 1. UNIT-III Interfacing Sensors and Actuators Programming and Interfacing with sensors – Temperature, Humidity, Water, MQ2,PIR and Ultrasonic – Magnetic relay switches, Actuators – Servo motor, Stepper Motor 1
  • 2. 2 Programming and Interfacing with sensors Temperature Sensor
  • 4. 4 Temperature Sensor float temp; int tempPin = A1; void setup() { Serial.begin(9600); } void loop() { temp = analogRead(tempPin); // takes analog volt from sensor and save to variable temp temp = temp * 0.48828125; // change the analog volt to its temperature equivalent Serial.print("TEMPERATURE = "); Serial.print(temp); // display temperature value Serial.print("*C"); Serial.println(); delay(1000); // update sensor reading each one second }
  • 7. 7 Humidity Sensor #include "DHT.h" #define DHTPIN 2 // what digital pin we're connected to #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); dht.begin(); }
  • 8. 8 Humidity Sensor void loop() { delay(2000); // Wait a few seconds between measurements float h = dht.readHumidity(); // Reading temperature or humidity takes about 250 milliseconds! float t = dht.readTemperature(); // Read temperature as Celsius (the default) float f = dht.readTemperature(true); // Read temperature as Fahrenheit (isFahrenheit = true) // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { Serial.println("Failed to read from DHT sensor!"); return;
  • 9. 9 Humidity Sensor // Compute heat index in Fahrenheit (the default) float hif = dht.computeHeatIndex(f, h); // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); Serial.print ("Humidity: "); Serial.print (h); Serial.print (" %t"); Serial.print ("Temperature: "); Serial.print (t); Serial.print (" *C "); Serial.print (f); Serial.print (" *Ft"); Serial.print ("Heat index: "); Serial.print (hic); Serial.print (" *C ");Serial.print (hif); Serial.println (" *F"); }
  • 12. 12 PIR Sensor #define pirPin 2 int calibrationTime = 30; long unsigned int lowIn; long unsigned int pause = 5000; boolean lockLow = true; boolean takeLowTime; int PIRValue = 0; void setup() { Serial.begin(9600); pinMode(pirPin, INPUT); }
  • 13. 13 PIR Sensor void loop() { PIRSensor(); } void PIRSensor() { if(digitalRead(pirPin) == HIGH) { if(lockLow) { PIRValue = 1; lockLow = false; Serial.println("Motion detected."); delay(50); } takeLowTime = true; }
  • 14. 14 PIR Sensor if(digitalRead(pirPin) == LOW) { if(takeLowTime){ lowIn = millis();takeLowTime = false; } if(!lockLow && millis() - lowIn > pause) { PIRValue = 0; lockLow = true; Serial.println("Motion ended."); delay(50); } } }