Long-time readers will know I’m not one to promote trendy marketing phrases and certainly ‘Internet of Things’ or ‘IoT’ is right up there with the best (worst) of them. But the concept behind the phrase is worth understanding as it drives the next generation of connected devices.
Single-function or ‘embedded’ gadgets built from microcontrollers like the Arduino’s Atmel ATMEGA328P can now jump on-board the internet, thanks to the proliferation of low-cost wireless connectivity.
So this month, we’re introducing you to the developer’s view of Bluetooth with a basic example of how to connect up an Arduino Uno to an Android device using this low-power wireless technology.
Wireless Light ‘n’ Sound
And to do that, we’ve come up with a project guaranteed to provide seconds of memorable entertainment that lets you turn a piezo buzzer on and off, plus – fade an LED up and down. It’s called (drumroll, please) Wireless Light ‘n’ Sound.
Okay, so it won’t turn up on a TED talk any time soon – but, you’ll learn how to add Bluetooth connectivity to your own projects. And all for less than $6.
Cheap Bluetooth hardware
Not that long ago, adding wireless to anything would cost an arm and a leg, but in recent times, Bluetooth technology prices have crashed dived and you can now pick up an HC-06 Arduino-ready Bluetooth transceiver (that’s transmitter and receiver) for under $6, including shipping.
Bluetooth is a low-power personal-area-network wireless communications standard that’s good for up to 10 metres in ‘clear air’ (meaning ‘no obstacles’). But the beauty of the HC-06 is that, to the Arduino Uno, it looks like just a standard serial device. There isn’t even a special library you have to add.
There’s just one small problem – the Arduino Uno only has one serial port, consisting of pins D0 (RX) and D1 (TX) – and it’s normally used, first, to upload your sketch to the Uno’s on-board program storage; and second, to provide rudimentary debugging via the Serial Monitor. If we pinch the Serial port for the Bluetooth module, neither of those other two functions will work.
But this isn’t an uncommon problem for the Uno and the Arduino IDE has a built-in solution called SoftwareSerial. The idea is to simulate a real serial port in software, allowing us to use any two other digital pins to do the job and it works extremely well – except here.
Unfortunately, the SoftwareSerial library is a bit slow, but we’ve found an alternative software serial library that, unsurprisingly, is called the Alternative Software Serial library or AltSoftSerial. It’s stunningly easy to use and works perfectly.
Our project
You can see the design of our project in the circuit diagram. The HC-06 module has just four-pins – transmit (TX), receive (RX), Vcc (5V) and GND (0V).
It’s designed to work off a 5VDC voltage rail, however, the logic level (the voltage level of the data) is only 3.3V, so in order to protect the Bluetooth module from blowing up, we’re providing its RX input with a simple voltage divider consisting of a 4.7Kohm and 10kohm resistor that drops the 5VDC output of the Arduino’s D9 pin to the required 3.3V (or thereabouts).
The rest of the project hardware is very simple – we’ve connected an LED to the Arduino’s D6 pin in series with a 470ohm resistor, plus a 5VDC piezo buzzer to pin D3 (you can pick up these piezo buzzers for about $2 on eBay).