We're always interested in how many folks are viewing our WNYC Data News projects at a given moment, and Chartbeat answers that question. But we don't always want to watch Chartbeat's dashboard for the latest info.
Enter the blinkies.
Using a string of colored LEDs, an Arduino and a little bit of code, we now have an ambient indicator that generally reflects our traffic and alerts us when thing get intense. A program running on my desktop computer checks Chartbeat for the latest number of simultaneous and passes that information across the room using Bluetooth, something I've wanted to play with for a while.
For the Bluetooth component, I walked slowly through the SparkFun Bluetooth guide, which was fascinating and fun. Communicating with something across the table is a trip.
Here's the parts list:
- Arduino Uno
- Neopixel LED strip (60 LEDs, 2 meters)
- Female power jack connector
- 5v Power supply for LED strip
- 9v Power supply for Arduino
- SparkFun Bluetooth board
- 6-pin Female right-angle header
- Jumper wires
I attached the power plug onto the LED strip and I soldered the right-angle header onto the Bluetooth board, which allowed me to use breadboard jumper wires to connect it. (I've really loved knowing how to solder. It's kinda like when I learned how to type. Get great info here.) I then wired it all together based on the tutorials.
Here's my final circuit:
There are two places I'm using code -- on the Arduino and on the desktop. I do the heavy lifting in the desktop code, which:
- Establishes communication with the Bluetooth module across the room
- Checks Chartbeat for the latest stats using the Chartbeat API
- Calculates the number of LEDs to light
- Sends a "p" and that number over the air to the Arduino.
Steps 2-4 repeat endlessly every minute. There's also code to watch for a threshold "alarm" which triggers a separate transmission to light up the strip in a new color (more on that below).
Here's the Processing code:
The Arduino code listens to the Bluetooth for the letter "p" followed by the number of LEDs to light.
The the Arduino also listens for the letter "c" followed by three numbers separated by commas -- which the desktop sends if the "alarm" threshold is met. It then lights the entire strip according to the "RGB," or red-green-blue, values indicated by those numbers.
There's lots more about how to program and troubleshoot your Arduino here.
Here's the Arduino code:
First, be sure your Bluetooth card is paired with your computer. You'll likely need to open the preferences for your computer to do this. Also be sure the computer's Bluetooth is turned on.
Next, be sure to note line 60 in the Processing code, and the comments above it, where you have to pick the serial port the program will use to connect with the Bluetooth card. You need to find your card in the list that appears in the Processing output window when the program runs. Count its position (they're separated by a single space) and put that position number between the brackets. Also note that the first position is 0, the second is 1 and so on.
After powering up both the LED strip and the Arduino, I run the Processing program (or sketch). Sometimes it takes running three or for tries, getting a "busy" message, before it connects. And then it does!
Let me know if you tried this, or modified it, in the comments.