IoTA Unit 3.pptx programming and interfaces sensor

Harini737456 7 views 14 slides May 05, 2024
Slide 1
Slide 1 of 14
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14

About This Presentation

This is unit 3 lesson topics


Slide Content

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 (" *F\t"); 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); } } }
Tags