Max Ogden | Open Web programmer
April 2019
Voxel.js Next
Check out the Voxel.js reboot
May 2016
Getting Started With Node For Distributed Systems
Where to get started with streams and peer to peer
July 2015
What's the deal with iot.js and JerryScript
Node.js will soon be running on tiny low power chips
July 2015
Electron Fundamentals
A quick intro to Electron, a desktop application runtime
May 2015
HD Live Streaming Cats to YouTube with the Raspberry Pi Camera
A how to guide
May 2015
Interdisciplinary Open Source Community Conferences
A list of community organized events
April 2015
Setting up HTTPS with a wildcard certificate and Nginx
How I set up HTTPS with Nginx
April 2015
A Month of Modules
Modules Mafintosh and I wrote this month
February 2015
Tessel Powered Plant Watering System
Make an HTTP accessible water pump
January 2015
Portland Fiber Internet
Review of 1Gb fiber from CenturyLink
January 2015
node-repl
An interactive console for node
January 2015
Nested Dependencies
Insight into why node_modules works the way it does
July 2013
Node Packaged Modules
Bringing NPM modules to the web
March 2013
Kindleberry Wireless
A Portable Outdoor Hackstation
January 2013
Bringing Minecraft-style games to the Open Web
A status report from the one month old voxel.js project
November 2012
A Proposal For Streaming XHR
XHR2 isn't stream friendly. Lets explore why and propose a solution!
October 2012
Scraping With Node
Useful modules and a tutorial on how to parse HTML with node.js
October 2012
Building WebView Applications
Things I learned while building @gather
May 2012
Fast WebView Applications
How to make web apps feel fast and responsive
April 2012
Node Streams: How do they work?
Description of and notes on the node.js Stream API
December 2011
Gut: Hosted Open Data Filet Knives
HTTP Unix pipes for Open Data
July 2011
Little Coders
Elementary school programming

Make a water pump that can be turned on and off over HTTP using only JavaScript.

Warning Do not try this at home without the help of an electronics expert. Solid state relays switch high voltage and can cause bodily harm if used improperly.

I have been looking for a way to do hobby electronics projects using JavaScript running on microcontrollers. You can control an Arduino remotely from a laptop over USB with libraries like johnny-five, but you can't keep your code running after you close your laptop since the Arduino can't run JavaScript.

The Tessel is a microcontroller that runs Node code on the board. The team at Tessel wrote a JS to Lua compiler and then they run Lua directly on the Tessel hardware. It's not the fastest thing in the world, but it opens up most of npm to run on a wi-fi enabled, USB powered microcontroller the size of an Arduino.

For this project I used four components. It takes about an hour to put together:

I would also recommend using a junction box/electronics enclosure for housing the SSR along the lines of this one.

The key is the solid state relay. For background on how these works check out this excellent article, but the short version is that they let you use a small voltage (3.3V or 5V such as those available in "digital out" pins in microcontrollers) to turn on and off high voltage circuits such as 110V or 220V (wall outlets).

Instead of using an SSR directly as I did you could also purchase a PowerSwitch Tail, which is a pre-made, safely housed relay enclosure that comes to you already built.

components

To build the 'circuit', I simply cut the dimmer slider portion off of the Lamp Dimmer, stripped the ends off of the wires, and connected them to the SSR instead. Where there used to be a dimmer slider the circuit there is now the SSR.

The flow of electricity is roughly: Wall -> Dimmer -> SSR -> Pump. The tessel is connected to the SSR and can turn it on and off at will.

Again, I can't stress enough that you should really not try this on your own unless you have someone who is experienced with Solid State Relays and 110V/220V electricity.

Here's a video of the system in action:

The tessel is running a small HTTP server written in Node that turns the G3 GPIO pin on or off. When it is on it outputs 3.3V to the SSR, which tells the SSR to turn on voltage, which turns on the pump.

var tessel = require('tessel')
var http = require('http')

var pin = tessel.port['GPIO'].pin['G3']

var server = http.createServer(function (req, res) {
  console.log(req.url)
  if (req.url === '/on') return on(req, res)
  if (req.url === '/off') return off(req, res)
  return res.end('<a href="/on">/on</a> or <a href="/off">/off</a>\n')
})

server.listen(80, function(err) {
  if (err) console.log('error!' + err)
  console.log('http listening')
})

function on (req, res) {
  console.log('turning on')
  pin.write(1)
  res.end('turned on\n')
}

function off (req, res) {
  console.log('turning off')
  pin.write(0)
  res.end('turned off\n')
}

Save the above code as a file called server.js, plug your Tessel over USB, and run tessel push server.js to upload the server onto your Tessel. You can run tessel logs to view the HTTP server logs while your tessel is connected over USB.

Once you have the Tessel configured to join your home Wi-Fi (using the tessel wifi CLI command) it will then always automatically connect a few seconds after powering up, every time. You can put it anywhere in your house, power it over USB, and it will start up it's HTTP server and be accessible over your local network.

You could definitely use other microcontrollers instead of the Tessel for this. I like the Tessel, however, because it is the simplest way to run Node code on hardware, and they also make add-on hardware modules that are easy to use. For example, you could use the Raspberry Pi for this project, but it would be more complicated as you would have to configure Linux. I just prefer to keep things easy!

Happy hacking! Questions? Open an issue in this repository