teensy

DIY LED Strip Controller

On a whim I decided to add LED lighting to my desk hutch. I already had a reel of LED strips but nothing to control them. As I wanted to build a controller that afternoon, I constructed it from parts which could be purchased locally. The controller I made has an on/off switch and two knobs: one to control the brightness and the other to control the color of the lights. Here is how I built it!

This project required the following parts: two 10K ohm potentiometers with knobs, an on/off switch, a project box, a 5 volt power supply, a power jack, some wire, and a small Arduino compatible microcontroller. RadioShack sells the Arduino Micro, but I used a Teensy 2.0 I had on hand as it is a much cheaper alternative. Of course, you also need some programmable LED strips. I used some 5 volt WS2812B LED strips (similar to Adafruit’s NeoPixel strips). It’s also useful but not required to have some connectors for the LED strips so that they can be detached from the controller. I used some JST connectors from my project stash.

The first step is to make holes in the project box. I did this with my trusty Dremel. Drill five holes: two for the potentiometers, one for the power switch, one for the power jack and a one for where the LED strip wires will enter the project box. Once the box is drilled out, place the power switch, potentiometers and power jack into the project box. Solder the power wires to the components.

IMG_9702

Next, I assembled the LED strips. If you are adding connectors to the LED strips, solder those on to the strips. If you’re connecting multiple strips, be sure that you bundle the wires together properly. I’ve found that using colored wire or marking wires with different colors of tape makes it easier to keep everything straight.

IMG_9722

Next, solder the potentiometers and LED strips. Mark the data lines for the LED strip and the potentiometers so you know which wire corresponds to a given component. It makes coding the microcontroller easier.

IMG_9761

Next, solder the microcontroller.  Keep track of the pins and their corresponding data lines. When soldering the potentiomenter to the microcontroller, make sure to connect the potentiometer data wire to pins that can support the analogRead function. These pins generally begin with the letter ‘A’.

IMG_9767

Now it’s time to program the microcontroller. The simple code can be found here. Update the code to reflect the length of your LED strip and the pins that correspond to your components. Be sure to test everything!

IMG_9771

Once you’ve verified that everything works, tape up any solder joints so that there are no shorts. Close up the box and you’re done!

IMG_9772

Pulse Jacket

led_image_2 01

This was one of my first Arduino projects. After some near misses with bicyclists while running at night, I decided to get some lights so people could see me in the dark. But why stop at boring plain lights? Wouldn’t it be cool if they could respond to my heart rate?

I looked at a number of existing heart rate sensors for Arduino, but most were optical and could not get accurate readings while I was running since they were constantly being jarred. Since I run with a Garmin GPS watch and heart rate monitor, I tried to hack into the information being sent between the heart rate monitor and the Garmin watch.

Reading a bit more about the technology, I learned that Garmin used the ANT protocol for communication between the watch and heart rate band. The good news was that SparkFun made an ANT transceiver breakout board. The bad news was that the board was discontinued and I could only get my hands on one board. I decided to move forward with this board for prototyping knowing that I would need to come up with a different solution when I made the final project.

The first step was to get the Garmin heart rate monitor and an Arduino communicating with each other. The ANT protocol documents are pretty thorough and they make great bedtime reading. Fortunately for those of us who are impatient, this thread on the SparkFun forums has sample code that already implements the protocol for the Garmin heart rate monitor.

Microcontroller with ANT breakout board

Now that I had the pulse rate information, it was time to add lights. I am a huge fan of Adafruit’s LED strips. These strips have weatherproofing so it would be possible to run outside in the rain. I trimmed the strips to the length of my arms and sealed the ends.

Microcontroller with lights

I added seven different light modes which increased in speed with the heart rate: rainbow, raindrop, range pulse, color shot, twinkle, circulatory and Cylon. Most of these modes are self-explanatory. The range pulse mode faded the strips in time with the pulse and also chose the color based on the current pulse rate (blue being low pulse, red being high). Here you can see a quick demo of the seven modes:

I then began building the final version. For this, I chose to use a Teensy 2.0 because of its low price and small size. I also had to revisit the ANT transceiver. Searching around, I found this ANTAP281M5IB  module with an on-board antenna. After some very delicate wiring and soldering, this proved to be a direct replacement for the SparkFun board.

