Bluetooth DHT Temp & Humid Sensor
Bluetooth DHT Temp & Humid Sensor
Guide Contents 2
Introduction 3
Connections 4
Arduino sketch 5
Python interface 8
Bluetooth devices are widely used in many consumers products, its the most popular wireless
protocol for small point-to-point networking. Every laptop and just about every computer has
Bluetooth classic built into it, so you often don't need a data receiver for a computer. And
recently, the Bluefruit product family has made it even easier to integrate Bluetooth in an
Arduino project. So why not use this technology in a simple home automation project?
Bluetooth is fast, low-power, and you can communicate with Bluetooth devices directly from a
computer because they usually have built-in Bluetooth capabilities. The other nice thing is that
with this project, you will be able to change the sketch running on your Arduino via the
Bluetooth connection, without having to plug any cables!
In this project, you will learn how to connect a Bluetooth module to Arduino, transmit
measurements from a temperature & humidity sensor to your computer, and display the data in
a nice Python interface. Let's start!
The hardware configuration consists in two parts: connecting the Bluetooth EZ-Link module to
the Arduino board, and then connecting the DHT22 temperature/humidity sensor.
The EZ-Link will take care of the wireless data transmission, and the DHT22 is a sensor. The
Arduino sits between the two, reading data from the DHT22 sensor and then sending the data
to the EZ-Link module.
Before you start this section we suggest going thru the tutorials we have for both these
components!
EZ-Link tutorial (http://adafru.it/d8q)
DHT22 tutorial (http://adafru.it/d8r)
Start by plugging the Bluetooth module on the breadboard. You then need to connect the
power for the Bluetooth module: the 5V coming from the Arduino board, and the Ground pin.
Now, we have to make the connections from the Bluetooth board to the Arduino so that both
can communicate via the Serial connection. Connect the Bluetooth TX pin to the Arduino RX (pin
0), and the RX pin to the Arduino TX (pin 1). You also have to connect the DTR pin of the
Bluetooth board to the Arduino Reset pin (which is next to the 3.3V pin), via a 1uF capacitor (the
negative side of the capacitor is marked with a gray line, and should be on the side of the
Arduino Reset pin).
Finally, you need to plug the DHT temperature sensor to your project. Pin number 1 goes to the
Arduino 5V, pin number 2 to Arduino pin 7, and pin number 4 to Arduino Ground. Finally, place a
resistor (between 4.7K and 10K) between pin number 1 and 2 of the DHT sensor.
For this project, you will need the Arduino IDE (http://adafru.it/d8v) installed, along with the DHT
sensor library (http://adafru.it/aJX) and the Python PySerial module (http://adafru.it/cLU).
We'll first test the Bluetooth module to see if everything is connected correctly. You need to
pair the Bluetooth module with your computer first. It depends on your OS, but you will usually
have a "Bluetooth preferences" menu to search for new Bluetooth devices:
Once the device is paired with your computer, you can reopen the Arduino IDE and test if the
Bluetooth connection is working. In Tools>Serial Port, you should have new choices for your
Bluetooth device. Choose the second one:
You can now work with the Arduino IDE as if the Arduino board was directly connected to your
computer: you can plug your Arduino board to an external source of power like a battery, and
use the Bluetooth connection to upload sketches.
To try it out, just load the "Blink" sketch, and click on upload: after a while the sketch should be
uploaded (it takes longer than with a USB cable) and the onboard LED of the Arduino Uno should
blink.
We now need to write the code for the Arduino, so it measures the temperature & humidity
when it receives a given command on the Serial port. This command will later be sent by your
computer, but for now we'll just make a simple test to make sure the Arduino part is working.
The core of the sketch is to make the Arduino answer with the temperature & humidity
measurement on the Serial port when a given character is received. I chose the character "m"
for "measurement" to make the Arduino send the measurements over the Serial port. This is
the part of the code that does exactly that:
int h = (int)dht.readHumidity();
int t = (int)dht.readTemperature();
// Setup
void setup(void)
{
dht.begin();
Serial.begin(115200);
}
void loop(void)
{
// Get command
if (Serial.available()) {
// Read command
byte c = Serial.read ();
int h = (int)dht.readHumidity();
int t = (int)dht.readTemperature();
Now upload the sketch (via Bluetooth of course!), open the serial monitor, and type in "m" and
click send. This is what you should see on the Serial port:
Finally, we need to build an application running on your computer to send the order to get new
measurements from the Arduino board, retrieve the data, and display it on your screen. I chose
Python for this interface but it's quite easy to interface with the Serial port with PySerial, and it is
also easy to build an interface with Tkinter which is installed by default with Python.
I won't detail every piece of the code here because it's way too long, but you can of course find
the complete code in the GitHub repository for this project (http://adafru.it/d8w).
serial_speed = 115200
serial_port = '/dev/cu.AdafruitEZ-Link06d5-SPP'
ser = serial.Serial(serial_port, serial_speed, timeout=1)
Then, the core of the Python script is the measure() function that is continuously executed
every second:
Then, the rest of the script simply displays this data on a simple Tkinter window. You can get
the complete code from the GitHub repository for this project (http://adafru.it/d8w). Finally,
type "python sensor_gui.py" in a terminal. This is what you should get:
Each new Bluetooth module that you add will appear as a new Serial Port on your computer, so
you can perfectly have several of these Bluetooth-based sensors in your home and build a
whole home automation system from it!