Alan Lee
Saul Maddox
Pierce Primm
Nolan Prescott
Binu Panicker
Donovan Buck
Important Points
To Consider
The only dumb question is the one you never asked.
Doesn't work?
It's probably the hardware.
Let's learn about your Johnny-Five Starter Kit!
Breadboard: Solderless wiring
Breadboard: Electrical Connections
Resistors: Reduce Current Flow, lower Voltage Level
LEDs: Light Up Your Life
Buttons, Potentiometer
Sensor: Temperature
Jumper Wires!
Connect The Arduino to your computer via USB.
Make a project directory and navigate
there in Shell/Command Prompt
npm install johnny-five
Turn it on
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
led.on();
});
node led-on.js
Make it blink
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
led.blink();
});
node led-blink.js
Change the blink rate.
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
led.blink(2500); // <-- ms on/off phases
});
node led-blink-slow.js
Manual, live control
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
this.repl.inject({
led: led
});
});
node led-boss.js
In the REPL
> led.on();
> led.off();
> led.blink();
> led.stop();
> led.pulse();
Respond to Button Press
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var button = new five.Button(2);
button.on("press", function() console.log("Button Pressed!"));
});
node button.js
Respond to Button Release
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var button = new five.Button(2);
button.on("press", function() console.log("Button Pressed!"));
button.on("release", function() console.log("Button Released!"));
});
node button.js
Convert Input to Output
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
var button = new five.Button(2);
button.on("press", function() led.on());
button.on("release", function() led.off());
});
node button.js
Multiple States of Input to Multiple States of Output
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
var button = new five.Button(2);
button.on("press", function() led.on());
button.on("hold", function() led.blink(50));
button.on("release", function() led.stop().off());
});
node button.js
Receive Values From a Sensor
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var rotary = new five.Sensor("A0");
rotary.on("change", function() {
console.log("Sensor changed!", this.value);
});
});
node sensor.js
npm install barcli
(say: barklee)
Analog Data
var Barcli = require("barcli");
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var range = [0, 1024];
var graph = new Barcli({
label: "Potentiometer",
range: range,
});
var rotary = new five.Sensor("A0");
rotary.scale(0, 1024).on("change", function() {
graph.update(this.value);
});
});
node sensor.js
Convert 10-bit Input
to 8-bit Output
Side Quest!
Open Developer Tools Console in either Firefox, Chrome or Edge, paste this:
0b1111111111
Hit <enter>
0b00000000 (0)
0b01000000 (64)
0b01111111 (127*)
0b10111111 (191)
0b11111111 (255*)
0b1111111111
0b0011111111
0b1111111111 >> 2
0b0011111111
0b11111111
255
PWM
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means.
Digital control is used to create a square wave, a signal switched between on and off.
- Arduino.cc
Convert 10-bit Analog Input to 8-bit PWM Output
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var led = new five.Led(11);
var rotary = new five.Sensor("A0");
rotary.on("change", function() {
// Analog sensors produce a 10-bit value,
// but led brightness is an 8-bit PWM value.
// Convert by shifting the value's bits
// two places to the right.
led.brightness(this.value >> 2);
});
});
node sensor.js
Temperature
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var temp = new five.Temperature({
controller: "TMP36",
pin: "A0"
});
temp.on("change", function() {
console.log(this.celsius + "°C");
});
});
node temperature.js
Convert Temperature to RGB
Temperature Display
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var temp = new five.Temperature({
controller: "TMP36",
pin: "A0"
});
var rgb = new five.Led.RGB({
pins: [3, 5, 6],
isAnode: true
});
temp.on("change", function() {
rgb.color(??????);
});
});
Control a Continuous Rotation Servo
Controlling a Servo
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var servo = new five.Servo.({
type: "continuous",
pin: "11"
});
this.repl.inject({
servo: servo
});
});
node servo.js
Trim the servo
In the REPL
> servo.cw();
> servo.stop();
> servo.ccw();
> servo.stop();
> servo.ccw(0.5);
> servo.stop();
Connect The Arduino to your computer via USB.
Make it go!
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var left = new five.Servo({pin: 11});
var right = new five.Servo({pin: 10, invert: true});
var servos = new five.Servos([left, right]);
servos.cw();
this.wait(3000, function() {
servos.stop();
});
});
node bot.js
Live Control
var five = require("johnny-five");
var board = new five.Board();
board.on("ready", function() {
var left = new five.Servo({pin: 11});
var right = new five.Servo({pin: 10, invert: true});
var servos = new five.Servos([left, right]);
var commands = {
left: function() { left.cw();right.ccw(); },
right: function() { left.ccw();right.cw(); },
fwd: function(speed) { servos.cw(speed); },
rev: function(speed) { servos.ccw(speed); },
stop: function() { servos.stop(); }
};
this.repl.inject(commands);
});
node bot.js
Try These!
> fwd();
> stop();
> rev(0.5);
> stop();
> left();
> stop();
johnny-five.io
Let's get ready to robot rumble!!!