loading

Since my study was not always at the best temperature, I decided it would be useful to display the ambient temperature on my desk. The cost of a sensor that provided humidity, in addition to temperature, was not prohibitive; therefore a display of humidity as well as temperature was included in this project.

Both the DHT11 and DHT22 sensors I considered provide temperature results in Centigrade. Fortunately it is an easy conversion to Fahrenheit (the format used in the USA, which is my location) . The sketch below displays temperature in both Fahrenheit and Centigrade, so it is applicable to whatever region of the world you are located in.

My initial project only involved temperature measurement, but since adding humidity was not too costly, I decided to include it in this project.

There are many published examples on-line showing how to display humidity and temperature using an Arduino UNO, some include displaying the results on an LCD. In this Instructable, we will also display the results on an LCD, but with the addition of power conservation that allows the LCD backlight to be toggled on and off when the display is not needed. This ability was meaningful to me, as I prefer to be able to turn the display off when I am not in the study.

If you are using a “wall wart” extra power consumption may not be of overwhelming importance, but if you are powering the display from a battery it likely is, as reduced power consumption will extend a battery’s life.

I considered both the DHT22 and the DTH11/12 sensors, and settled on the DHT22, although slightly more expensive. The DHT11 can often be purchased for less than $2, while the DHT22 is often found for less than $5. If purchased directly from China, the cost can be even less. If I only wanted to display temperature, I could have used instead the TMP36 sensor and realized some savings, and indeed this is how I built an earlier DIY of mine. However, I decided to include a humidity display in this project.

The DHT22 is slightly more accurate than the DHT11. So, the slightly higher cost of the DHT22 seemed reasonable. Both DTH devices contain capacitive humidity sensors. These humidity sensors are widely used for industrial and commercial projects. While not extremely accurate, they are capable of functioning at relatively high temperatures and have a reasonable resistance to chemicals in their surroundings. They measure the changes in a dielectric that are produced by the relative humidity of their surroundings. Fortunately, the changes in capacitance are essentially linear in relation to humidity. The relative accuracy of these sensors can be easily seen by placing two of them side-by-side. If this is done it will be seen that they differ by, at most, 1 or 2 percentage points.

The DHT11/22 sensors can easily be substituted for each other. Depending on cost constraints, if any, either sensor can be chosen. They both come in similar 4-pin packages that are interchangeable, and as we will see shortly only 3 of the 4 pins on either package will be needed to build the desktop humidity and temperature display presented here. Although only three pins are needed for use, the four pins provide additional stability when these DHT sensors are placed/mounted on a breadboard.

As will be seen in this Instructable, the project requires very few components as the majority of the “heavy lifting” is performed by the sensor and the sketch.

Step 1: The Required Items.

The required items are:

- An experimental platform

- An LCD shield

- A DHT22 (AOSONG AM2302) digital temperature and humidity sensor.

- Female headers to be soldered on the LCD shield. I used 5, 6, and 7-pin female headers (although if you select the alternative shield, also shown here, no headers will be needed). Male header pins can be substituted for the sockets, and if used only the gender of one side of the three Dupont hook-up wires will need to be changed.

- Three Dupont hookup wires (That is correct, only 3 wires are needed)

- An Arduino UNO R3 (Other Arduinos can be used in place of the UNO)

- A USB cable to upload your sketch from a computer to the UNO

A device such as a “wall wart” or battery to power the UNO after it is programmed. All required items are readily found on Amazon, eBay, Banggood, etc.

You possibly already have many of the needed items, if not all, on your workbench, although some may need to be purchased. When you have all the required items for this project, let’s begin. Although if you have the first few, it is possible to start while waiting on the others.

Step 2: Preparing the Experimental Platform

The experimental platform comes in a vinyl bag containing a 120mm x 83mm Plexiglas sheet, and a small plastic bag containing 5 screws, 5 plastic standoffs (spacers), 5 nuts and a sheet with four bumpers, self-adhesive feet. All four bumpers will be needed, as will four each of the other items. There is an extra screw, standoff, and nut that are not required. However, the bag does not contain instructions.

