Reader small image

You're reading from  Arduino Home Automation Projects

Product typeBook
Published inJul 2014
Publisher
ISBN-139781783986064
Edition1st Edition
Tools
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

Chapter 3. Measuring the Temperature Using Bluetooth

In this third chapter of the book, we are going to use yet another technology for home automation purposes. We will use a very commonly used technology for sensors, namely, Bluetooth. We are going to interface a Bluetooth module with Arduino, make some measurements using Arduino, and transmit this data back to your computer via Bluetooth. To receive and display the data on your computer, we are going to use the programming language Python.

The following are the major points we will see in this chapter:

  • We are first going to select the different hardware components for the project, including the Arduino board, the Bluetooth module, and the temperature and humidity sensor. At this point, we will also install the different software components that are required for the project.

  • Then, we will actually build the hardware part of the project. To do so, we'll connect the different components together using a breadboard and some wires.

  • Right after...

Hardware and software requirements


Let's first see what we need to build this project. The project is once again based on the Arduino Uno board, but it will also work with other Arduino boards such as Arduino Mega. Due to the differences in the architecture, especially in the behavior of the serial port, some more recent boards such as Arduino Due or Arduino Leonardo might now work with the code that we are going to build in this project.

Then, the other important component of the project is the Bluetooth module. I used the Bluefruit EZ-Link Bluetooth module from Adafruit for this project. It integrates a Bluetooth chip and all the required electronics for the module to work with Arduino. It is really easy to use and interfaces directly with the serial port of your Arduino board.

Note

You can find documentation on this Bluetooth board at the following URL:

https://learn.adafruit.com/introducing-bluefruit-ez-link

Of course, it should be possible to use other Bluetooth modules for this project...

Hardware configuration


Let's now build our project. We will have to connect the different modules and sensors with Arduino, connect the smaller components (such as a resistor and capacitor), and connect everything together using jumper wires.

To help you out in visualizing the different connections that have to be made, you can have a look at the following image:

To build our project, let's execute the following steps:

  1. The first step is to place the Arduino board next to the breadboard so that you can easily make different connections. You can also place the Bluetooth module at this point. When you are done with placing the components, you should have something similar to the following image:

  2. We'll now take care of the connections of the Bluetooth module, starting with the power. You have to connect the GND pin of the Arduino board to one of the blue power rail of the breadboard, which will be the negative rail from now. You can also connect the 5V of the Arduino board to the red power rail...

Creating the Arduino sketch


Let's now build a simple sketch to test our sensor via Bluetooth. We are going to build a sketch so that it measures the temperature and humidity from the DHT sensor when a given command is received on the serial port.

We start by including the DHT library so that we can use the DHT11 sensor:

#include "DHT.h"

Then, define the sensor's pin and type:

#define DHTPIN 7
#define DHTTYPE DHT11

Note that if you are using a different DHT sensor, you will need to modify the code here. For example, if you are using a DHT22 sensor, simply type the following:

#define DHTTYPE DHT22

You will also need to define an instance of the DHT sensor and to send the sensor type and sensor pin as an argument:

DHT dht(DHTPIN, DHTTYPE);

In the setup() function of the sketch, you will have to initialize the DHT sensor's instance and start the serial connection:

dht.begin();
Serial.begin(115200);

We need to use a speed of 115,200 bauds here instead of the standard 9600 bauds, as it is recommended in...

Testing the temperature and humidity sensor


It's now time to compile the sketch and upload it. To do so, we are going to use the Bluetooth connection. Let's execute the following steps to test the temperature and humidity sensor:

  1. Once your project is powered up (either by using a USB cable or an external power source), you can go to the Bluetooth preferences of your operating system. You should see that the Bluetooth module has been detected. Note that the name of this Bluetooth module will change depending on your own module, as shown in the following screenshot:

  2. Just click on the pair button (or a similar button depending on your operating system) and the Bluetooth module should be linked to your computer.

  3. Now, let's get back to the Arduino IDE. You should now be able to select the Bluetooth module in the serial ports' list. At this point, you can either select the one starting with tty or cu; it does not matter for testing purposes. Note that depending on your setup, you will see different...

Measuring the temperature and humidity remotely


Now that the basics of the project are working, we can go further. We clearly don't want to constantly have the serial monitor from the Arduino IDE open and type commands by hand. This is why we need to build a graphical interface on your computer.

In this section, we are going to build a simple graphical interface using Python and the graphical library that comes with it, Tkinter. All the code will simply be contained in a Python file that can be executed later to open the interface.

The first step of the Python code is to import the correct Python modules. Python modules are basically like Arduino libraries; they add additional functions to Python. We need the time module, the serial module that we installed before, and every other component of the Tkinter module:

import time
import serial
from Tkinter import *

If you need more information on the Tkinter module, you can visit the official documentation page at https://wiki.python.org/moin/TkInter...

Summary


In this project, we built a Bluetooth– and Arduino–based temperature and humidity sensor. Using this sensor, you can measure data that comes from your Arduino board via Bluetooth and display this data on your computer.

Let's see the major takeaways from this chapter. In the first part of the chapter, we chose the components of this project, including the Bluetooth module and the temperature and humidity sensor. We also downloaded and installed the required software components of the project.

Then, we built the hardware part of the project and made the required connections on the breadboard. We connected the Bluetooth module and the temperature and humidity sensor to the Arduino board.

Then, we spent some time building the main sketch of the project. At the same time, we tested the project by checking whether the Bluetooth connection was actually working. We also checked whether the temperature and humidity sensor was working correctly.

Finally, we used Python to build a simple interface...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino Home Automation Projects
Published in: Jul 2014Publisher: ISBN-13: 9781783986064
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz