Software apps and online services
Here's a project you can do in one evening: a smart taillight for your bike – or set of LED strips for any project – with custom colors and flashing patterns. It's cheap, and will set you apart on the road!
This is based on the Glowhacker workshop I used to run at Noisebridge, but with an extra piece or two to make it clever. We use rolls of waterproof 5050 RGB LEDs, which are not individually addressable and are cheaper than WS2812 / NeoPixel strips.
And here's the most basic circuit:
The LEDs can be powered directly from a 9V battery (easy for workshops), and each color rail is a ground wire. That's the first thing to really grasp here. If you connect one directly to ground, that color will turn on!
☆ Color mixing: If you connect both blue and red to ground, you'll get purple. If you use a full 12V in, and hook up all three color rails to ground, you get white (light is additive).
The NPN bit there is a transistor. Make sure your transistor can handle the power! That means 12 volts and up to 2000mA current. The ones we ordered fit the bill, but they were also strangely old-looking and the legs snapped off easily, so be careful even if you're ordering from Amazon. These ones also had a weird pinout, so I hooked it up backwards at first.
My example "brain" was a LightBlue Bean, and I soldered headers to digital pins 2, 3, and 4, as well as GND. The Bean runs off of a 3V coin cell, and rather than build a transformer, I decided to leave it that way. That's why we're using a transistor: when pin d2 goes high, that acts as the "base" (or "gate") voltage for the transistor, which then permits the 9V electricity to flow from the collector (color rail) to the emitter (ground). The emitter is connected to the battery's ground terminal, to complete the lights' power circuit, and to the Bean's GND pin, to complete the brain's logic circuit. That is, you need a common ground.
Of course, don't ever solder directly to the battery. Use a 9V connector.
I recommend having a backup in case your little e-brain fails or runs out of batteries (or gets stolen). Here's how to hook that up:
- Direct control – The Red rail is connected directly to the battery's ground terminal (the light is perma-on in this position, unless the battery is disconnected)... or
- Smart control – The Red rail is connected to the Collector pin of the transistor, which is only allowed to connect to the Emitter (ground) if the digital pin on the e-brain is HIGH.
As the workshop went on, people asked if they could hook up multiple colors and flip between them. I built some more onto the circuit to find out...
Now we have green and red hooked up. When both are on, they make yellow. How? Add another transistor:
- Solder a wire from Color #2 to the Collector pin.
- Solder the brain's pin d3 to the Base pin.
- Solder the Emitter pin to the other Ground connections you have.
Et voilà! You have pin d3 controlling the second color. See below for the ultra-crazy diagram that contains this info.
Of course, you can get SUPER CRAZY and "hard-combine" two or more colors so you can, say, toggle between yellow and blue. In that case, just glob some solder on to connect the Red and Green rails (additive color). Then solder a wire to that glob, for Yellow, and another to Blue. Connect Yellow to d2 and Blue to d3.
This diagram shows that.
It also shows you how to hook up two strips at once. I usually prefer to have the LED strips' wires conjoined near them, so that a single cable can run back up to the power and brain. I mount those under the seat, where they're less noticeable and more protected from the elements.
Of course, anywhere I'm running a cable more than a few inches, I prefer to splice in a few LEDs to make the long run. You get more lights, and they hold stably to the bike frame!
I've synced the GitHub repo to this project. It contains two sketches for the LightBlue Bean: a simple one-color flasher, and the code for that red-yellow-green traffic light thing. See below!
Of course, in the workshop, we were teaching people to use the lights with johnny-five (Node.js)... Any code for this light is simply a modified "Blink" example sketch. With NodeBots it's no different, and there is usually a basic LED blinker demo for any microcontroller. Just take note of which digital pins you're using, add more color channels to the sketch if you want, and vary the time ratios to change your blink pattern.
These LED strips come with an adhesive backing. When you're soldering, cover your joints with heat-shrink tubing. With LED ends, I like to slide the heat-shrink on and then "inject" hot glue inside it, which contracts the tubing and also waterproofs the joint.
Peel the backing off and stick the strip to your bike. Then, hot-glue the ends down, and run the nozzle of the glue gun between the edge of the LED strip and your bike frame. If there isn't room, you probably don't need to do this; it's the smaller, rounder pipe surfaces that need the extra adhesion.
Zip-tie cables judiciously to the bike frame. Watch out for pinch and bend points.
- Double-check how the rails are arranged in your LED strips; it varies between brands.
- If two LED strips are running off the same circuit, make sure they point the same way: Arrange them with power flowing from one end to the other, and all the 12V rails should be at the top or bottom.
- Some LED strips can be powered from either end; some cannot.
- Ensure that your transistors can handle the voltage AND current!!
- Check the pinout for your transistor: I've labeled Base, Collector, and Emitter in the diagrams based on the ones we had, which were weird.
- Light color is additive! Red + green = yellow; blue + green = teal or cyan; red + blue = purple; everything = white
- TEST YOUR CIRCUIT before you transfer it to the bike!
- Flickering lights? Check places where the cable bends or pinches. These can actually break inside the cable sheath, so you may need to replace a length of wire. Other than that, just make sure all your solder joints are well-connected, supported, and insulated.
- If you do this as a group workshop, costs can be as low as $11/person. I'll be making a project specifically for that, shortly.
If you'd like to run this as a workshop, it's a pretty relaxed run if you go for four hours. Have one person teach programming with regular LEDs, and another person leading the hardware construction. I'll update this with further guidelines soon.
Go forth and shine!