Initially the vinyl bag is cut open to remove the Plexiglas sheet and the small bag. The Plexiglas sheet is covered on both sides with paper to protect it in handling and transit.

We need to peel the paper back on each side of the platform and remove the two sheets. Once the paper is removed from each side, the four holes for mounting the Arduino to the platform are easily seen. I found it easiest if after peeling the paper away, the acrylic sheet is placed with the four holes on the right, and the holes closest together and near one edge of the acrylic board, facing me (as can be seen in the attached picture).

Step 3: Mounting the Arduino UNO or Clone to the Experimental Platform.

The Arduino UNO R3 board has four mounting holes. The transparent spacers are placed between the underside of a UNO R3 and the upper side of the acrylic board. Working on my first experimental board I made the mistake of assuming that the spacers were washers that should be placed underneath the Plexiglas board to hold the nuts in place - they should not. The spacers are positioned underneath the Arduino UNO board, around the screws after the screws pass through the UNO's mounting holes. After passing through the board the screws pass through the spacers and then through the holes in the acrylic Plexiglas board. The screws are terminated by the nuts enclosed in the small package. The screws and nuts should be tightened to insure that the Arduino will not move when in use.

I found it easiest to start with the hole nearest the reset button (see photos) and work my way clockwise around the Arduino. The UNO is attached to the board, as might be expected, using one screw at a time.

You will need a small Phillips head screwdriver to turn the screws. I found a socket to hold the nuts was quite helpful, although not necessary. I used drivers made by Wiha and available on Amazon [a Wiha (261) PHO x 50 and a Wiha (265) 4.0 x 60]. However, any small Phillips head screwdriver should work without problem, and as noted previously a nut driver is not really required (although it makes mounting quicker, easier, and more secure).

Step 4: Mounting the Half-size, 400 Tie Points, to the Experimental Platform.

The underside of the half-sized breadboard is covered with paper pressed onto an adhesive backing. Remove this paper and press the breadboard, with its now exposed adhesive backing, onto the experimental platform. You should try to place one side of the breadboard parallel to the side of Arduino it is closest to. Simply press the self-adhesive side of the breadboard onto the acrylic board.

Next, turn the platform over and mount the four included plastic feet on the four corners of the platform’s underside.

Whatever experimental platform you use, when you finish you should have both the Arduino UNO R3 and a half-size breadboard mounted on it, and four feet on the underside to allow the platform and breadboard to be placed on any flat surface without marring that surface, while providing firm support to the assembly

Step 5: The LCD Shield

You can use a shield, such as the one shown earlier with pins already soldered on. However, such a shield has pins rather than sockets, so the Dupont breadboard cables must be chosen accordingly. If so, you only need to mount it onto the UNO. When mounting be sure that you mount the shield in the correct orientation, with the pins on each side of the shield lined up with the sockets on the UNO.

If you use a shield, such as the one I use here, without pins already soldered in place set aside female headers with 5, 6, and 7 sockets, respectively, to solder onto the shield. The sockets of these headers should be on the component side of the shield when you solder them on (see photographs). Once the headers are soldered in place, you can proceed in a similar manner to that for a shield purchased with the pins already soldered on. I chose to use M-M Dupont cables as opposed to M-F cables, as I generally prefer M-M cables.

Whichever shield you select to start with, when you finish you should have a shield mounted on top of the Arduino UNO. Either shield, the one with pre-soldered pins or the one you soldered yourself with female headers, uses quite a few digital pins. Fortunately, digital pins D0 through D3 and D11 through D13 are not used by the shield, and so are available for use. Analog socket A0 is used by the shield to hold the results of button presses. Thus, analog pins A1 through A5 are free to use.

I find it easiest to use a breadboard with male headers inserted to hold the female headers for soldering (see photographs).

Digital pin 10 is used for the LCD’s backlight display, and we will use it in our sketch to control power to the LCD when the display is not in use. Specifically, we will use the “LEFT” button on the shield to toggle the backlight on and off to save power when the display is not needed.

Step 6: Using the DHT22 Humidity and Temperature Sensor

Insert the four pins of the DHT22 into the half-size breadboard, thereby mounting the sensor on the breadboard.

The DHT22 has four pins. I numbered these pins 1 to 4 as shown in the included photograph. The power to the sensor is provided via pins 1 and 4. Specifically, pin 1 provides the +5v power, and pin 4 is used for ground. Pin 3 is not used, and pin 2 is used to provide the information needed for our display.

Connect the three pins that are used on the DHT22, using their associated holes on the breadboard, to the shield, and thus the Arduino UNO as follows:

1) Pin 1 of the sensor goes to the shield’s 5v power socket,

2) Pin 4 of the sensor goes to one of the shield’s GND connectors,

3) Pin 2 of the sensor, the data output pin, goes to digital socket 2 on the shield and thus to D2 on the UNO, no analog connectors are required.

The DHT22 sensor can only provide updated information every 2 seconds. That is, if you pole the sensor more than once every two seconds you may get results that are dated.

Step 7: The Sketch

I have included the sketch I used below.However, this site removes less than and greater than symbols and the text in between these symbols. Thus, if you want to see the sketch as written just download the attached text file.

/*

Sketch to display humidity and temperature on the desktop

Written by R. Jordan Kreindler, July 2016

Uses an LCD Shield to display Humidity, as well as Fahrenheit and Centigrade

room Temperatures.

With the press of the ‘Left’ button the LCD backlight turns off and

with another press of this button the backlight turns back on.

The DHT22 sensor provides Centigrade temperature values which can be easily

converted to Fahrenheit.

*/

#include DHT.h

#include LiquidCrystal.h

// Be sure and encase the DHT.h and LiquidCrystal.h inside less than and greater than signs.

// The LCD shield uses digital pins 4 through 9

// and analog pin A0(for the buttons)

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Define a LiquidCrystal object, lcd

int DHTData = 3; // The data pin from the DHT22 is digital pin 3

DHT dht(DHTData, DHT22);// Define a DHT object, dht

int humidity = 0; // Holds humidity results as an integer

float cTemp = 0.0; // Holds Centigrade temerature results as a float

int centigradeTemp = 0; // The Centigrade temperature after conversion to int

int fahrenheitTemp = 0; // Will hold the converted to Fahenheit temperature

int i = 0; // A for loop index

int delay1 = 700; // The time between text displays

boolean backlightOn = true; // Holds state of backlight

int adcValueRead = 0; // Start with a value in adcValueRead

void centered(int line, char str1[]) {

// Written by R. Jordan Kreindler June 2016

int length1 = strlen(str1);

int spaces = (15 - length1) / 2.0;

lcd.setCursor(0, line);

lcd.print(" "); // Should show 16+ spaces between quotes, but Instructable.com removes spaces

lcd.setCursor(0, line);

for (i = 0; i <= spaces; i++) {

lcd.print(" ");

}

lcd.print(str1);

}

void setup() {

lcd.begin(16, 2);

lcd.clear();

pinMode(10, OUTPUT); // Set pin 10 for output to turn backlight on/off

digitalWrite(10, HIGH); // Set LCD backlight on

dht.begin(); //Starts the DHT22 sensor

lcd.setCursor(0, 0);

lcd.print("'Left' is On/Off");

}

