-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest1TempSensorTrickFire.ino
More file actions
41 lines (33 loc) · 976 Bytes
/
Test1TempSensorTrickFire.ino
File metadata and controls
41 lines (33 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <DHT.h>
// Define the pin and type of DHT sensor
#define DHTPIN 2 // Pin where the DHT22 is connected
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Start serial communication
Serial.begin(9600);
Serial.println("DHT22 sensor test!");
// Initialize the DHT sensor
dht.begin();
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Read humidity
float humidity = dht.readHumidity();
// Read temperature in Celsius
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again)
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
}