How to Build a Simple Yet Effective DIY Humidity Sensor with an Arduino
Introduction
Building a humidity sensor can be a fun and educational DIY electronics project. With just a few components, including an Arduino microcontroller, you can create a device that measures the relative humidity in the surrounding environment.
In this guide, I will show you how I built a simple humidity sensor using an Arduino Uno, a DHT11 temperature and humidity sensor module, and a few other basic components. I'll explain how the circuit works, provide a parts list and wiring diagram, and walk through the process of uploading sensor code to the Arduino.
While this humidity sensor is basic, it is accurate enough for most home and hobbyist applications. The whole project can be built in an afternoon with novice to intermediate skills in Arduino and electronics. Let's get started!
Parts and Tools Needed
To build the Arduino humidity sensor, you will need:
-
Arduino Uno - The brain of the device, reads data from the sensor and outputs it. Any Arduino board will work.
-
DHT11 temperature and humidity sensor - Provides temperature and relative humidity data. Low cost and simple to use.
-
Breadboard - For prototyping and wiring up the circuit.
-
Jumper wires - For connections between components.
-
10K ohm resistor - Pulls up voltage to the data pin.
-
LEDs - I used red and green to visually indicate humidity levels.
-
220 ohm resistors - Current limiting resistors for the LEDs.
-
Battery pack or wall adapter - Powers the Arduino and components.
You'll also need basic tools like wire strippers, pliers, etc. No soldering is required since this is built on a breadboard.
Circuit Diagram
Here is the circuit diagram showing how to connect the components:
The DHT11 sensor, 10K resistor, and LEDs connect to the Arduino as shown. Power and ground rails run along the sides of the breadboard.
Uploading the Code
To get the sensor data into the Arduino, you'll need to upload this example DHT11 sensor code from the Arduino IDE:
```c++
include "DHT.h"
define DHTPIN 2 // Digital pin connected to the DHT sensor
define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
}
```
This initializes communication with the sensor, takes readings every 2 seconds, and prints the results to the Serial monitor.
Building the Circuit
With the code set up, it's time to build the circuit on the breadboard. Follow the wiring diagram closely to make all the correct connections.
Plug the Arduino into your computer via USB to upload the code. Attach the battery pack or wall adapter to provide power.
Once wired up, open the Serial monitor in the Arduino IDE. You should begin seeing temperature and humidity readings print out every 2 seconds once the code starts running!
Adding Indicator LEDs
To take this project a step further, you can add LEDs that visually indicate the humidity level.
Use a red LED to represent high humidity. Connect it through a 220 ohm current limiting resistor to Arduino pin 4.
Connect a green LED and resistor to pin 5 to indicate lower humidity levels.
Then modify the Arduino code to turn the LEDs on and off based on the humidity threshold you want. For example:
c++
if (h > 70){ // Humidity over 70%
digitalWrite(4, HIGH); // Turn on red LED
digitalWrite(5, LOW);
} else {
digitalWrite(4, LOW);
digitalWrite(5, HIGH); // Turn on green LED
}
Upload this new code and your humidity sensor will now have visual indicators!
Applications and Future Improvements
While this Arduino humidity sensor is very simple, it can form the basis for many useful projects:
-
Add a LCD display to show the humidity and temperature visually.
-
Log data to a computer or web server for recording and graphing.
-
Use it to control a dehumidifier, humidifier, or HVAC system.
-
Monitor humidity levels in a greenhouse, wine cellar or art storage room.
-
Alert you via text or email if humidity gets too low or high.
There are also ways to improve accuracy and reliability:
-
Add a more accurate DHT22 sensor instead of the DHT11.
-
Enclose the sensor circuit in a protective case with ventilation.
-
Use the average of multiple readings for more stable values.
-
Calibrate the readings against a known accurate device.
Overall, building your own humidity sensor with an Arduino is a super satisfying electronics project. With just a few common components, you can create a useful tool to monitor humidity in any environment. Let me know in the comments if you end up building one!