void loop() {

humidity = round(dht.readHumidity());

lcd.setCursor(0, 1);

lcd.print("RH:");

lcd.print(humidity);

lcd.print(" ");

cTemp = dht.readTemperature();

centigradeTemp = round(cTemp);

fahrenheitTemp = round(cTemp * 9.0 / 5.0 + 32.0);

lcd.print("F:");

lcd.print(fahrenheitTemp);

lcd.print(" ");

lcd.print("C:");

lcd.print(centigradeTemp);

lcd.print(" ");

adcValueRead = analogRead(14); // Check if any buttons pressed

if ( (adcValueRead >= 400 && adcValueRead <= 500) && backlightOn == true) {

lcd.clear();

lcd.print("Powering off ");

for (int i = 1; i < 4; i++) {

lcd.print(".");

delay(500);

}

digitalWrite(10, LOW); // Set LCD backlight off

backlightOn = false;

adcValueRead = 5000;

}

if ( (adcValueRead >= 400 && adcValueRead <= 500) && backlightOn == false ) {

Serial.println(adcValueRead);

digitalWrite(10, HIGH); // Set LCD backlight on

lcd.clear();

lcd.print("Powering on ");

for (int i = 1; i < 4; i++) {

lcd.print(".");

delay(500);

}

backlightOn = true;

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("'Left' is On/Off");

}

}

Step 8: The Assembled Project in Use

I mounted my assembled project on a business card holder (see photograph). The business card holder shown in the attached photograph was available in my ‘odds and ends’ collection, so I used it. However, the assembled project could just as easily be placed and displayed on a mobile phone holder. Any holder that takes the assembled project from a flat position to an angle of 30-60 degrees should work well.

Step 9: Afterwards

Congratulations, if you followed the steps above you now have your own humidity and temperature display, including a power saving mode.

If you decide you would like to extend the information displayed, this Instructable can serve as a starting point. In another project I added a real time clock (RTC) module, in addition to the sensor used here, so I could include the day of the week, month, day of the month, and current time in the display. I also presented less information (I did not include the temperature in Centigrade) on line two of the display so I could include the %, percent, and ⁰, degree, symbols (see attached photograph).

Perhaps, this Instructable may suggest possible follow-on projects for you, in addition to the date and time display discussed in this step.