IMG_8863

Once everything was working, it was time to put this into a portable package for running. The main concern was power. After a bit of research, I found these Energizer power packs that I could plug directly into the Teensy. The one amp power pack would power both LED strips for about an hour. After verifying that everything still worked, I placed the assembled project into a small project box.

IMG_8862

The last issue was how to attach the LED strips to my arms. I thought about embedding them into a jacket by sewing them in, but I decided against that as it would be a pain to clean. Finally, I just glued some cable clips to the back of the LED strips and used velcro straps to adjust them for the right fit.

Assembling the arm supports
Assembled Jacket

And after all that we were ready to go! My first real-world test was the Midnight Run in Central Park on New Years Eve 2013.

New Years Eve - 2013
New Years Eve - 2013

And now I can easily be seen in the dark!

Blinky Box

This was a gift for my two year old nephew. Since he is a fan of lights and buttons, I wanted to make something blinky for him to enjoy. The concept was simple: make a clear box with buttons and lights that would change color and pattern based on the buttons that were pressed.

Blinky Box

First, I had to find a clear acrylic box large enough for some LEDs, switches, buttons and a microcontroller. I found this great polycarbonate box from Hammond Manufacturing that seemed to be the right size. Next, I needed to find some buttons that could take a beating. Fortunately, Adafruit sells some translucent arcade buttons in bright colors. The lighting was a no-brainer as I am a huge fan of Adafruit’s addressable LED strips. I also found a glowy on/off switch for the power. Somewhere along the way, I thought it would be a cool idea to add a rotary knob so that he could select different blinking patterns.

The next step was to assemble the pieces and wire everything together. The polycarbonate box was harder to work with than I had hoped. The polycarbonate would discolor if I used the laser cutter, so I found myself drilling all of the holes with a rotary tool. I then added the buttons, knob and on/off switch.

Assembly

Once all of the bits were together, I had to add a microcontroller to control the button states and light transitions. I decided to go with the Teensy 3 as it was what I had on hand (and I had yet to work with one). Also, Teensy 3 allows all digital pins to be interrupted (as opposed to four on the Teensy 2), which would simplify reading the button state. The other great reason for selecting the Teensy is that it already has an Encoder library, which makes reading the knob state simple.

The code was easy. Interrupts on the arcade buttons would change a variable representing the color. The interrupt for the black button would kick off a rainbow display routine. In the main loop, I polled for changes in the rotary encoder state and transitioned the lights accordingly. When I was finished, there were five main light colors (white, red, yellow, green and blue), one rainbow routine and six possible blink patterns (always on, fade on/off, blink on/off, chasing light, random twinkling lights and alternating lights).

IMG_6082

I saved the hardest part for last: power. I wanted something that my nephew couldn’t disturb, so anything outside of the box was out of the question. Regular batteries would require opening the box to change, so I thought something rechargeable would work better. I decided to go with a Lithium Ion battery. Unfortunately, these are generally around 3.7 volts and the LED strips require 5 volts. This meant that I needed to find a way to recharge the battery from the outside and find a way to step up the voltage. Fortunately, SparkFun sells a power cell board that does both. Yay!

Power Supply

I added a power jack to the box and used an old 5 volt AC adapter to supply the charging power. I then connected the power cell board and the battery using this handy tutorial. Fortunately, the charging of the battery seemed to work! Unfortunately, the power cell board only provides 600 milliamps at 5 volts, which is not enough power to run a full meter of the LED strip. Sadly, I had to cut the strip in half. It was still impressive even with just one loop of lights! To make the battery last even longer, I also implemented some of the suggestions for conserving power with the Teensy.

The best part about this toy is that it is fully programmable. As he gets older, I can program new features or games into it. Perhaps one day, I can even teach him to program it himself! 🙂

Here is a short video of the assembled box

 

Microcontrollers!

IMG_6193

Looking through some of my electronics stuff, I realized that I ten different kinds of microcontrollers! That’s not bad at all, considering that I only discovered my love of them last summer. There are five flavors of Arduino: Uno, Uno Ethernet, MEGA, MEGA ADK and Due. There are three flavors of Teensy: Teensy 2.0, Teensy++ 2.0 and Teensy 3.0. There are also two wearables: Lilypad Arduino and Adafruit Flora. So many microcontrollers, so little time!

Motion-Sensitive Paper Lantern

Back in February, I made a motion-sensitive lantern for the Lunar New Year. The idea was simple: have a lantern that appeared to be mostly plain but would reveal a design when a person moved closer to it.

Lantern from far away

The easiest form to use was a round paper lantern. I started with a 14″ white paper lantern and some markers. I then attempted to draw some snakes on it, as 2013 is the year of the snake. As I am not an artist, let’s pretend that these squiggles look like snakes.

Lantern up close

The next part was to add some lighting. The lighting needed to change color. I decided to go with LED strips from Adafruit, as I could wrap them in the center of the lantern and have fairly uniform lighting. I had some left over pieces from a previous project and this seemed like the perfect occasion to use them.

Next, the lighting needed to respond to motion. There were a couple of sensors that would have allowed me to detect motion, but I decided on a passive infrared (PIR) sensor. Interestingly, these sensors work by detecting rapid changes in infrared radiation (including those given off by body heat).

PIR Sensor

The code for this was very straightforward. The PIR sensor sends a high signal on its output pin whenever motion is detected. Therefore, it’s as simple as polling the output pin with digitalRead() and transitioning the lights based on changes in the output pin state.

Finally, I had to find a lightweight power source. I found an Energizer power pack, which was the perfect power supply for Teensy. It even came with a mini USB adapter, which meant that I could plug it directly into the Teensy without having to solder anything. Here is the final internal assembly of the lamp!

The final assembly

And here is the lamp, fully assembled and running!

Dance Dance Revolution Keyboard

Over the weekend, I turned a Dance Dance Revolution dance pad into a keyboard input device. The pad will be used as part of a larger project at the NYC Resistor 2013 Interactive Show. Here is how I did it.

The pad itself is one of those metal arcade style Dance Dance Revolution pads. The only output was a 15 pin D-Sub connector, much like a VGA cable.

Dance Pad
The dance pad connector

Fortunately for me, a fellow Resistor already went through the arduous task of figuring out the pinout for this particular pad. A little further research based on the pinout revealed that this particular model was a TX-1000. The full pinout can be found here.

The next task was to wire the connector to a microcontroller and try to read input from the board. I decided to go with a Teensy as it already has a library that supports keyboard output. In order to have the Teensy be recognized as a HID by a computer, you have to change the USB type. This can be done by changing Tools -> USB Type to “Keyboard + Mouse + Joystick”.

Now I needed to write some code to read the input from the dance pad and convert it to keyboard output. First, I had to define the input pins in the setup function of the Teensy code. This was done with pinMode using pullup resistors.

pinMode(leftPin, INPUT_PULLUP);   // Left arrow

The next step was to read the input from the control pad and send the corresponding keyboard character when a pad was pressed. Fortunately, Teensy offers a Bounce library which makes debouncing switches easy. First you declare a Bounce object on your input pin.

Bounce leftButton = Bounce(leftPin, 400);

Next, poll the pin in the loop() method for state changes. Once a state change is detected, send the corresponding keyboard key.

if (leftButton.update()) {
    if (leftButton.fallingEdge()) {
         Keyboard.set_key1(KEY_LEFT);
    }
}

Once everything was wired up and the Teensy code was running, everything seemed to work… except the right arrow. Unfortunately, this meant that it was time to take the pad apart!

Underneath a panel

The wires

After a bit of investigating and a few false starts, I found that the wires were easily accessible under the up arrow. Thankfully, the wires for each button were a different color so it was easy to determine which wires to test. Testing with a multimeter showed that the right signal wire in the cable was not working. After running a new signal wire for the right pad (and soldering everything else I cut), everything worked as expected! I then used a solderable D-Sub connector and enclosure from RadioShack to make a connector for the pad.

The completed connector

I could then hook the dance pad connector to my homemade connector and then a mini USB to USB cable from the Teensy to my computer. There is nothing more satisfying than navigating your computer by dancing!