Your SlideShare is downloading. ×
Controlling robots using javascript
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Controlling robots using javascript


Published on

Controlling Robots using JavaScript. Slides from my talk at jsfoo. Details at

Controlling Robots using JavaScript. Slides from my talk at jsfoo. Details at

Published in: Technology

  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. Controlling robots using JavaScript Sudar Muthu (@sudarmuthu) Research Engineer, Yahoo! Labs
  • 2. Who am I? Research Engineer by profession Creates robots as hobby Prefers Arduino Prefers JavaScript at work Why not combine both of them? .. and that’s what I am going to talk about today
  • 3. Why hardware for a software hacker? Fun!
  • 4. Let’s start with a demo Demo
  • 5. Participate in the demo  Visit
  • 6. Control the bot at stage @hardwarefun
  • 7. Arduino Visual Basic for hardware Includes both Hardware and software Photo credit Arduino team
  • 8. Interfacing Arduino with JavaScript Using serial connection (node-serialport) Using abstraction (like johnny-five or duino) Using serial Bluetooth connection (asimijs)
  • 9. Using Serial ConnectionYou need node-serialport - SerialPort = require("serialport").SerialPort, arduino = new SerialPort("/dev/tty/ACM1");// when data is received from arduinoarduino.on("data", function (data) { arduino.write(new Buffer[data]); console.log("Got: " + data);});// if there was any errorarduino.on("error", function (data) { console.log("Error: " + data);});
  • 10. Using Abstraction Build on top of node-serialport - Options include Johnny-five - and duino - Load the firmdata program into Arduino It provides the necessary abstraction Write code using a node.js library Profit 
  • 11. DemoLet there be LIGHT
  • 12. Codevar five = require("johnny-five"), board = new five.Board();board.on("ready", function() { // Create an Led on pin 13 (new five.Led(13)).strobe(1000);});
  • 13. Hardware setup
  • 14. Reading sensor data What you need?Any sensor and a LED
  • 15. Reading sensor datavar five = require("johnny-five"), board, led, photoresistor;board = new five.Board();board.on("ready", function() { // Create a new `photoresistor` hardware instance. photoresistor = new five.Sensor({pin: "A2”, freq: 250}); led = new five.Led(13); // "read" get the current reading from the photoresistor photoresistor.on("read", function( err, value ) { if (value > 50) { led.on(); } else {; } console.log( value, this.normalized ); }); // Inject the `sensor` hardware into the Repl instances context; // allows direct command line access board.repl.inject({ pot: photoresistor });});
  • 16. Using serial Bluetooth connection Bluetooth shield gives wireless capability to Arduino A Bluetooth connection appears as serial port in your computer Using node-serialport you can talk wirelessly to Arduino And that’s what I did for demo ;)
  • 17. Using serial Bluetooth connectionvar SerialPort = require("serialport").SerialPort, bt = new SerialPort("/dev/cu.FireFly-CCFA-SPP");// when data is received from bluetoothbt.on("data", function (data) { bt.write(new Buffer[data]); console.log("Got: " + data);});// error reading bluetooth serial portbt.on("error", function (data) { console.log("Error: " + data);});
  • 18. How the demo worked Node.js Server Node ClientAdmin page User page User page User page
  • 19. Links AsimiJS – The demo that I showed initially Asimi – A simple bot using Arduino Getting started with hardware programming hardware-programming Getting started with Arduino and-avr Node-serialport serialport Johnny Five
  • 20. QuestionsThank YouSudar Muthu (@sudarmuthu)