SlideShare a Scribd company logo
Controlling robots
 using JavaScript




 Sudar Muthu (@sudarmuthu)
 Research Engineer, Yahoo! Labs
 http://hardwarefun.com
 http://github.com/sudar
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
Why hardware for a software hacker?




           Fun!
Let’s start with a demo




       Demo
  http://hardwarefun.com/projects/asimijs
Participate in the demo 




          Visit
    http://hardwarefun.com:3000
Control the bot at stage
               http://hardwarefun.com/projects/asimijs




#asimijs @hardwarefun
Arduino
 Visual Basic for hardware
 Includes both Hardware and software




                         Photo credit Arduino team
Interfacing Arduino with JavaScript

 Using serial connection (node-serialport)
 Using abstraction (like johnny-five or duino)
 Using serial Bluetooth connection (asimijs)
Using Serial Connection
You need node-serialport - https://github.com/voodootikigod/node-serialport

var SerialPort = require("serialport").SerialPort,
  arduino = new SerialPort("/dev/tty/ACM1");

// when data is received from arduino
arduino.on("data", function (data) {
    arduino.write(new Buffer[data]);
    console.log("Got: " + data);
});

// if there was any error
arduino.on("error", function (data) {
    console.log("Error: " + data);
});
Using Abstraction

 Build on top of node-serialport -
  https://github.com/voodootikigod/node-serialport
 Options include Johnny-five -
  https://github.com/rwldrn/johnny-five and duino -
  https://github.com/ecto/duino
 Load the firmdata program into Arduino
 It provides the necessary abstraction
 Write code using a node.js library
 Profit 
Demo




Let there be LIGHT
Code
var five = require("johnny-five"),
  board = new five.Board();

board.on("ready", function() {

 // Create an Led on pin 13
 (new five.Led(13)).strobe(1000);

});
Hardware setup
Reading sensor data

   What you need?



Any sensor and a LED
Reading sensor data
var 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 {
          led.off();
      }
    console.log( value, this.normalized );
  });
  // Inject the `sensor` hardware into the Repl instance's context;
  // allows direct command line access
  board.repl.inject({
    pot: photoresistor
  });
});
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 ;)
Using serial Bluetooth connection
var SerialPort = require("serialport").SerialPort,
  bt = new SerialPort("/dev/cu.FireFly-CCFA-SPP");

// when data is received from bluetooth
bt.on("data", function (data) {
    bt.write(new Buffer[data]);
    console.log("Got: " + data);
});

// error reading bluetooth serial port
bt.on("error", function (data) {
    console.log("Error: " + data);
});
How the demo worked

                Node.js Server




                                 Node Client



Admin page


                  User page
                   User page
                     User page
Links
 AsimiJS – The demo that I showed initially
  http://hardwarefun.com/projects/asimijs
 Asimi – A simple bot using Arduino
  http://hardwarefun.com/project/asimi
 Getting started with hardware programming
  http://hardwarefun.com/tutorials/getting-started-with-
  hardware-programming
 Getting started with Arduino
  http://hardwarefun.com/tutorials/getting-started-with-arduino-
  and-avr
 Node-serialport https://github.com/voodootikigod/node-
  serialport
 Johnny Five https://github.com/rwldrn/johnny-five
Questions

Thank You

Sudar Muthu (@sudarmuthu)
  http://hardwarefun.com
  http://gitbub.com/sudar

More Related Content

KEY
Android and Arduio mixed with Breakout js
PPTX
Home sensor prototype on Arduino & Raspberry Pi with Node.JS
PPTX
Js robotics
PDF
[H3 2012] 우리가 모르는 Node.js로 할 수 있는 몇가지
PDF
Build Lifecycle Craftsmanship for the Transylvania JUG
PDF
Metasepi team meeting #6: "Snatch-driven development"
PDF
Detecting headless browsers
Android and Arduio mixed with Breakout js
Home sensor prototype on Arduino & Raspberry Pi with Node.JS
Js robotics
[H3 2012] 우리가 모르는 Node.js로 할 수 있는 몇가지
Build Lifecycle Craftsmanship for the Transylvania JUG
Metasepi team meeting #6: "Snatch-driven development"
Detecting headless browsers

What's hot (12)

PDF
JavaScript in the Real World
TXT
PDF
My Robot Poops - In JavaScript (with web sockets)
PDF
Why use JavaScript in Hardware? GoTo Conf - Berlin
PDF
Couverture de code
PDF
Mojolicious lite
PDF
Infinum Android Talks #20 - Making your Android apps fast like Blue Runner an...
PDF
Continuous Integration for iOS (iOS User Group Berlin)
PDF
Continuous Integration for iOS
PDF
Bundler is the Best
PDF
CasperJS and PhantomJS for Automated Testing
PDF
Let's begin io t with $10
JavaScript in the Real World
My Robot Poops - In JavaScript (with web sockets)
Why use JavaScript in Hardware? GoTo Conf - Berlin
Couverture de code
Mojolicious lite
Infinum Android Talks #20 - Making your Android apps fast like Blue Runner an...
Continuous Integration for iOS (iOS User Group Berlin)
Continuous Integration for iOS
Bundler is the Best
CasperJS and PhantomJS for Automated Testing
Let's begin io t with $10
Ad

Similar to Controlling robots using javascript (20)

PDF
Building Droids with JavaScript
PDF
Hardware for JavaScript Developers
PDF
Droids, java script and web connected hardware
PDF
How To Electrocute Yourself using the Internet
PPTX
Bare metal Javascript & GPIO programming in Linux
PPTX
Hacking into IoT using JavaScript
PDF
Johnny-Five
PPTX
Nodebots
PDF
Introducing the Arduino
PPT
Arduino final ppt
PDF
arduino
PDF
A Practical Guide to Connecting Hardware to the Web
PPTX
ARDUINO.pptx
PDF
Arduino Teaching Program
PDF
Edge Of The Web
PDF
PPTX
What is Arduino
PPTX
Arduino
PDF
Little bits & node.js IOT for beginner
PDF
Ardx experimenters-guide-web
Building Droids with JavaScript
Hardware for JavaScript Developers
Droids, java script and web connected hardware
How To Electrocute Yourself using the Internet
Bare metal Javascript & GPIO programming in Linux
Hacking into IoT using JavaScript
Johnny-Five
Nodebots
Introducing the Arduino
Arduino final ppt
arduino
A Practical Guide to Connecting Hardware to the Web
ARDUINO.pptx
Arduino Teaching Program
Edge Of The Web
What is Arduino
Arduino
Little bits & node.js IOT for beginner
Ardx experimenters-guide-web
Ad

More from Sudar Muthu (20)

PPTX
A quick preview of WP CLI - Chennai WordPress Meetup
PDF
WordPress Developer tools
PDF
WordPress Developer Tools to increase productivity
PDF
Unit testing for WordPress
PDF
Unit testing in php
PPTX
Using arduino and raspberry pi for internet of things
PPTX
How arduino helped me in life
PPTX
Having fun with hardware
PPTX
Getting started with arduino workshop
PPTX
Python in raspberry pi
PPTX
Hack 101 at IIT Kanpur
PPTX
PureCSS open hack 2013
PPTX
Pig workshop
PPTX
Arduino Robotics workshop day2
PPTX
Arduino Robotics workshop Day1
PPTX
Hands on Hadoop and pig
PPTX
Lets make robots
PPTX
Capabilities of Arduino (including Due)
PPTX
Picture perfect hacks with flickr API
PPTX
Hacking 101
A quick preview of WP CLI - Chennai WordPress Meetup
WordPress Developer tools
WordPress Developer Tools to increase productivity
Unit testing for WordPress
Unit testing in php
Using arduino and raspberry pi for internet of things
How arduino helped me in life
Having fun with hardware
Getting started with arduino workshop
Python in raspberry pi
Hack 101 at IIT Kanpur
PureCSS open hack 2013
Pig workshop
Arduino Robotics workshop day2
Arduino Robotics workshop Day1
Hands on Hadoop and pig
Lets make robots
Capabilities of Arduino (including Due)
Picture perfect hacks with flickr API
Hacking 101

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPT
Teaching material agriculture food technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Modernizing your data center with Dell and AMD
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PDF
Review of recent advances in non-invasive hemoglobin estimation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
20250228 LYD VKU AI Blended-Learning.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Per capita expenditure prediction using model stacking based on satellite ima...
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Teaching material agriculture food technology
Advanced methodologies resolving dimensionality complications for autism neur...
Chapter 2 Digital Image Fundamentals.pdf
Empathic Computing: Creating Shared Understanding
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
MYSQL Presentation for SQL database connectivity
Modernizing your data center with Dell and AMD
GamePlan Trading System Review: Professional Trader's Honest Take
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Review of recent advances in non-invasive hemoglobin estimation

Controlling robots using javascript

  • 1. Controlling robots using JavaScript Sudar Muthu (@sudarmuthu) Research Engineer, Yahoo! Labs http://hardwarefun.com http://github.com/sudar
  • 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 http://hardwarefun.com/projects/asimijs
  • 5. Participate in the demo  Visit http://hardwarefun.com:3000
  • 6. Control the bot at stage http://hardwarefun.com/projects/asimijs #asimijs @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 Connection You need node-serialport - https://github.com/voodootikigod/node-serialport var SerialPort = require("serialport").SerialPort, arduino = new SerialPort("/dev/tty/ACM1"); // when data is received from arduino arduino.on("data", function (data) { arduino.write(new Buffer[data]); console.log("Got: " + data); }); // if there was any error arduino.on("error", function (data) { console.log("Error: " + data); });
  • 10. Using Abstraction  Build on top of node-serialport - https://github.com/voodootikigod/node-serialport  Options include Johnny-five - https://github.com/rwldrn/johnny-five and duino - https://github.com/ecto/duino  Load the firmdata program into Arduino  It provides the necessary abstraction  Write code using a node.js library  Profit 
  • 12. Code var five = require("johnny-five"), board = new five.Board(); board.on("ready", function() { // Create an Led on pin 13 (new five.Led(13)).strobe(1000); });
  • 14. Reading sensor data What you need? Any sensor and a LED
  • 15. Reading sensor data var 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 { led.off(); } console.log( value, this.normalized ); }); // Inject the `sensor` hardware into the Repl instance's 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 connection var SerialPort = require("serialport").SerialPort, bt = new SerialPort("/dev/cu.FireFly-CCFA-SPP"); // when data is received from bluetooth bt.on("data", function (data) { bt.write(new Buffer[data]); console.log("Got: " + data); }); // error reading bluetooth serial port bt.on("error", function (data) { console.log("Error: " + data); });
  • 18. How the demo worked Node.js Server Node Client Admin page User page User page User page
  • 19. Links  AsimiJS – The demo that I showed initially http://hardwarefun.com/projects/asimijs  Asimi – A simple bot using Arduino http://hardwarefun.com/project/asimi  Getting started with hardware programming http://hardwarefun.com/tutorials/getting-started-with- hardware-programming  Getting started with Arduino http://hardwarefun.com/tutorials/getting-started-with-arduino- and-avr  Node-serialport https://github.com/voodootikigod/node- serialport  Johnny Five https://github.com/rwldrn/johnny-five
  • 20. Questions Thank You Sudar Muthu (@sudarmuthu) http://hardwarefun.com http://gitbub.com/sudar