Measure Temperature and Humidity with Arduino Programming and Component Required
Measuring Temperature and Humidity with Arduino
Did you know that you can measure temperature and humidity with an Arduino? It’s true – by connecting a few components to your Arduino, you can measure temperature and humidity accurately. In this blog, we’ll show you how to do this using basic components and the Arduino programming language.
Components Needed
- Arduino board
- DHT11 Temperature and Humidity Sensor
- 4.7KΩ Resistor
- Breadboard and Jumper Wires
Connect the Components
Start by connecting the DHT11 sensor to the breadboard. Connect one pin of the sensor to digital pin 2 on your Arduino board and the other to ground. Use the resistor to bridge the two pins. Once the connections are secure, you can use jumper wires to connect the breadboard to the Arduino board.
Write the Code
Now it’s time to write the code that will read the temperature and humidity values from the DHT11 sensor. To do this, you’ll need to download and install the Adafruit DHT library. This library contains all the functions you need to read the values from the sensor and display them on the serial monitor.
Once the library is installed, open the Arduino IDE and paste the following code:
#include "DHT.h"
#define DHTPIN 2 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t) || isnan(h)) {
Serial.println("Failed to read from DHT sensor!");
} else {
Serial.print("Temperature = ");
Serial.print(t);
Serial.print(" *C ");
Serial.print("Humidity = ");
Serial.print(h);
Serial.println("% ");
}
delay(2000);
}
The code is now complete. Compile and upload it to your Arduino board. To view the temperature and humidity readings, open the serial monitor in the Arduino IDE. If all goes well, you should see the temperature and humidity readings printed on the serial monitor.
And there you have it – with a few components and some code, you can measure temperature and humidity with an Arduino. Have fun!