Making robots to do our bidding with Node.js

Node powers almost every piece of user-facing software we develop and we enjoy using it every day. But we also like to stretch our imagination and find applications for node that are outside the mainstream.

Enter Nodebots Day 2014, an annual event held around the world that brings together people who love node and are excited to use it to interact with the physical world and make robots do their bidding.

Fluencia hosted the DC edition of this year’s event at our headquarters. This post will serve as both an introduction to nodebots and the johnny-five framework, and a summary of the highlights from the day for those who couldn’t make it. Let’s go!

Getting started with johnny-five

The johnny-five framework – named after the robot protagonist of the 1986 film Short Circuit – is an open-source library and npm module that provides an interface for writing JavaScript that the microcontroller can understand. It works out of the box with Arduino, but plugins are available for Raspberry Pi, Spark Core, and many others.

npm install johnny-five

Now, create your first Hello World! Make sure you have Node.js and npm installed, and follow the instructions on the johnny-five README to get up and running. Write a file called helloworld.js:

var five = require(‘johnny-five’), // Here’s Johnny!
    board = new five.Board();

board.on(“ready”, function() { 
  var led = new five.Led(13);     // LED connected to pin 13

Connect your Arduino to any USB port and run the program with node helloworld.js. In a few seconds the program will connect to your board and the LED will start blinking. Hello World!

But that’s not all. You also have access to your very own REPL (read-eval-print loop) session, which allows you to interact with the board directly from the command line. Inject the REPL within the board “ready” handler, for example:

  led: led

Then you can run commands like led.on(),, and led.strobe() in real time.

We’re just getting started

This is all pretty cool already, but there’s much more you can do to harness the power of node for your bot.

Node is great for creating http servers quickly and easily. With the express framework, it’s even easier to write a simple server that listens for requests and do something when it receives a request. Imagine if we could remotely control our nodebot through a web browser from anywhere online.

Install the express framework with npm install express and use it to spin up a server and listen for GETs on the /turn route. For example,

var express = require('express');
var app = express();
app.get(‘/turn’, function(req, res) {


A program as simple as this allows you to control your robot by visiting http://localhost:3000/turn. This is awesome, but the app has to be running on the same machine that is connected to the Arduino to communicate with it. Not exactly remote control.

There is a solution to this, too. We can create a tunnel into localhost and expose the program to the internet. Several programs are out there to allow just such tunneling, and ngrok is exactly what I was looking for.

Install and run ./ngrok in the root folder of your project, and it will assign a randomly generated URL such as which tunnels directly into your localhost. Now anyone on the internet can visit this URL to get access to your locally running application. I wouldn’t recommend this for a production level app, but for testing and hobbying it works great!

Look at the awesome things we built

Here’s a sampling of some of the projects that came out of Nodebots Day DC 2014.

Morse code nodebot

This nodebot is a master morse code translator, taking in any string and converting it to a series of long and short buzzer beeps, by @mcwhittemore.

Button boxing game nodebot

Making use of only a few parts, this project used 7 LEDs, 2 pushbuttons, and a few wires and resistors, and quickly became the most addicting and exciting game of the day, by @daiweilu and @wind_memory.

Fork it and make your own!

Twitter nodebot

This nodebot connects to the Twitter Streaming API to blink and beep whenever anyone tweets @nodebotsday, by yours truly, @danielpazsoldan.

And many, many more!

There was an Xbox Kinect nodebot that mimics your arm movement, a nodebot that could tell you the traffic in your area, and there was the makings of a nodebot tank. But we just couldn’t capture all of the awesome projects.

We had a good turnout and everyone had a great time. The day was full of brilliant ideas, wonderful company, and the first steps toward JavaScript robot domination - a success in my book. Special thanks to Caroline Woods at Fluencia, and Matthew Whittemore and Chetan Shenoy at Social Tables for organizing a unique and awesome event.

What can you build using node and johnny-five? Show us what can you do, and see you at next year’s Nodebots Day!