Temperature-Humidity Meter

Posted on: Wed, 23/05/2018 - 13:19 By: Peter

Introduction

This project describes a simple device to measure temperature and relative humidity and displays their values, along with the apparent temperature, often describe as “feels like”.

Electronics

The Circuit

The sensor used is the ubiquitous DHT21, a digital sensor which in this case is read via a small MCU chip, an ATtiny84, and the output displayed on a 16 character by 2 line LCD display.

The circuit schematic is shown below, and dxf files are available for download at the bottom of the page.

Schematic
    

To make the device portable it is powered via battery, in this case a simple PP3 9V battery dropped to 5V by a 7805 voltage regulator.  Since the source is a battery no filter capacitors have been included in the power circuit.  To maximise battery life the press-to-make power switch is non-locking.  To use the device you simply hold down the button until the values appear in the display. 

The LCD display incorporates two potentiometers: VR1 controls brightness of the LCD’s backlight and VR2 the display’s contrast.  In theory, and if you wish to be cautious, VR1 should have a current limiting resistor in series between itself and the +5V to avoid it’s overheating in case the display is set too bright.  It has been omitted here as this is essentially a set-and-forget value that will not be used at very high brightness.  Also, the nature of the power switch means that the backlight will never be on for very long.

The MCU needs to be programmed and so the MISO, MOSI and SCK lines are taken out to a standard 2x5-pin ISP header.

The PCB

The printed circuit board used to make the device is illustrated below.  The yellow lines are the copper traces on the underside of the board, the red lines are jumper wires on top of the board and the green represents the locations of the components.  The jumper wires were used to avoid the complication of either a double-sided board or a board with too fine a separation between tracks.  Here the track gaps are all at least 0.8mm which simplifies creating the board on a cheap desktop milling machine.

PCB
    

Enclosure

The enclosure was cut from 3mm thick acrylic sheet (dxf files available below) and the finished product is pictured below.

PCB in case
   
Finished Project
    

Software

Code

The following program needs to be loaded into the MCU.  For simplicity it was written in the Arduino version of C++ and so can be uploaded using the Arduino IDE and an ISP programmer.  An Arduino board itself can serve as the programmer.

#include <LiquidCrystal.h>
#include "DHT.h"

#define DHTPIN 10
#define DHTTYPE DHT22

// initialise the LCD and specify how it is connected to the MCU.
const int rs = 6, en = 5, d4 = 0, d5 = 1, d6 = 2, d7 = 3;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

// Initialise the sensor and specify connection.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  lcd.begin(16, 2);  // WE are using a 1602 LCD.
  dht.begin();

  // Print a message to the LCD.
  lcd.clear();
  lcd.print("Reading...");
}

char buffer[18];

void loop() {
  
  // Wait a few seconds between measurements.
  delay(2000);

  // Read relative humidity
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    lcd.setCursor(0, 1);
    lcd.print("NaN");
    return;
  }

  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);
  // Display the data
  lcd.setCursor(0, 0);
  dtostrf(t,5,1,buffer);
  lcd.print(buffer);
  lcd.print("C ");
  dtostrf(h,5,1,buffer);
  lcd.print(buffer);
  lcd.print("% RH");
  lcd.setCursor(0, 1);
  lcd.print("Feels Like");
  dtostrf(hic,5,1,buffer);
  lcd.print(buffer);
  lcd.print("C");
}

 

Calibration

The manufacturer's data sheet claims that the DHT21 has a temperature accuracy of ±0.5ºC and a relative humidity accuracy of ±2-5%.  These estimates are perhaps optimistic and so the readouts of up to three figures should certainly not be taken at face value.  If greater accuracy is required then the code must be modified to allow for adjustment of the readings against a reliable calibration source.

Downloads

DXF Files

Software

MCU Code

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.