mercoledì 5 marzo 2014

How to make a bluetooth datalogger for temperature and humidity.

In this project I use an Arduino Mega (2560) board, a DHT22 sensor (more accurate than DHT11 sensor), a 10 kΩ resistor, a 10 kΩ trimmer, a 2 x 16 LCD display, a HC-05 bluetooth serial adapter, a RTC module (from Adafruit: and a SD card module (from Adafruit:

This is a complete datalogger for temperature and humidity, infact it saves these two values with the time every 10 minutes (you can set this frequency in the sketch as you like, even if I suggest not less than 10 minutes because the file becomes too big) in a CSV file stored into the SD card. The sketch creates automatically the path for the log files using the path /templog/yy/mm/dd. You can read the logs putting the SD card into your pc's card reader or using the bluetooth connection.

Download the software from github
Here are the sketch, the python script and the Fritzing schematic.

Schematic (Fritzing, available on the repository)

After connecting the parts, create a folder in the SD card and name it templog.Power on your Arduino. It will soon start to measure temperature and humidity and to save them on the SD card.

Example of Bluetooth module with adapter

Inside the sketch you can set some variables:

max_battery_voltage        if the power supply is a battery you can set here its voltage (the display shows the charge level)

minutes_updatefile        the sketch updates the log file every "minutes_updatefile" minutes

seconds_updatedatehour        the sketch updates the date and the time on the lcd display every "seconds_updatedatehour" seconds

seconds_updatemeasurelcd        the sketch updates the temperature and the humidity values on the lcd display every "seconds_updatemeasurelcd" seconds

seconds_updatemeasurebattery        the sketch updates the measure of the charge of the battery every "seconds_updatemeasurebattery" seconds

pathbase        this is the root folder for the logs on the SD card (default is templog/)

The sketch has some internal commands:

rf&:   the "read file" command
sf&:   the "size file" command
mth&:  the "measure t/h" command
rdt&:  the "read date/time" command
tsd&:  the "type sd card" command
ssd&:  the "size sd card" command
fm&:   the "free memory size" command
sdt&:  the "update date and time" command
rbt&:  the "read voltage battery" command

You can interact with the data logger via the bluetooth connection and the script Download this script from the github repository and put the name and the MAC address of your bluetooth module in this script (for example, in my script they are BT1 and 00:13:04:10:06:20).

Here are some examples of usage:

python -dn BT1 -cl "mth&?" reads temperature and humidity
python -dn BT1 -cl "rdt&?" reads date and hour
python -dn BT1 -cl "sf&14/01/20?" reads the size of the specified file  (format:  yy/mm/dd)
python -dn BT1 -cl "rf&14/01/20?" reads the specified file  (format:  yy/mm/dd)
python -dn BT1 -cl "tsd&?" reads the type of SD card
python -dn BT1 -cl "ssd&?" reads the size of SD card
python -dn BT1 -cl "fm&?" reads the size of free memory in microcontroller
python -dn BT1 -cl "sdt&2014&01&21&14&30&00?" sets date and hour (format:  yyyy, mm, dd, hh, mm, ss)
python -dn BT1 -cl "rbt&?" reads battery voltage

The datalogger working

A zoom of the display