Raspberry Pi + Arduino + Node = Home Automation


After figuring out how to set up the Raspberry Pi and how to communicate between a Raspberry Pi and an Arduino, I wanted to try a simple home-automation project that incorporated several really awesome and useful technologies:

Raspberry Pi
– Node
– Socket.IO
– Canvas with KineticJS
– RGB LED Pixels

The following diagram shows how all this tech is arranged.  

Screen Shot 2013-02-05 at 10.29.26 PM

This is by no means the only way to do home-automation, but its a fun project if you don’t mind programming, and there are a lot of advantages to using these particular tools.  Having a browser based interface allows you to work the controls from virtually any computer or mobile device.  Canvas gives you the ability to create a rich interactive experience for the end-user.  KineticJS makes it incredibly easy to make canvas animations.  The Raspberry Pi gives you the benefit of a fully functional web server and allows the project to be portable.  Node makes developing that web server as well as serial communication with the Arduino quick and easy.  Websockets and Socket.IO allow the server to easily push updates to all clients in real time, so if I tweak a slider, everyone viewing the control panel sees me move it.  Finally the Arduino gives us an easy way to control the physical world and access to countless libraries including one that helps to work with the RGB LED Pixels .

Here is a video of the whole thing in action:

In my previous tests, Firmata was a great choice for integrating the Pi and Arduino since it simplified the code base – instead of writing a C program for the Arduino, the Arduino was controlled directly from my Node program.  In this case however, I opted to leverage this Adafruit Arduino library to work with the RGB LED Pixels.  So it made more sense to write a separate Arduino sketch which incorporates this lib and communicates with Node over serial.  Couple of things to note:

1. Arduino libraries go in this location:

2. Node serial communication can be done using this package
    sudo npm install -g serialport

3. Optional: Since the Arduino IDE is quite slow on the Pi, Ino is a great option for building and uploading arduino code from the command line.

Here is our holiday tree outfitted with RGB LED Pixels from Adafruit.com


From another angle you can see the attached Raspberry Pi and Arduino (in the dark)


A clearer daytime pic of the setup. Breadboard with BBB Arduino Clone –> USB BUB –> male-to-male mini-A USB adapter –> Raspberry Pi


The Raspberry Pi is running a Node web server which communicates with clients using Socket.IO. Here it is in its entirety. For the canvas and arduino code, see the Github repo below.


When on the same network as the Pi, navigating a browser to http://raspberrypi:8080 brings up this canvas based control panel. I used KineticJS to make this happen faster


Next, I’d like to take this project further by having a line of communication coming back from the Arduino to the canvas front-end.  When multiple clients are looking at the control panel and one user moves the sliders, everyone should see them move in close to real time.

In addition to my desktop browser, I tried this out from my Android device (LG Nexus 4 running Chromium).  I was disappointed to find that the animation is clunky and jumpy, and touch control is inaccurate.  I’ve heard that unless they’re very simple, canvas animations require extensive optimization to work in mobile browsers.  I have friends that are struggling with similar issues, so hopefully there will be some advancement in this area on mobile browsers to make canvas truly universal.

The source code for this project is available here on Github.


  1. Pingback: Raspberry Pi + Arduino + Tornado
  2. Pingback: Raspberry Pi obsessed | Jamie Gilmartin

Post a comment

You may use the following HTML:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>