You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
798 B
37 lines
798 B
/*
|
|
* Simple code to test the temperature sensor function and electrical connections.
|
|
*/
|
|
#include <DHT.h>
|
|
|
|
// Type of DHT sensor used is 11
|
|
#define DHTTYPE DHT11
|
|
#define DHTPIN 2
|
|
|
|
// Initializes DHT sensor
|
|
DHT dht(DHTPIN, DHTTYPE);
|
|
|
|
/* ===== SETUP AND LOOP ===== */
|
|
void setup() {
|
|
// Starts the serial com with PC
|
|
Serial.begin(9600);
|
|
Serial.println("Running setup function");
|
|
|
|
dht.begin();
|
|
}
|
|
|
|
void loop() {
|
|
// Reads temperature as Celsius
|
|
float temperature = dht.readTemperature();
|
|
|
|
// Checks if the read failed and handles the failure
|
|
if (isnan(temperature)) {
|
|
Serial.print(F("Failed to read from DHT sensor!"));
|
|
}
|
|
|
|
Serial.print(F("Temperature: "));
|
|
Serial.print(temperature);
|
|
Serial.println(F("°C "));
|
|
|
|
// Waits a few seconds between measurements.
|
|
delay(1000);
|
|
}
|
|
|