Control your LightSaber with LeapMotion and LittleBits.
The new Star Wars Movie “The Force Awakens” is upon us. Get ready for it. Everyone is having this Star Wars fever include 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. I 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 use gravity to pull down a LightSaber. Or maybe use strings to pull down and make it like a puppet.
I did more research about Nodebots and came across a framework called Johnny-Five.io (http://johnny-five.io/) and CylonJS (http://cylonjs.com/). Johnny-Five makes it easy to work with #NodeBots. CylonJS has a bunch of Platforms that can connect to NodeJS. And I was hooked.
Here’s the Github Repository for Johnny-Five
Here’s how to get started with CylonJS.
I bought a LeapMotion at Kickstarter about 2 years ago wanting to develop and learn more about gesture recognition. It’s like Kinect for desktop. Life Happens, Never had a chance to work on that either. I looked at the api, got confused, found another new shiny thing to learn…
CylonJS has connectors to LeapMotion and the idea came up. Here’s the tutorial how to connect CylonJS with Leapmotion. http://cylonjs.com/documentation/drivers/leapmotion/
What If I use that to control my LightSaber. But how to make the thing move by itself?
Last year, the Internet of Things buzzword started to popup. Reading articles about it, I came across this platform called CloudBit. Cloudbit is a module made by Littlebits. Littlebits are kinda like Legos for electronic projects. Researching some more, I found out that they have Arduino Bit. Arduino! Really? That’s cool.
Eventually, I ended up getting hooked into Littlebits. I have two kids, (5 and 2 year old) and I wanted to teach them about programming. Realizing that they need to learn how to read first 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 as ‘Tricks. It’s all magic to them.
I also created a presentation that might help
CylonJS has 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. 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.
I found few tutorials on how to use Littlebits Arduino with NodeJS. I tried using it for CylonJS and it worked.
Here’s a tutorial how to connect Littlebits with NodeJS. Very easy to follow. using the Johnny-Five.io
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. Looks something like this.
Here’s how I connected it to the LightSaber. To leàrn more visit Littlebits website
Here’s the link to github repo
leapmotion-jedi — Control your LightSaber with LeapMotion and Littlebitsgithub.com
Looking at the code (index.js), when I receive a “hand” from leap motion. Just get the hand.roll data. It will give you the roll rotation of the hand. Then I convert the value between 0 to 256 pass it to the Led-1 connector in CylonJS. Led-1 is connected to Pin 5 of Arduino.
To run this project. run
It will install all the necessary dependencies.
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, subscribe to my youtube channel. Here are some of the projects I’ve been working on lately.