A BLE-enabled Dust Detector with Arduino and nRF8001
First created: Jul, 2014 // Last updated: Jul, 2014
Update: A self-made dust sensor of mine is documented here, as an alternative to the Sharp dust sensor below.
This article is a follow-up of a previous post on making a Sharp dust detector work with Arduino. Here I add a Bluetooth Low Energy (BLE) interface so that I can use a smartphone to access the dust detector output rather than an Arduino serial console.
Nordic’s nRF8001 is an IC with BLE stack programmed inside, and needs a microcontroller to work together. It uses a propietary but also well documented application controller interface (ACI) to interact with a microcontroller (which is Arduino in this case) through a modified SPI link. The nRF8001 breakout board used here is mostly built around the Nordic’s nRF8001 reference design (see Figure 21 in its datasheet) plus a logic level shifter (HJ4050 from TI) on the SPI pins (SCK, REQN, MOSI, MISO, RDYN). That is because the logic high is 3.3V for nRF8001 but 5V for Arduino. More information about nRF8001 is available in its datasheet.
I draw a block diagram as shown in Figure 1 to help understand how nRF8001, Arduino and smartphone work together.
Figure 1: nRF8001-Arduino-smartphone system block diagram
In plain English, nRF8001 is the hub where Arduino and smartphone exchanges information. In BLE speak, the smartphone client will be notified once the TX characteristics get updated on the nRF8001 server (new data from Arduino via ACI), and the data will be pushed from nRF8001 to smartphone. In the other direction, smartphone can also send data to nRF8001 (updating the RX characteristics), and nRF8001 notifies and sends the data to Arduino.
Figure 2 shows the circuit wiring. The part related to the dust detector is the same to the previous post. What is new are the pins connected to the nRF8001 breakout board as follows:
SCK (clock) on nRF8001 board –> Arduino digital pin 13
MISO (master-in slave-out) on nRF8001 board –> Arduino digital pin 12
MOSI (master-out slave-in) on nRF8001 board –> Arduino digital pin 11
REQ (chip-select) on nRF8001 board –> Arduino digital pin 10
RDY (nRF8001 ready) on nRF8001 board –> Arduino digital pin 2 (should be an interrupt pin)
RST (reset) on on nRF8001 board –> Arduino digital pin 4
GND on nRF8001 board –> Arduino GND
VIN on nRF8001 board –> Arduino 5V VCC
Figure 2: Circuit wiring
Part of the heavy lifting in software has been done by the friends from Adafruit as they publish Adafruit-flavored nRF8001 Arduino SDK on Github here, which, I believe, is based on Nordic’s BLE SDK for Arduino. Download the SDK, and install it as part of Arduino library by following this instruction.
A great part of the code below is derived from the echoDemo example. It pushes what is read from the amplifier output to nRF8001. Note that the code works for Arduino Nano and Uno. It may need slight change for other Arduino flavors. The code below is released under MIT license. Giving credits by linking this post in your work is very much appreciated but not required.
One needs a BLE client on smartphone to test the functionality of the circuit. First check your if your smartphone has BLE capability. Download an app named “nRF UART” from Google Play or App Store.
Open the app, click “Connect”. One should see the RX values being pushed to the smartphone once get connected. One should get something like in Figure 3: