Star Wars: The Force Awakens is upon us. Everyone is having Star Wars fever, including me.

What I wanted to do is to find the easiest way to control a lightsaber just like they do in the movies. I bought my son a lightsaber toy at Toys ‘R’ Us, and wanted to introduce him to the world of Star Wars. (He’s 5 years old by the way.) I thought of different ways to do the trick, like hanging it on a ceiling and using gravity to pull down a lightsaber. Or maybe using strings to pull down and make it like a puppet.

Already being familiar with JavaScript, I started to look into NodeJS this year wanting to learn new technology. I was surprised to find out that there’s this emerging trend called NodeBots – using NodeJS to build robots. That sparked my interest. I’ve always wanted to learn about robotics but never had a chance. This is a good way to learn both.

I came across two frameworks – Johnny-Five and CylonJS. Johnny-Five makes it easy to work with NodeBots, while CylonJS has a bunch of platforms that can connect to NodeJS. And I was hooked. One of the platforms that CylonJS connects to is Leap Motion, and the idea came up. What if I used that to control my lightsaber? But then, how to make the thing move by itself?

Last year, I came across this platform called CloudBit, a module made by littleBits. LittleBits are kind of like Legos for electronic projects. Researching some more, I found out that they have an Arduino Bit. Arduino! Really? That’s cool. I have two kids (5 and 2 years old) and I wanted to teach them about programming. Realizing that they need to learn how to read before they can read code, I thought maybe I can show them the concepts. Electronics is a good way to show software development concepts. That’s where it all started anyway. My kids call littleBits “Tricks.” It’s all magic to them.

CylonJS offers a platform to connect to Arduino. Now I can do NodeJS and skip C++ and Arduino programming. I can just connect NodeJS to littleBits Arduino. LittleBits makes it easy to prototype stuff. They have these DC Motor Bit and Wireless Bits. It’s easy to connect stuff together, and it’s even easier to use Arduino with it. This gave me the idea to connect a DC Motor to the end of the lightsaber toy. It will make it spin – I just need to send the signal.

Here’s a tutorial on how to connect littleBits with NodeJS. It’s very easy to follow using Johnny-Five. Now, here’s a tutorial on how to connect to CylonJS to Arduino. The concepts that you learn from connecting Johnny-Five is the same as connecting CylonJS. Now it’s time to put them both together. Get data from LeapMotion. If data is valid, send a command to littleBits Arduino to spin the motors. That’s it. Nothing special. With 36 lines of code, I got blown away.


The Arduino bit is connected to a wireless transmitter bit. The wireless receiver is connected to a DC motor bit, then attached to the lightsaber via Lego Wheel. Add 9V battery power. It looks something like this:


Make sure to connect the Arduino to your computer and add USB Power.

Here’s how I connected it to the lightsaber:


Here’s the code that makes it all work (with the full source on GitHub):

Looking at the code (index.js), when I receive a “hand” from Leap Motion, I just get the hand.roll data. It will give me the roll rotation of the hand. Then I convert the value to between 0 to 256 and pass it to the LED-1 connector in CylonJS. The LED-1 is connected to Pin 5 of the Arduino.

To run this project, run

>>npm install

It will install all the necessary dependencies. Then, type

>>node index.js

LittleBits made it easy to put things together. CylonJS made it work with 36 lines of code. Amazing. Have fun! If you want to see my other projects, be sure to subscribe to my YouTube channel.

An earlier version of this post appeared on Ron’s Medium page, along with an additional guide on the littleBits website.

Ron is a dad, senior software developer at ThyssenKrupp Elevator Americas, freelance dev, registered tax preparer, and hardware lover.

Twitter LinkedIn