Bluetooth LE Go-Anywhere Sensor Pack

by intensePancake in Circuits > Sensors

30056 Views, 306 Favorites, 0 Comments

Bluetooth LE Go-Anywhere Sensor Pack

title_combo_v1.0.2.png

Introduction

In recent years, portable sensor devices have gained a lot of popularity due to their ability to give you instant, accurate information about your local environment. Some of these devices include the Sensordrone, Smart Citizen, and the Storm Tag. These devices combine portability and accessibility in such a way that they're easy to use and convenient to carry around. However, they can be expensive, as they're required to pack quite a bit of advanced technology into a very small package.

This Instructable is for my Bluetooth Low Energy Go-Anywhere Sensor Pack (BLEGASP, if you will). It's a device that I built from an Arduino and various environment sensors. Since environmental concerns differ from person to person, I wanted to create a device that maximizes sensor modularity. And so were born the objectives for this project:

  • To create a sensor pack that:
    • is portable
    • has reasonable battery life
    • measures useful data about the environment
    • communicates with a custom Android app
    • is customizable
  • To create an Android app that:
    • communicates with the sensor pack
    • can control the sensor pack
    • displays sensor data
    • is easy to use
    • is aesthetically pleasing

In order to accomplish these objectives, I decided that the communication should take place via Bluetooth Low Energy (Bluetooth LE, or BLE). Bluetooth LE, also known as Bluetooth Smart, is a wireless technology that's designed to allow effective communication between compatible devices while providing a significant reduction in the power consumption of those devices as compared to Classic Bluetooth.

The sensor pack that I built can report seven different quantities about the environment. These are temperature, relative humidity, heat index, barometric pressure, visible light intensity, infrared (IR) light intensity, and ultraviolet (UV) index. In this Instructable, I'll show you how to build the sensor pack that I built, program the Arduino with the sketch that I wrote to control it, and use the Android app that I wrote to communicate with it.

Contributions

Thanks to master of digital image creation and modification burstolava

Get Materials

0713142011.jpg
0707141204a.jpg
53c446cdd535cf6259000189.jpg
53c446eed535cf9e16000019.jpg
53c446ddd535cf625900018b.jpg
0707141434d.jpg
0714141702.jpg
0707141206b.jpg
top_schematic.png

Materials


Optional Materials


Tools

  • solder-less breadboard
  • soldering iron
  • solder

Connect the Bluetooth Low Energy Module

nRF8001_schematic.png
53c446cdd535cf6259000189.jpg
0709140921a.jpg
Screenshot_2014-07-14-15-00-20.png
monitor.png

Connect the BLE Module Breakout Board

Using your breadboard, connect the nRF8001 breakout board to the Arduino as shown in the schematic. This board is made by Adafruit Industries, and I used Adafruit's Arduino library for controlling it. The library is in the lib/ directory of my GitHub repository. Copy this library into your Arduino sketchbook/libraries/ directory so that the Arduino software can find it.

BLE Testing

At this point, you can already test out your Bluetooth LE connection! Here's how:

  1. Upload one of the example sketches inside the library onto your Arduino. There are two examples there, and both will work, but they work slightly differently. I used the callbackEcho demo.
  2. Install Nordic Semiconductor's nRF UART 2.0 app onto your Android device. If you're wondering, Nordic Semiconductor is the company that makes the nRF8001 chip.
  3. Make sure your Arduino is plugged into your computer, and use the serial monitor on the Arduino software to see what's happening.
  4. Run the app on your Android device.
  5. Send text from the Android to the Arduino or from the Arduino to the Android. If you see the same thing sent back, it works!


Learn More

If you're interested in learning more about Bluetooth Low Energy, Adafruit has a useful introduction to the technology. You can also check out the official Bluetooth Developer Portal and Android's BLE guide.

The breakout board for this Bluetooth LE module simulates a UART device to make it easy to send and receive data. There's plenty of information about UART and how it works on the UART Wikipedia page.

The nRF8001 breakout board uses a SPI bus to communicate with the Arduino. If you're not familiar with this bus, the Wikipedia page is a useful resource.

Connect the Temperature and Pressure Sensor

BMP180_schematic.png
53c446ddd535cf625900018b.jpg
0709140921b.jpg
bmp180_monitor.png

Connect the BMP180 Breakout Board

Connect the BMP180 breakout board as shown in the schematic. The board is made by SparkFun Electronics. I used their Arduino library to make measurements. Copy this library from the lib/ directory of my GitHub repository to your sketchbook/libraries/ directory.

Programming Note

The BMP180 sensor can function as either a barometric pressure sensor or as an altimeter, to measure altitude. I used it as a pressure sensor. When measuring pressure, though, you need to first measure temperature, and the sensor returns the absolute pressure. Absolute pressure varies with elevation, so we need to compensate for its effects. SparkFun's library includes a way to do this, but it requires that the Arduino knows our elevation. You'll need to change the ALTITUDE constant defined in the code you're using.

Test the Temperature and Pressure Readings

Testing this sensor is straightforward enough. Here are the steps:

  1. Open one of the examples from the library. I suggest using the SFE_BMP180_example, because that's the one I used for reference.
  2. Go to line 71 of SFE_BMP180_example.ino and change the ALTITUDE constant to be your elevation. You can find your elevation at veloroutes.org/elevation/. Be sure to enter your elevation in meters here.
  3. Upload the sketch to your Arduino.
  4. Use the Arduino Serial Monitor to see if it works.

Learn More

This board uses an I2C bus to communicate with the Arduino. If you're not familiar with this bus and want to learn about it, check out learn.sparkfun.com/tutorials/i2c/all and www.i2c-bus.org. There is also a good introduction to both I2C and SPI interfaces here.

Connect the Relative Humidity Sensor

DHT22_schematic.png
0707141434d.jpg
0709140921a.jpg
dht22_monitor.png

Connect the DHT22 Humidity Sensor

Connect the DHT22 humidity sensor as shown in the schematic. This sensor can also function as a temperature sensor. It can take both temperature and humidity readings every 2 seconds. Since I already had a temperature sensor on the BMP180 from Step 3, I didn't use the temperature sensor functionality here.

The Adafruit library for the DHT22 is in the lib/ directory of my repository. Just like the previous step, copy it from there to your Arduino sketchbook/libraries/ directory.

Test the Humidity Readings and Heat Index Calculations

The Adafruit library for the DHT22 sensor provides an easy way to read both temperature and relative humidity. The library can also perform a calculation of heat index. Heat index is a measure of how hot it feels due to the effects of both temperature and humidity. You can test these three values with the example sketch provided in the library directory. Here's how:

  1. Upload the DHTtester example sketch from the library onto your Arduino.
  2. Look at the serial monitor to see if it works. You should see a relative humidity reading, temperature in both °C and °F, and the result of a heat index calculation in °F.

Connect the Light Sensor

Si1145_schematic.png
53c446eed535cf9e16000019.jpg
0709140921b.jpg
si1145_monitor.png

Connect the Si1145 Light Sensor

Connect the Si1145 breakout board as shown in the schematic. The board is made by Adafruit, and I used their Arduino library for controlling it. The library is located with the other Arduino libraries in the lib/ directory of my GitHub repository. This board uses the I2C bus to communicate with the Arduino, just like the BMP180 barometric pressure sensor from Step 3.

Testing the Readings

The test sketch included with the Adafruit Si1145 library provides an easy way to test the sensor. Here's how:

  1. Upload the si1145test sketch from the library to your Arduino.
  2. Open the serial monitor and take a look. You should see relative readings of visible light intensity and IR light intensity, and a reading for UV index.

Measurement Notes

When measuring visible light intensity and infrared light intensity, the library is written to provide relative values. You'll get an idea of how much light there is hitting each photodiode, but you won't get measurements in lux.

UV index is a measurement of the strength of UV radiation. It provides an easy way to tell how much exposure you are getting to UV radiation at a specific place and time.

[Optional] Bypass Arduino's On-Board Regulator

LM2825_schematic.png
0714141702.jpg
0713141058.jpg

Arduino Uno 5V Regulator

The Arduino Uno uses a linear voltage regulator to provide its 5V power from an external input. In general, though, linear regulators are very inefficient. The efficiency of a linear regulator is usually well below 50%.

Since one of the goals of this project was to make the sensor pack as portable as possible, I decided to bypass the on-board linear regulator for a more efficient option. This provides better battery life for the sensor pack. I used an LM2825N 5 volt buck switching regulator as the 5V regulator. I ordered this part as a free sample from Texas Instruments. According to its datasheet, which is included in the doc/ref/ directory of my GitHub repository, its efficiency is typically about 80%. Much better!

Connect the LM2825 Buck Converter

If you want to bypass the on-board regulator like I did, connect the buck converter as shown in the schematic. Each of the outputs on pins 4-8 will provide 5 volts as long as the input is a high enough voltage. I used a 9V battery as the input.

Warning

Arduino specifically advises against bypassing the on-board regulator. Please be careful when connecting this part of the circuit. If you connect a wire to the Arduino's 5V input, and the wire voltage is not 5V, there is a chance that you will irreparably damage your Arduino board. I strongly recommend using a voltmeter to test the voltage at the output of your regulator and make sure it's 5V before connecting it to the Arduino.

Alternative

If you decide that you don't want to use the buck converter, using the on-board regulator is very easy. To use it, connect your battery to the Vin pin—not the 5V pin—on the Arduino board. As long as your voltage source is between 7V and 12V, you'll be perfectly fine.

Battery Life

For portable devices such as this one, battery life is an important factor. Using the external LM2825 buck converter, I've estimated the battery life of my completed project. To do this, I measured the current draw from the battery while the sensor pack was advertising its existence over Bluetooth LE. I measured 43.5mA. According to this Wikipedia page, a standard alkaline 9V battery has a capacity of about 565mAh. Drawing 43.5mA, this gives us a battery life of

565mAh / 43.5mA = 12.99 hours

So, advertising continuously, we'd get about 13 hours of battery life. Not too bad for a single 9V battery!

I didn't measure current consumption for other Bluetooth LE states. The current draw would probably be different, so any communication with other BLE capable devices would affect battery life in some way.

Verify Connections

top_schematic.png
0713141059a.jpg

Check Your Connections

If you've successfully done the tests for all of the sensors and the Bluetooth LE module, you can safely skip this step.

Otherwise, you should check the connections to protect against damaging something. You should make sure that:

  • No 3.3V power connection is connected to the Arduino's 5V pin
  • The 9V battery is either:
    • connected to the buck converter's input
    • connected to the Arduino's Vin pin
  • The buck converter's output is 5 volts and is connected to the Arduino's 5V pin
  • All ground lines are tied to the Arduino's ground
  • The I2C and SPI interfaces are connected properly

Download Arduino Code

0707141204a.jpg
arduino_code.png

Libraries

All of the Arduino libraries are available in the lib/ directory of my GitHub repository. Once you've downloaded them, put them all in your Arduino's sketchbook/libraries/ directory so that the compiler can find them.

  • Adafruit_BLE_UART - used to control the nRF8001 breakout board for communication over Bluetooth LE
  • Adafruit_Si1145 - used to get measurements from the Si1145 light sensor breakout board
  • DHT - used to get measurements from the DHT22 humidity and temperature sensor
  • SFE_BMP180 - used to get measurements from the BMP180 barometric pressure sensor breakout board

GitHub repository

All of the Arduino code required for this project is available at my GitHub repository. The main Arduino project file is BLE_sensor_pack.ino. Inside this file, update the constant REF_ALTITUDE_FT with your elevation in feet. Again, you can find your elevation at veloroutes.org/elevation/. Upload this sketch to your Arduino once you have the libraries in place.

Download Android App And/or Code

Screenshot_2014-07-14-18-33-09.png
Screenshot_2014-07-14-13-57-50.png
android_code.png

App Description

I wrote a BLE Sensor Pack app for Android devices. Bluetooth LE is only supported on Android 4.3 or later, so your device must adhere to that requirement in order to install it. The first screen is a screen with a connect button on it. When you hit 'Connect', the app attempts to find the sensor pack. If it finds it, it brings you to the next screen. In addition to the buttons at the bottom, pressing the sensor row will toggle that sensor's state.

Installation

This app works specifically with the sensor pack that I'm describing in this Instructable. Since it's so specific to the device, I've decided not to put it on the Google Play Store. The Android application package file (.apk extension) is in the app/ directory of my GitHub repo. There are several ways to install it. I emailed it to myself as an attachment, and opened the email with my Android device. It then asked me if I wanted to install the app.

Note: you may have to enable installation of apps from unknown sources on your device by going to Settings → Security and checking Unknown source.

Test BLE Sensor Data Communication

0709140920a.jpg
Screenshot_2014-07-14-13-57-39.png

Now that you have the circuit put together on a breadboard, the Arduino programmed, and the Android app installed, it's time to see the whole system in action!

You can use a battery here, but I recommend using a USB cable to power the Arduino at this step. That way, you can monitor the Arduino's state on the serial monitor.

  1. Apply power to the Arduino. It'll initialize the UART service over BLE and start advertising its existence.
  2. Start the Android app on your device. If you don't turn Bluetooth on first, it'll ask you for permission to do so.
  3. Press 'Connect' on the Android screen. The device should connect to the Sensor Pack.
  4. Turn sensors on/off and measure your environment!

Solder the Stackable Headers

0707141207a.jpg
0707141209.jpg
0707141431.jpg
0707141439.jpg

Now that we have a working system on a breadboard, it's time to make it smaller and much more portable!

Solder the Stackable Arduino Headers

  1. Place the perforated board that came with the Adafruit DIY shield onto the Arduino. Position the perf board how you'd like the final product to be aligned.
  2. Find where the stackable headers should go through the perf board so that they stack onto the Arduino pin headers. Reference the complete schematic to make sure you have access to all required pins, as the DIY shield doesn't come with quite enough headers.
  3. Push the headers through the perf board where they should go. Note that some of the headers are bent so that you can use perf board with standard 0.1 inch spacing. It'll be a bit harder to get these through the board.
  4. Make sure the board stacks onto the Arduino properly.
  5. Solder the stackable headers to the board. Don't make any connections just yet; just solder to keep the headers in place.

Assemble the Shield

0713141732a.jpg
top_schematic.png

Solder the Pin Headers and 24-pin Socket

I always try to avoid soldering parts like breakout boards and ICs directly into my circuit. Applying heat with a soldering iron directly to the pins can damage the board or chip. Instead, I suggest using female pin headers and IC sockets. This way, you can avoid damaging your components and make it possible to reuse them in the future without desoldering them first.

  1. Cut the pin headers so that you have the right number of headers for each part
    • 10 pins for the nRF8001 breakout board
    • 7 pins for the Si1145 breakout board
    • 5 pins for the BMP180 breakout board
    • 4 pins for the DHT22 sensor
  2. Position the pin headers and the 24-pin IC socket on the perf board so that everything will be positioned correctly once they're placed on the board. It may be useful to connect the components to the headers and socket to do this, but make sure to remove them before soldering.
  3. Once the headers are positioned properly, solder them to the board for stability.

Solder the Connections

Using the full schematic as a reference, solder everything together with wire. Don't forget to include the pull-up resistor and the capacitor.

Plug in the Components

Connect the components to the correct pin headers and IC socket. Be careful to connect them in the correct direction for your soldering. A quick test is to match up the voltage supply and ground pins. If they're okay and you're soldering is good, all the other connections should be correct.

Put It All Together

0713142011.jpg
0713141736.jpg
0713141747a.jpg
android_screenshot.png

Final Testing

Now that you've assembled the shield, it's time to test the finished product! The testing process is very similar to the testing in Step 10. Again, I recommend that you not connect a battery just yet. Instead, use a USB cable connected to your computer. Watch the serial monitor as you play around a bit with the Android app, turning various sensors on and off.

If everything works, great! If not, you'll have to debug the circuit. The Arduino serial monitor is your best friend here. Look at what is being printed, and possibly add your own Serial.print statements to see what's working and what isn't. Look at the solder joints that you made on the board, and try to find something that's wrong. Look for short circuits and loose wires. If you can't find the problem, use a multimeter to check connections and voltages at various points in the circuit.

Once everything has been tested, you have a working portable Bluetooth LE sensor pack and Android app! Congratulations!

Customize!

0714141356c.jpg
0713142011a.jpg
windows_screenshot2.png

Make it Your Own

I really like this project because it has so much potential for customization. It's as modular as I could make it, so you can add your own capabilities. What do you want it to do? Add that on!

Ideas

Here are just a few ideas for how you could build on this project and make improvements:

  • Improve battery life

The buck switching regulator that you added in Step 6 will allow you to drastically reduce power consumption of the Arduino while it's in sleep mode. Put it in sleep mode for some amount of time every loop and watch your power consumption drop! Obviously it can't always stay asleep, since it has to communicate with Bluetooth LE devices.

  • Customize the Android app

The Android development website provides great tutorials and documentation for Android app development. Get into it and turn the BLE Sensor Pack app into your own vision!

  • Add/Remove sensors

There are so many different sensors out there that you can add to this project! The Arduino has plenty of analog and digital I/O pins, and has hardware and libraries for handling buses like I2C and SPI. This makes it easy to add on nearly whatever you want.

  • Add other components

Maybe you want your Android device to be able to control your window blinds through the Arduino and stepper motors. Maybe you want to be able to set a cooking timer and have the Arduino send you a notification through your Android device when your meal is finished cooking. Build off of this project and add whatever components you want to realize your idea.

Whatever you decide to build, make it awesome. Good luck!