Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The DHT11 is a digital temperature and humidity sensor that communicates over a 1-wire protocol. Here's an example code in Arduino that reads the temperature and humidity from the sensor:
- Note: This code assumes that the DHT11 sensor is connected to pin 2 of the Arduino board. If you're using a different pin, you'll need to modify the DHTPIN definition accordingly. Also, the sensor may take up to 2 seconds to provide an accurate reading, so a delay is added before each reading.
- */
- #include <DHT.h>
- #define DHTPIN 2 // the pin connected to the sensor
- #define DHTTYPE DHT11 // specify the sensor type
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- Serial.begin(9600);
- dht.begin();
- }
- void loop() {
- delay(2000); // wait 2 seconds between readings
- // read the temperature and humidity from the sensor
- float temperature = dht.readTemperature();
- float humidity = dht.readHumidity();
- // print the temperature and humidity
- Serial.print("Temperature: ");
- Serial.print(temperature);
- Serial.println(" °C");
- Serial.print("Humidity: ");
- Serial.print(humidity);
- Serial.println(" %");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement