— words and things

Archive
nodejs

A little over a year ago while I was walking through Bocoup in Boston I was introduced to a cute little robot roaming the offices connected to Rick Waldron‘s macbook. He was controlling all of the movements of the robot through a node.js REPL via a library he created called johnny-five. I was immediately hooked and have been obsessed with arduino hacking in a node environment ever since. His project has come a long way in the past year and if you are not hacking arduino with node you have to try it out. It is easier than ever to get started with hardware hacking thanks to the johnny-five project.

Recently I came across a cool remote controlled multi-colored lamp in an airbnb while traveling through Switzerland. Fascinated by how fun it was to change the color of the room to any color and realizing that “normal” lights just would not cut it any more meant that I had to have one for myself. Once I made it back home I found the lamp on amazon and balked at the hefty $130 price tag that came with it. Immediately I thought “How hard can this be to make myself?!”. Two hours later I had created a simple prototype using an arduino with an RGB LED and a few open source tools. After you get set up with johnny-five follow this tutorial on getting an RGB LED hooked into your arduino. Once you have that running you are ready to get started building your own remote control for the LED.

Step One: Find a color wheel to control the color of the LED. 

The first thing I needed was a way to select a color to show. There are multiple solutions out there but one stuck out above the rest. Colorwheel by John Wier was a perfect option for a prototype because it offered me exactly what I needed. A color wheel to embed in a browser with a simple api to give me access to the RGB values corresponding to what I selected in the wheel. The only issue here is that its using raphael so it will not work on ios, but for a browser prototype this was no problem.

Step Two: Pass the RGB values to node.

Once I was able to get the RGB values from the onchange method provided by Colorwheel I could pass these brightness values down to the server through web sockets. In this particular case I chose binary.js ( this is slightly overkill but it works ) to handle the streaming web sockets from the client to the server. It was as easy as:

bc.send({}, [color.r, color.g, color.b]);

Step Three: Send the RGB brightness to the hardware.

Once I had the RGB values into the server it was time to hook up the RGB LED to the breadboard and wire it to the arduino so I could control it through johnny-five. Contributers to johnny-five have done a great job of creating wrappers around all kinds of different pieces of hardware for you. The LED wrapper demonstrates how easy it is to get up and running quickly. It is even used in the intro example for johnny-five. In our case we want to increase the brightness of each of the three LEDs inside of an RGB LED based on the red, green or blue value you selected in the color wheel. The LED wrapper has conveniently added a brightness() method for us .

Next Steps: Git clone, turn up the lumens or add a mobile controller

I have made the code available on github for anyone who wants to test this out on their own.

Now that you have a simple RGB LED working you probably are going to want more lumens shining, changing to color of the room around you. You could go for a much larger LED but a more simple option would be to order an LED strip . This will give you access to many more leds and let you stream them around the room changing your surroundings to whatever color you wish. Another option would be to get rid of the current client side code and migrate to a more mobile friendly version so you can control your lights remotely.

 

 

 

Read More