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('')(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 });; bumperShelfLed.on("hold", function() { console.log( "Button held" ); }); bumperShelfLed.on("press", function() { if(relayShelfLed.isOn){ console.log('turn 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(; console.log(relayShelfLed.isOn); socket.on('led:on', function (data) { relayShelfLed.on(); console.log('LED ON RECEIVED'); }); socket.on('led:off', function (data) {; 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

Continue reading Johnny Five + Arduino + Node Web Server

Using a momentary switch with an arduino

I purchased an arduino a little while ago and got the starter kit with it.
It comes with most of the stuff you need to get into some fun projects and understanding how the whole thing works.

20m 66ft 20awg Extension Cable Wire Cord
HeroNeo 10pcs Connector Adapter Cable
SunFounder 8 Channel 5V Relay Shield Module
Sunfounder Project Super Starter Kit with Tutorial Book
Arduino Mega 2560 Board Model
16mm High Round Cap Momentary Metal Push Button Switch
Triangle Bulbs 3528-IP65-White-60L Pure White LED Strip Light, Waterproof LED Flexible Light Strip 12V with 300 SMD LED

Well my first real project was to get led lights to work. I asked for the led lights for christmas as a stocking stuff.
After that I bought the relay and power supply as a gift to myself for my birthday.

Then it was off to wiring it up.
Plug the 12v into one side of the bread board.
Plug the negative for the LEDs into the same row as the power supply.
Then run a wire from the positive to the Common (center) plug of the relay you would like to use.
Take the positive of the LEDs and plug that into the Normally Closed channel of the relay.
The idea with that is when the relay is triggered the circuit if created.

Now to wire up the relay to the arduino.
Run a wire from the 5v power into the VCC of the relay. This is the part that actually powers the physical switch/magnet to close the circuit on the other side of the relay.
Run a wire from the ground power into the ground of the relay.
Use any of the none PWM channels on the arduino since PWM is NOT what we want for controlling the relay.
I picked ch 22 and plug that into ch 1 of the relay.
Note this relay has all the resistors and circuitry setup so you don’t need to do any of that yourself. You can purchase a relay by itself and do all that yourself.

We now have a fully wired up circuit to control the relay.

Lets try this first code to make sure it worked:

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(22, OUTPUT);

// pinMode(led, OUTPUT);

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(22, HIGH);

digitalWrite(22, LOW);

That worked so we know can now save that file incase we need it later.
Now we can do the logic for the momentary switch. I picked a momentary switch because of the look in the physical world. It returns to a flat state after its pushed instead of like a light switch that moves and stays in the position you put it on. The problem with the momentary is now you have to keep track of states, the time it takes to push the button and how it needs to be wired.

Continue reading Using a momentary switch with an arduino