Description: A simple example application that demos how to use The Electric Imp, and Arduino, Spacebrew and Node.js to build a multi-use sensor
This is an example application that demos how to:
- Use an Arduino to power a proximity sensor as a motion detector, and, when it sees motion, send a command over serial to an
- Electric Imp, which throws an event over the Internet to
- Electric Imp's cloud service, which we've configured to exposes an API that rolls up and reports these events upon HTTP GET, which
- Our Node.js server polls, and upon finding new events, acts by both
- Writing a record to a mongoDB and
- Forwarding the event to
- Spacebrew
Up to this point we have built a Spacebrew publisher, that happens to also persist data (something not typically included in Spacebrew).
We have also included an example Spacebrew subscriber, in the form of a web app that uses the Spacebrew javascript API in order to increment a count of movements observed. Our web app first polls our Node app to get a historical count for the day, and the timestamp of that last movement. The real-time Spacebrew updates then increment this historical count, and reset the last-movement-seen clock.
I used:
-
$5: Arduino Pro Mini 5v 16MHz for the size, but you could use any Arduino
-
$29: Electric Imp—You'll also probably need a breakout board for your Imp.
-
$10 or $20: I used the small April breakout board, but there's also an Arduino Shield
-
$7: Proximity Sensor
-
$10: And you might want a project box
-
$6: some jumpers
All told, this is about $70. Here's what it looked like (used a USB hub to power the Imp and Arduino):
You'll need to have, and know your way around:
- The Arduino IDE
- Node.js and NPM—I recommend installing via Homebrew if you're on a Mac
- mongoDB—again, install with Homebrew if you can
- Some sort of HTTP server. I set one up that listened on port 80. If that doesn't mean anything to you, try using the Apache server built into OS X if you're on a Mac.
- You'll first need mongoDB and Node up and running. Again, if you're on a Mac, I recommend using Homebrew to get that far.
- Start mongoDB, whichever way you choose (see documentation accompanying whichever method you used to install)
- Start Spacebrew (instructions)
- Start app.js in the elevator-subscribe folder
- Start up your web server.
- Pull up the Spacebrew admin and connect your publisher and subscriber
Keep in mind, I have used localhost all over the place here. If you want to be able to access this from other clients, you'll want to use an IP address or hostname that works on your network.
As you wish.