SlideShare a Scribd company logo
1 of 20
Download to read offline
Nodebot:
Arduino + Javascript
Desiree Santos
@desisant
•
Consultora ThoughtWorks Brasil
•
Open hardware desde 2009
•
Hobby #1 objetos interativos
•
Coordena (arduinrio)
•
Modera arduinoBrasil
•
Hackerspace
@desisant
Agenda
•
IDE Sublime + Stino
•
IDE Arduino
•
Instalar nodejs
•
Download john-Five
Desenvolvimento:
100% prática:
•
Javascript
•
Eletrônica
•
Analógico
•
Digital
Referência: node-ardx.org
@desisant
Expectativa
Explorar meios diferentes para controlar o arduino
Utilizando ferramentas que aumentam a nossa produtividade
Extrair o melhor que o arduino proporciona
Alavancar aprendizado com JS + arduino para desenvolver projetos
Javascript é meio e não fm, não é ofcina de javascript
Sim
Não
Não se preocupe, haverá suporte para todos fcarem na mesma página
@desisant
Arduino is an open-source electronics
platform based on easy-to-use
hardware and software.
It's intended for anyone
making interactive projects.
By Massimo Banzi
@desisant
Arte de controlar arduino utilizando a linguaguem Javascript
@desisant
Montar o ambiente:
1) Baixar IDE arduino
→ www.arduino.cc/ → menu Download
2) Sublime Text → http://www.sublimetext.com/2
3) Instalar plugin STINO no sublime text
→ https://github.com/Robot-Will/Stino
4) Instalar nodejs https://nodejs.org/
@desisant
Blink – Piscar Led
2 pin (digital)
5mm LED
330 ohm resistor (orange-orange-brown)
jumper wires
@desisant
var five = require("johnny-five");
var myBoard, myLed;
myBoard = new five.Board();
myBoard.on("ready", function() {
myLed = new five.Led(13);
myLed.strobe( 1000 );
// make myLED available as "led" in REPL
this.repl.inject({
led: myLed
});
// try "on", "off", "toggle", "strobe", "stop" (stops strobing)
});
blink.js
@desisant
Semáforo
3 pin (digital)
5mm LED
330 ohm resistor (orange-orange-brown)
jumper wires
@desisant
var five = require("johnny-five");
var board, leds=[], ledPins = [2,3,4,5,6,7,8,9];
board = new five.Board();
board.on("ready", function() {
// initialize LEDs using a for loop
for (var i = 0; i < ledPins.length; i++){
var myLed = new five.Led(ledPins[i]);
leds.push(myLed);
}
function allOn(){
for (var i = 0; i < leds.length; i++) {
leds[i].on();
}
}
function allOff(){
for (var i = 0; i < leds.length; i++) {
leds[i].off();
}
}
function oneAfterAnother() {
var delay = 1;
board.counter = 0;
for (var i = 0; i < leds.length; i++) {
var led = leds[i];
board.wait(delay,function(){
console.log(this.counter + " on");
leds[this.counter].on();
});
board.wait(delay + 200,function(){
console.log(this.counter + " off");
leds[this.counter].off();
this.counter = (this.counter + 1) % leds.length;
});
delay += 500;
}
}
// allOn();
// board.wait(1000,allOff);
oneAfterAnother();
semaforo.js
@desisant
•
2 pin header x 4
•
Piezo element
•
jumper wires
Música
@desisant
var five = require("johnny-five");
five.Board().on("ready", function() {
var piezo = new five.Piezo(9);
var val = 0;
this.loop(200, function() {
if (val ^= 1) {
// Play note a4 for 1/5 second
piezo.frequency(five.Piezo.Notes["a4"], 200);
}
});
});
Music.js
@desisant
• 2 pin header x 4
• 5mm LED
• Pushbutton x 2
• 330 ohm resistor (orange-orange-brown)
• 10k Ohm Resistor (brown-black-orange) x 2
• jumper wires
Push Button
@desisant
var five = require("johnny-five"),
onButton, offButton, led;
five.Board().on("ready", function() {
onButton = new five.Button(2);
led = new five.Led(13);
onButton.on("down", function(value){
led.on();
});
});
Button.js
@desisant
• 2 pin header x 4
• Potentiometer 10k ohm
• 5mm LED
• 330 ohm resistor (orange-orange-brown)
• jumper wires
Potenciômetro
@desisant
var five = require("johnny-five"),
board, myPotentiometer;
board = new five.Board();
board.on("ready", function() {
myPotentiometer = new five.Sensor({
pin: "A0",
freq: 250
});
myLed = new five.Led(9);
myPotentiometer.on("read", function() {
var rawValue = this.raw;
myLed.brightness(Math.floor(rawValue / 4));
});
});
Potenciometro.js
@desisant
• 2 pin header x 4
• TMP36 Temperature sensor
• jumper wires
Temperatura
@desisant
var five = require("johnny-five");
five.Board().on("ready", function(){
var tempSensor = new five.Sensor("A0");
tempSensor.on("read", function(err, value){
var cel = (100 * (value / 1000) - 50).toFixed(2);
console.log("temp is " + cel);
});
});
Temperatura.js
@desisant
@desisant
desisantos.wordpress.com
Dúvidas, suporte para projetos :

More Related Content

Similar to Control Arduino with JavaScript

Controlling robots using javascript
Controlling robots using javascriptControlling robots using javascript
Controlling robots using javascriptSudar Muthu
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyMike Hagedorn
 
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...melbats
 
JavaScript Robotics #NodeWeek
JavaScript Robotics #NodeWeekJavaScript Robotics #NodeWeek
JavaScript Robotics #NodeWeekSuz Hinton
 
Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro
Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo CastroHome Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro
Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo CastroAlberto Sagredo Castro
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with androidfirenze-gtug
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunJingfeng Liu
 
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoEchelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoAndri Yadi
 
Android and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsAndroid and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsmusart Park
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the ServerDavid Ruiz
 
Making things sense-Day 2 (May 2011)
Making things sense-Day 2 (May 2011)Making things sense-Day 2 (May 2011)
Making things sense-Day 2 (May 2011)markumoto
 
Distance Machine Locker
Distance Machine LockerDistance Machine Locker
Distance Machine Lockeryeokm1
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysisIbrahim Baliç
 
Programming the Real World: Javascript for Makers
Programming the Real World: Javascript for MakersProgramming the Real World: Javascript for Makers
Programming the Real World: Javascript for Makerspchristensen
 
How NOT to write in Node.js
How NOT to write in Node.jsHow NOT to write in Node.js
How NOT to write in Node.jsPiotr Pelczar
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch
 
Smartphone++
Smartphone++Smartphone++
Smartphone++mharkus
 
Arduino by bishal bhattarai IOE, Pashchimanchal Campus Pokhara, Nepal
Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, NepalArduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal
Arduino by bishal bhattarai IOE, Pashchimanchal Campus Pokhara, Nepalbishal bhattarai
 

Similar to Control Arduino with JavaScript (20)

Node azure
Node azureNode azure
Node azure
 
MouthMouse
MouthMouseMouthMouse
MouthMouse
 
Controlling robots using javascript
Controlling robots using javascriptControlling robots using javascript
Controlling robots using javascript
 
Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
 
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
 
JavaScript Robotics #NodeWeek
JavaScript Robotics #NodeWeekJavaScript Robotics #NodeWeek
JavaScript Robotics #NodeWeek
 
Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro
Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo CastroHome Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro
Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro
 
Programming objects with android
Programming objects with androidProgramming objects with android
Programming objects with android
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
 
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & ArduinoEchelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
Echelon Indonesia 2016 - Innovation Through Opportunities in IoT & Arduino
 
Android and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout jsAndroid and Arduio mixed with Breakout js
Android and Arduio mixed with Breakout js
 
node.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Servernode.js - Eventful JavaScript on the Server
node.js - Eventful JavaScript on the Server
 
Making things sense-Day 2 (May 2011)
Making things sense-Day 2 (May 2011)Making things sense-Day 2 (May 2011)
Making things sense-Day 2 (May 2011)
 
Distance Machine Locker
Distance Machine LockerDistance Machine Locker
Distance Machine Locker
 
Automated malware analysis
Automated malware analysisAutomated malware analysis
Automated malware analysis
 
Programming the Real World: Javascript for Makers
Programming the Real World: Javascript for MakersProgramming the Real World: Javascript for Makers
Programming the Real World: Javascript for Makers
 
How NOT to write in Node.js
How NOT to write in Node.jsHow NOT to write in Node.js
How NOT to write in Node.js
 
soft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.jssoft-shake.ch - Hands on Node.js
soft-shake.ch - Hands on Node.js
 
Smartphone++
Smartphone++Smartphone++
Smartphone++
 
Arduino by bishal bhattarai IOE, Pashchimanchal Campus Pokhara, Nepal
Arduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, NepalArduino by bishal bhattarai  IOE, Pashchimanchal Campus Pokhara, Nepal
Arduino by bishal bhattarai IOE, Pashchimanchal Campus Pokhara, Nepal
 

More from Desiree Santos

Efetividade na névoa conectando bits e bytes
Efetividade na névoa  conectando bits e bytesEfetividade na névoa  conectando bits e bytes
Efetividade na névoa conectando bits e bytesDesiree Santos
 
Internet das coisas na prática
Internet das coisas na práticaInternet das coisas na prática
Internet das coisas na práticaDesiree Santos
 
Programando arduino com javascript
Programando arduino com javascriptProgramando arduino com javascript
Programando arduino com javascriptDesiree Santos
 
Internet das coisas - ADP TecnoTalks
Internet das coisas - ADP TecnoTalksInternet das coisas - ADP TecnoTalks
Internet das coisas - ADP TecnoTalksDesiree Santos
 
SenacTalks - Mulheres na tecnologia
SenacTalks - Mulheres na tecnologia SenacTalks - Mulheres na tecnologia
SenacTalks - Mulheres na tecnologia Desiree Santos
 
Internet das coisas - Oportunidades & Inovação
Internet das coisas - Oportunidades & InovaçãoInternet das coisas - Oportunidades & Inovação
Internet das coisas - Oportunidades & InovaçãoDesiree Santos
 
Grace Hopper - Internet of Things from A to Z
Grace Hopper - Internet of Things from A to ZGrace Hopper - Internet of Things from A to Z
Grace Hopper - Internet of Things from A to ZDesiree Santos
 
Internet das Coisas - Cafeteira hacker
Internet das Coisas - Cafeteira hackerInternet das Coisas - Cafeteira hacker
Internet das Coisas - Cafeteira hackerDesiree Santos
 
Seminário de robótica - PUCRS
Seminário de robótica - PUCRSSeminário de robótica - PUCRS
Seminário de robótica - PUCRSDesiree Santos
 
Inove com Internet das Coisas
Inove com Internet das CoisasInove com Internet das Coisas
Inove com Internet das CoisasDesiree Santos
 
Internet das Coisas (Internet of Things - IoT)
Internet das Coisas (Internet of Things - IoT)Internet das Coisas (Internet of Things - IoT)
Internet das Coisas (Internet of Things - IoT)Desiree Santos
 
LevelUp program - Framework to retain talent
LevelUp program - Framework to retain talentLevelUp program - Framework to retain talent
LevelUp program - Framework to retain talentDesiree Santos
 
Domótica: Controle dispositivos via comando de voz com arduino
Domótica: Controle dispositivos via comando de voz com arduinoDomótica: Controle dispositivos via comando de voz com arduino
Domótica: Controle dispositivos via comando de voz com arduinoDesiree Santos
 

More from Desiree Santos (20)

Efetividade na névoa conectando bits e bytes
Efetividade na névoa  conectando bits e bytesEfetividade na névoa  conectando bits e bytes
Efetividade na névoa conectando bits e bytes
 
Arduino
ArduinoArduino
Arduino
 
Internet das coisas na prática
Internet das coisas na práticaInternet das coisas na prática
Internet das coisas na prática
 
Programando arduino com javascript
Programando arduino com javascriptProgramando arduino com javascript
Programando arduino com javascript
 
Internet das coisas - ADP TecnoTalks
Internet das coisas - ADP TecnoTalksInternet das coisas - ADP TecnoTalks
Internet das coisas - ADP TecnoTalks
 
SenacTalks - Mulheres na tecnologia
SenacTalks - Mulheres na tecnologia SenacTalks - Mulheres na tecnologia
SenacTalks - Mulheres na tecnologia
 
Internet das coisas - Oportunidades & Inovação
Internet das coisas - Oportunidades & InovaçãoInternet das coisas - Oportunidades & Inovação
Internet das coisas - Oportunidades & Inovação
 
Grace Hopper - Internet of Things from A to Z
Grace Hopper - Internet of Things from A to ZGrace Hopper - Internet of Things from A to Z
Grace Hopper - Internet of Things from A to Z
 
Internet das Coisas - Cafeteira hacker
Internet das Coisas - Cafeteira hackerInternet das Coisas - Cafeteira hacker
Internet das Coisas - Cafeteira hacker
 
Seminário de robótica - PUCRS
Seminário de robótica - PUCRSSeminário de robótica - PUCRS
Seminário de robótica - PUCRS
 
Nodebot day lamp
Nodebot day lampNodebot day lamp
Nodebot day lamp
 
Robots
RobotsRobots
Robots
 
Inove com Internet das Coisas
Inove com Internet das CoisasInove com Internet das Coisas
Inove com Internet das Coisas
 
Quilombolas
QuilombolasQuilombolas
Quilombolas
 
Internet das Coisas (Internet of Things - IoT)
Internet das Coisas (Internet of Things - IoT)Internet das Coisas (Internet of Things - IoT)
Internet das Coisas (Internet of Things - IoT)
 
LevelUp program - Framework to retain talent
LevelUp program - Framework to retain talentLevelUp program - Framework to retain talent
LevelUp program - Framework to retain talent
 
Domótica: Controle dispositivos via comando de voz com arduino
Domótica: Controle dispositivos via comando de voz com arduinoDomótica: Controle dispositivos via comando de voz com arduino
Domótica: Controle dispositivos via comando de voz com arduino
 
Arduino
ArduinoArduino
Arduino
 
Arduino
ArduinoArduino
Arduino
 
Robótica com Arduino
Robótica com ArduinoRobótica com Arduino
Robótica com Arduino
 

Control Arduino with JavaScript

  • 2. @desisant • Consultora ThoughtWorks Brasil • Open hardware desde 2009 • Hobby #1 objetos interativos • Coordena (arduinrio) • Modera arduinoBrasil • Hackerspace
  • 3. @desisant Agenda • IDE Sublime + Stino • IDE Arduino • Instalar nodejs • Download john-Five Desenvolvimento: 100% prática: • Javascript • Eletrônica • Analógico • Digital Referência: node-ardx.org
  • 4. @desisant Expectativa Explorar meios diferentes para controlar o arduino Utilizando ferramentas que aumentam a nossa produtividade Extrair o melhor que o arduino proporciona Alavancar aprendizado com JS + arduino para desenvolver projetos Javascript é meio e não fm, não é ofcina de javascript Sim Não Não se preocupe, haverá suporte para todos fcarem na mesma página
  • 5. @desisant Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. By Massimo Banzi
  • 6. @desisant Arte de controlar arduino utilizando a linguaguem Javascript
  • 7. @desisant Montar o ambiente: 1) Baixar IDE arduino → www.arduino.cc/ → menu Download 2) Sublime Text → http://www.sublimetext.com/2 3) Instalar plugin STINO no sublime text → https://github.com/Robot-Will/Stino 4) Instalar nodejs https://nodejs.org/
  • 8. @desisant Blink – Piscar Led 2 pin (digital) 5mm LED 330 ohm resistor (orange-orange-brown) jumper wires
  • 9. @desisant var five = require("johnny-five"); var myBoard, myLed; myBoard = new five.Board(); myBoard.on("ready", function() { myLed = new five.Led(13); myLed.strobe( 1000 ); // make myLED available as "led" in REPL this.repl.inject({ led: myLed }); // try "on", "off", "toggle", "strobe", "stop" (stops strobing) }); blink.js
  • 10. @desisant Semáforo 3 pin (digital) 5mm LED 330 ohm resistor (orange-orange-brown) jumper wires
  • 11. @desisant var five = require("johnny-five"); var board, leds=[], ledPins = [2,3,4,5,6,7,8,9]; board = new five.Board(); board.on("ready", function() { // initialize LEDs using a for loop for (var i = 0; i < ledPins.length; i++){ var myLed = new five.Led(ledPins[i]); leds.push(myLed); } function allOn(){ for (var i = 0; i < leds.length; i++) { leds[i].on(); } } function allOff(){ for (var i = 0; i < leds.length; i++) { leds[i].off(); } } function oneAfterAnother() { var delay = 1; board.counter = 0; for (var i = 0; i < leds.length; i++) { var led = leds[i]; board.wait(delay,function(){ console.log(this.counter + " on"); leds[this.counter].on(); }); board.wait(delay + 200,function(){ console.log(this.counter + " off"); leds[this.counter].off(); this.counter = (this.counter + 1) % leds.length; }); delay += 500; } } // allOn(); // board.wait(1000,allOff); oneAfterAnother(); semaforo.js
  • 12. @desisant • 2 pin header x 4 • Piezo element • jumper wires Música
  • 13. @desisant var five = require("johnny-five"); five.Board().on("ready", function() { var piezo = new five.Piezo(9); var val = 0; this.loop(200, function() { if (val ^= 1) { // Play note a4 for 1/5 second piezo.frequency(five.Piezo.Notes["a4"], 200); } }); }); Music.js
  • 14. @desisant • 2 pin header x 4 • 5mm LED • Pushbutton x 2 • 330 ohm resistor (orange-orange-brown) • 10k Ohm Resistor (brown-black-orange) x 2 • jumper wires Push Button
  • 15. @desisant var five = require("johnny-five"), onButton, offButton, led; five.Board().on("ready", function() { onButton = new five.Button(2); led = new five.Led(13); onButton.on("down", function(value){ led.on(); }); }); Button.js
  • 16. @desisant • 2 pin header x 4 • Potentiometer 10k ohm • 5mm LED • 330 ohm resistor (orange-orange-brown) • jumper wires Potenciômetro
  • 17. @desisant var five = require("johnny-five"), board, myPotentiometer; board = new five.Board(); board.on("ready", function() { myPotentiometer = new five.Sensor({ pin: "A0", freq: 250 }); myLed = new five.Led(9); myPotentiometer.on("read", function() { var rawValue = this.raw; myLed.brightness(Math.floor(rawValue / 4)); }); }); Potenciometro.js
  • 18. @desisant • 2 pin header x 4 • TMP36 Temperature sensor • jumper wires Temperatura
  • 19. @desisant var five = require("johnny-five"); five.Board().on("ready", function(){ var tempSensor = new five.Sensor("A0"); tempSensor.on("read", function(err, value){ var cel = (100 * (value / 1000) - 50).toFixed(2); console.log("temp is " + cel); }); }); Temperatura.js