chipKIT Project 2: Temperature and relative humidity logger

Summary of chipKIT Project 2: Temperature and relative humidity logger


This project builds a PC-based ambient temperature and relative humidity logger using a chipKIT Uno32 and a DHT11 sensor. The DHT11 plugs directly into four Uno32 I/O pins (no extra wiring), powered by configured GPIO pins. The Uno32 reads sensor data every 2 seconds and sends bytes over USB-UART to a Processing application on the PC, which displays real-time values and logs timestamped samples to an ASCII file. Processing provides Start/Stop control and creates new log files per session; data can be exported for plotting.

Parts used in the PC-based temperature and humidity logger:

  • chipKIT Uno32 board
  • DHT11 temperature and humidity sensor
  • USB cable (for power and USB-UART connection)
  • PC running Processing (software)
  • DHT11 library for chipKIT/Arduino (software)
  • Processing Serial library (software)

This project is about building a PC-based temperature and relative humidity logger using the chipKIT Uno32 board and the DHT11 sensor. The project setup requires no additional wires (other than the USB cable) and components; the DHT11 sensor is directly plugged into four I/O pins of the Uno32 board and the project is ready to go. This could be a handy and an easiest way to setup an ambient room monitoring system for a server room. The Uno32 reads the temperature and relative humidity from the DHT11 sensor at preset interval and sends the data to PC through the USB-UART interface. A PC application is developed using the open-source Processing programming platform to log data onto an ASCII file. The PC application also displays the real-time temperature and relative humidity on computer screen.

PC-based logger for temperature and relative humidity
PC-based logger for temperature and relative humidity

Theory

Measurement of temperature and relative humidity using DHT11 sensor and PIC microcontroller for more details on the DHT11 communication protocol. The following picture describes the four pins of the DHT11 sensor.In this project, four pins of the DHT11 sensor is directly inserted into four I/O pins (7, 6, 5, and 4) of the Uno32 board. The power supply (1), data (2), and ground (4) pins of DHT11 go to I/O pins 7, 6, and 5 of the Uno32, respectively. The Uno32 pins 7 and 4 are configured as output pins and are set to High (3.3V) and Low (Gnd), respectively, through software to power the DHT11 sensor.

DHT11 pins
DHT11 pins

 

Inserting DHT11 on to I O pins 7-4 of Uno32
Inserting DHT11 on to I O pins 7-4 of Uno32

 

Complete setup of the project
Complete setup of the project

Note that an I/O pin of Uno32 can source up to 18mA current that is sufficient to power the DHT11 sensor, which only requires less than 5mA during data conversion and transfer. Pin 3 of DHT11 is unused. Temperature and humidity bytes are read through I/O pin 6 of the Uno32.

chipKIT sketch

Writing firmware is easier with the use of the DHT11 library available for Arduino or chipKIT platform. The DHT11 library for Arduino was originally written by George Hadjikyriacou and was later modified by other people. Make sure you include the library in your chipKIT sketch. The following sketch is for Uno32 to read the temperature and relative humidity data (two bytes) from the DHT11 and send them over the serial port. The sampling interval is set to 2 seconds.

/*
  Project 2:   PC-based temperature and humidity logger
  Description: The DHT11 sensor is used to measure the ambient
               temperature and relative humidity. The measured
               values are displayed on a PC and logged into a ASCII
               file through an application written using Processing.
  Board: chipKIT UNO32
 */
#include "dht11.h"
 
#define VCCPIN      7
#define DHT11PIN    6
#define GNDPIN      4
dht11 DHT11;
void setup()
{
  Serial.begin(9600);
  pinMode(VCCPIN, OUTPUT);
  pinMode(GNDPIN, OUTPUT);
  digitalWrite(VCCPIN, HIGH);
  digitalWrite(GNDPIN, LOW);
}/*--(end setup )---*/
 
void loop()
{
  int chk = DHT11.read(DHT11PIN);
  Serial.write(DHT11.humidity);
  Serial.write(DHT11.temperature);
  delay(2000);
}

Download the complete chipKIT sketch and library files

On PC’s side, the open source programming language Processing is used to develop an graphical application to display the received temperature and humidity information. Processing is an open-source software development environment designed for simplifying the process of creating digital images, animations and interactive graphical applications. It is free to download and operates on Mac, Windows, and Linux platforms. I have written a simple application here that receives the temperature and humidity bytes sent by the Uno32 board through the serial port, and display those information on a graphical window. The data logging part records the temperature and humidity samples plus date and time stamps on an ASCII file. The date and time are based on the PC’s RTC.

You should import the Processing Serial library first before accessing the serial port. This can be done by,

import processing.serial.*;

Next, you can open a serial port as

Dev_Board = new Serial(this, "COM12", 9600);

In my case the USB-UART module on Uno32 board appears as COM12. You should find the right COM number to make it work for you. In Windows machine, you can find this information from the Device Manager tool.

A clickable Start/Stop button is provided on the display window. The Processing Mouse functions are used to detect a mouse press over the button. When the Start is pressed, data logging begins and the label on the button changes to ‘Stop’. If Stop is pressed, the data logging is paused. The temperature samples are recorded along with the date and time stamp (from PC) into an ASCII file. Every time the Start is pressed, the program creates a new ASCII log file. The name of the file contains the current system date and time so that there won’t be any overwriting of files. However, the data are temporarily stored into the PC’s RAM and are transferred to the ASCII file on the hard drive only after pressing the Stop button.

Download the Processing source and applications

Output on computer screen
Output on computer screen

Here’s a sample of the output ASCII file where the temperature and relative humidity information are logged along with the time stamps.

Output record file
Output record file

The data from the log file can be read and plotted to generate graph using applications like MS Excel, or even the given Processing code can be modified further to plot the temperature and relative humidity vs time.

Quick Solutions to Questions related to PC-based temperature and humidity logger:

  • Can the DHT11 be powered directly from Uno32 I/O pins?
    Yes. The project powers the DHT11 by setting Uno32 pin 7 High (3.3V) and pin 4 Low (Gnd), and the sensor current requirement is less than the Uno32 I/O pin sourcing capability.
  • How is the DHT11 connected to the Uno32?
    The DHT11 four pins are inserted into Uno32 I/O pins 7, 6, 5, and 4, with VCC to pin 7, data to pin 6, ground to pin 5, and pin 3 unused.
  • How often does the Uno32 sample the DHT11 sensor?
    The sketch samples the DHT11 every 2 seconds (delay(2000)).
  • How does the Uno32 send data to the PC?
    The Uno32 writes the humidity and temperature bytes to the serial port over the USB-UART interface at 9600 baud.
  • What does the Processing application do?
    The Processing app receives serial bytes, displays real-time temperature and humidity, and logs timestamped samples into an ASCII file.
  • How are log files named and created?
    Each Start creates a new ASCII log file whose name contains the current system date and time to prevent overwriting; data are written to the file when Stop is pressed.
  • Do I need additional wiring besides the USB cable?
    No. The project requires no additional wires; the DHT11 is directly plugged into the Uno32 I/O pins and the USB cable provides the PC connection.
  • Which serial port settings are used in Processing?
    The example opens the serial port at 9600 baud; the device COM number must be selected (example: COM12).

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter