Temperature and Humidity
Components:
1- Arduino
2- Humidity and Temperature sensor module
3- 1k resistor
4-Wires
Connections:
Data pin : pin 3
Gnd : 1K Resistor :Gnd
Vcc : 5v
Code:
#include <dht.h>
// Define the DHT11 sensor pin
#define DHTPIN 2
// Create a DHT11 object
dht DHT;
void setup() {
// Start the serial communication
Serial.begin(9600);
}
void loop() {
// Read the temperature and humidity from the DHT11 sensor
int chk = DHT.read11(DHTPIN);
// Check if the reading was successful
if (chk == DHTLIB_OK) {
// Print the temperature and humidity to the serial monitor
Serial.print(“Temperature: “);
Serial.print(DHT.temperature);
Serial.print(” °C, Humidity: “);
Serial.print(DHT.humidity);
Serial.println(“%”);
} else {
// Print an error message if the reading failed
Serial.println(“Error reading DHT11 sensor”);
}
// Wait for a short period of time before taking another reading
delay(2000);
}