IoTA Unit 3.pptx programming and interfaces sensor
Harini737456
7 views
14 slides
May 05, 2024
Slide 1 of 14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
About This Presentation
This is unit 3 lesson topics
Size: 786.89 KB
Language: en
Added: May 05, 2024
Slides: 14 pages
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 }
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; }