One thing that really bugs me about my Android phone (Nexus S) is the lack of a notification light. Anyone who has worked with me on hardware projects knows I love making LEDs flash... after all, my final university project was basically a giant flashing LED (portable traffic light). So one afternoon I decided to dig out my Arduino and "build what's missing". The plan was to create a simple Arduino program that accepts Bluetooth commands from my Android device to control an LED. Basic stuff, but a good way to dig into some new material, since I've never really touched the Android SDK. With that in mind, I dug out my electronics bag from the closet.
For this project, I only need a handful of parts:
- Arduino (in this case I'm using my old NG, but new users should try the Uno)
- Bluetooth module (I use the RN-41)
- LD1117 3.3V linear voltage regulator
- Some LEDs, of course
- Breadboard, resistors, capacitors, etc.
The Bluetooth module is pretty easy to interface to. Basically, it just needs a 3.3V rail, some logic connections (reset, status), and a serial interface (RX/TX). However, the Arduino works on 5V logic. Therefore, the only trick is generating the 3.3V power and signals. There's a bunch of ways to interface between different voltages, but here are a couple of the best:
- Voltage regulators (like the LD1117). These provide a stable voltage even when you add load.
- Switches (transistors, relays, etc.). Best option when you need to signal high current loads or use a low-voltage logic signal to drive a high voltage loads.
- Resistors. Sometimes you can get away with with just using a simple voltage divider circuit when you need to step down a signal (e.g. from 5V to 3.3V).
I used a voltage regulator to generate the 3.3V rail for the Bluetooth module, and a resistive voltage divider to step down the Arduino's serial output. The other inputs from the Bluetooth module don't need any conversion, since a 3.3V input will still drive a 5V input (sneaky). After that, we just run a couple LEDs connected to both the Arduino as well as the Bluetooth module's status pin (for debugging), and we're ready to go.
Multimeters are great for debugging electronics, but LEDs can be very useful as well. For example, the RN-41 Bluetooth module has several status pins that indicate things like connectivity, state, etc. I tend to hook everything up when I'm bringing up a new part and once it's working, take away everything but the essentials. This can save a lot of headaches when you miss a pull-up somewhere...
With everything in place, the only thing left to do (for now) is to power up the board and write a quick Arduino sketch to test the LEDs and make sure we can communicate with our Bluetooth module. Since the RN-41 is controlled with simple commands sent over the serial interface, it's easy to send a couple commands over to check that we connected everything correctly. For the RN-41, we send "$$$" to put the module into configuration mode; if the status LED starts blinking, you know you're in business.
Next time, we'll write the Arduino code that receives commands via Bluetooth to control our notification LED and build a simple Android app to run it.