Temp and Humidity sensor

Today I completed a temp and humidity sensor for my desk. The case is fully 3d printed, and internal parts are soldered together. This brief post will show the steps I took. 

Source of the project

PurpleFlup created this project on Thingiverse. I only made a slight change to the code, which I will explain shortly. Other than that, I really couldn’t see a way to improve on the grand design of this sensor. 

Parts required

Getting parts together.

The case only has two parts to 3D print. Both pieces are available with and without mounting screws. I printed both the front and back housing with mounting screw holes. On the front housing, I used the screw hole to mount the DH22 sensor. I didn’t use the screw holes on the rear housing and instead used a command strip to mount the completed sensor to the wall.

I used Glint Green from Filament One to print the parts. It is a great premium PLA.

Here are the electrical parts used to complete this project:

  • Arduino Nano – pin headers are not soldered to the board. I used an Elegoo board.
  • 16×2 LCD with backlight – I used HiLetgo HD44780 1602 LCD Display Module DC 5V 16×2 Character LCM Blue Blacklight.
  • DHT22 – I used AZDelivery 3 x DHT22 AM2302 Temperature and Humidity Sensor.
  • Mini USB Cable – The flavor of Nano I use utilizes a Mini USB connection.
  • 22 AWG solid wire – I used about 15cm lengths of Red, Black, and Yellow wire.

Assembly of the sensor

A look inside the housing after soldering was completed.

The assembly of the sensor was pretty straight forward. I just followed the schematic provided with the Thingiverse file. The only mistake I originally made was to start using stranded wire. But solid wire worked better to solder to the Nano and display.

Here are some tips I have for anyone who has don’t this type of project before:

  • Assemble on a breadboard before soldering. Getting everything soldered together and then finding a bad component just sucks.
  • Solder the sensor and display first. Then tie everything into the Arduino.
  • Use shrink tube, especially on the DHT22 sensor. The pins on the sensor move easily, and I think they would shorten if the shrink tube is not used.
  • Solder the red wires together before hooking them up to the Arduino.
  • Solder the black wires together before hooking them up to the Arduino.
  • Use shrink tube with the splices.
  • Try to lay the wires in the housing nicely after everything is soldered. The wire lengths I used at 15cm might have almost been a little long. But they fit in there nicely.

Programming the Arduino

The programming included with the 3d print worked great. I did make one change, however. Originally the code had the sensor display the temp in Fahrenheit, plus the humidity. I wanted to include Celsius as well. So I modified the code to show both C and F on the top line of the display. The second line of the display shows the humidity and is no longer labeled.

Below is the modified code I used. The required libraries were already installed in Arduino IDe for me. I think I already had the DHT.h library for the dht22 installed in Arduino IDE from an earlier project.

#include "DHT.h" //including the dht22 library
#include "LiquidCrystal.h"
#define DHTPIN 2 //Declaring pin 9 of arduino for the dht22
#define DHTTYPE DHT22 //Defining which type of dht22 we are using (DHT22 or DHT11)
DHT dht(DHTPIN, DHTTYPE); //Declaring a variable named dht
LiquidCrystal lcd(9,8,7,6,5,4); // Initializing the LCD pins.
void setup() { //Data written in it will only run once
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
dht.begin(); //This command will start to receive the values from dht22
void loop() { //Data written in it will run again and again
float hum = dht.readHumidity(); //Reading the humidity and storing in hum
float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
float tempf = dht.readTemperature(true); //Reading the temperature as Fahrenheit and storing in temp
// Check if any reads failed and exit early (to try again).
if (isnan(hum) || isnan(temp)) {
lcd.print("Failed to read");
lcd.setCursor(0,0); //Setting the cursor at the start of the LCD
lcd.print(temp); //Writing the value of temperature on the LCD
lcd.print(" C  ");
lcd.print(tempf); //Writing the value of temperature on the LCD
lcd.print(" F");
lcd.setCursor(0,1); //setting the cursor at next line
lcd.print("    "); //Writing the humidity on the LCD display
lcd.print(hum); //Writing the humidity value stored in hum on the LCD display
lcd.print(" %");

Final project

Temp/humidity sensor completed and hung by my desk.

Above is a picture of the final project mounted on my wall. Instead of mounting it using screws, I opted to use command strips. Overall this was a fun little project. Although honestly, it has been over twenty years since I’ve done any measurable soldering. Apparently, soldering is not something that gets easier with age.

Song of the Day: The Heat Is On

Yes, it really is that hot at my desk right now (27 C, 81 F). Glen Fry can interpret these sensor readings.

Bonus Song: Some Like It Hot

I actually don’t mind my desk area being this hot. As The Power Station says:

One comment

Leave a Reply