Johnny Five + Arduino + Node Web Server

Johnny Five Node Module

Johnny Five – Buttons

Arduino + Johnny Five

Johnny Five – Relay

Originally wired the relay and button based on a different diagram. With Johnny five though, its looking for a much more logical and clear setup. So I rewired based on the diagrams and had to see the relay to type: "NC" and was able to get the lights to turn on and off with the correct button pushes.

Johnny Five really helps abstract away the need to figure out how Firmata is handling everything but also allows you a lot of control with great documentation (once you find it).

Pass one of Button + Web Browser turning off and on a light:


var express = require("express"); var five = require("johnny-five"); var board = new five.Board(); var bumper; var app = express(); var httpServer = require("http").createServer(app); var io=require('socket.io')(httpServer); var port = 3000; app.use(express.static(__dirname + '/public')); app.get('/', function(req, res) { res.sendFile(__dirname + '/public/index.html'); }); httpServer.listen(port); console.log('Server available at http://localhost:' + port); var led; var relayShelfLed; var bumperShelfLed; board.on("ready", function() { relayShelfLed = new five.Relay({ pin: 22, isOn: true, type: "NC" }); this.repl.inject({ relay: relayShelfLed }); bumperShelfLed = new five.Button({ pin: 52, // invert: true }); relayShelfLed.off(); bumperShelfLed.on("hold", function() { console.log( "Button held" ); }); bumperShelfLed.on("press", function() { if(relayShelfLed.isOn){ console.log('turn off'); relayShelfLed.off(); }else{ console.log('turn on'); relayShelfLed.on(); } console.log( "Button pressed" ); }); bumperShelfLed.on("release", function() { console.log( "Button released" ); }); //Socket connection handler io.on('connection', function (socket) { console.log(socket.id); console.log(relayShelfLed.isOn); socket.on('led:on', function (data) { relayShelfLed.on(); console.log('LED ON RECEIVED'); }); socket.on('led:off', function (data) { relayShelfLed.off(); console.log('LED OFF RECEIVED'); }); }); console.log('Waiting for connection'); }); //turn light on //turn light off //event emiter for light

I created a quick project to make this work with my arduino and a relay.

Office Manager



2 thoughts on “Johnny Five + Arduino + Node Web Server”

  1. Hey !
    I search some help for use button with J5.

    For make instant state view of 4 switch in web page.

    But i don’t really know how tu use emitter for this case.

    Can you help me ?

Leave a Reply

Your email address will not be published. Required fields are marked *