If you would like to contact me with any questions or for additional information, or to expand my knowledge in the area presented, I can be reached at transiintbox@gmail.com. (please replace the second 'i' with an 'e' to contact me.

<p>This is cool, any idea how I could make output on analog dials using a stepper motor?</p>
<p>Dear MichaelR411,</p><p>Thanks for taking the time to comment.</p><p>If you want to use steppers, you should consider using a half-step algorithm. For most steppers that would give you 100s of steps, which should allow sufficient precision for the appropriate displays.</p><p>I use half stepping in Part 3 of my Instructable tutorial, &ldquo;DC Motors: Continuous, Gear, Servo, Brushless, Vibration, and Stepper, A Tutorial&rdquo;. However, I have only published Part 1 recently, and although Parts 2 and 3 are already written in draft, I will need time to edit and expand them slightly. That is, Part 3 is not yet posted and it will be a while before it is.</p><p>If you can wait until I post Part 3 that's great, as I believe I have two projects and sketches, in that Part that use half-stepping. If you use half stepping, you can set up an appropriate conversion factor to change the relative humidity and temperature values to inputs that could be used by the steppers.</p><p>If you use the humidity values (0 to 100% relative humidity) and &ldquo;reasonably expected&rdquo; temperature values, e.g., 60-90 degrees. The display of these should be even easier to read. You may want to just display &quot;reasonably expected&rdquo; humidity values as well, so as to expand that display also. By using half-stepping you will have quite a number of potential angles to select from.</p><p>Please let me know how your analog project works out for you.</p><p>The very best, and thanks again for your comments.</p>
Sure i can wait. Thanks mate, I am looking forward to seeing it. :)
<p>Dear MichaelR411,</p><p>Your welcome, and the very best of luck. </p>
<p>Is your &quot;<em>Power Saving mode</em>&quot; just allow the user to turn off the LCD backlight while still leaving the LCD on and updating it while no one is there ?</p><p>I was expecting low power mode or interrupts or anything, but the provided code while clean and easy to read is still looping as fast as it can, reading the sensor, and updating the LCD both more than once a second.</p><p>In the datasheet they warn not to send any commands to the DHT22 within 1 second of power up to avoid bad data and they say sample period should be <strong>greater </strong>than 2 seconds. This means you could enter a lower power mode or not poll the DHT22 &amp; update the LCD for 2 seconds while waiting for a keyboard press.</p><p>I have found three distinct datasheets for the Aosong DHT22 (also know as AM2302);</p><p>1) (bad but readable English if English is your primary language) is here; <a href="https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf" style="">https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf</a></p><p>2) <a href="http://akizukidenshi.com/download/ds/aosong/AM2302.pdf">http://akizukidenshi.com/download/ds/aosong/AM2302...</a></p><p>3) <a href="https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf">https://cdn-shop.adafruit.com/datasheets/Digital+h...</a></p><p>I hope this information is of use to you and your readers. thank you for your instructable.</p>
<p>I made something somewhat similar.</p><p>Using a RTC (Real Time Clock) and a temp detector, it tracks the temperature since power on displaying the current as well as high and low. It also logs the information to an sd card</p>
<p>Dear TimN33,</p><p>Hi and thank you for taking the time to write. Your project is awesome. Thank you for sharing. I had thought about using a 2004 instead of the 1602 LCD display, but I could not find a shield for the 2004 LCD which meant I would have had, perhaps, more problems in attempting to raise it for viewing.</p><p>As you can tell from the last picture, I have now extended this project to include the day of the week, calendar and time (hours and minutes) as well as relative humidity and temperature. Based on the email I have received, I will likely post that as a separate Instructable.</p><p>Your logging to an SD card is an interesting and useful idea, as is the display of low and high temperatures. Both are items I did not have any requirements for. Although, they clearly provide additional information not available in my project, and are worth considering for a future project.</p><p>My Instructable finishes with, &ldquo;Perhaps, this Instructable may suggest possible follow-on projects for you, in addition to the date and time display discussed in this step&rdquo;. You did not need this Instructable to find a project extension that worked for you. Congratulations on a great project. The very best.</p>
<p>Meant to ask, are you using a RTC for time or some sort of sync with PC?</p>
<p>Dear TimN33,</p><p>Hello again; thank you for the question. I am using a DS3231 real time clock (RTC) in the last picture shown.</p><p> One of the reasons I display the results without decimals is to avoid frequent changes in relative humidity or temperature. The second is that, based on my personal measurements, it does not seem that the DHT22 can provide accurate decimal results.</p><p>The very best.</p>
<p>Thanks!!! The 20x4 was easy since it used I2C (as does the RTC and device I'm using for temperature readings) so it's basically 4 wires including power and ground using the LiquidCrystal_I2C.h library. I did not like the idea of having it sample as fast as it could go (free running) and it wasn't easy to set it for roughly 1 second intervals, so I use an interrupt from the RTC set for 1 second intervals and that triggers the updates.</p><p>Thanks for the encouragement</p><p>Tim</p>
I'm in the same boat. I use a DS3232 and the alarm interrupt for 1 second triggers.<br>Interesting that what I do is to only update the temperature if the change is &gt; .2 degrees since it does vary randomly a bit in the tenths of a degree.<br><br>I'm using a MPU-6050 for the temp readings. Its actually a gryo/accellerometer but can read temperatures too.<br>The RTC has a temperature reading, but as you may have read, it only updates every minute or 2...
<p>By the way, for my post, ignore the ribbon cable on the right.. I also use it with a raspberry pi which is not connected</p><p>The monitor is interrupt driven and updates every second, but logs every 10 seconds to the SD card. It sends the data on the serial port so I can use the serial plotter to graph it or open the datafile later in excel</p>

About This Instructable

3,739views

105favorites

License:

More by R Jordan Kreindler:Arduino Stepper Drivers Tutorial-2/2 Arduino Stepper Drivers Tutorial-1/2 DC Motors Tutorial-3/3: Steppers 
Add instructable to: