loading

When in the state of Flow, creative people usually don't want to take a break for mortal considerations like eating or bathroom breaks. The great Beethoven famously kept a chamber pot under his piano, so as not to lose momentum in a fit of genius.

This applies for creative people who are not up there in the rare air of the Immortals, too, like people in the workshop at the Bloomington, IN, Makerspace, Bloominglabs. It is far enough from the bathroom that one would have to take a walk into the other room, perhaps to find it occupied, which would only mean further delay.

This gave me the idea for an eye-catching indicator light in the workshop. Why a light? There are lots of power tools in the workshop that make a lot of noise. Just as radio studios have flashing lights to indicate a doorbell ring or incoming call, it would make sense to use a light for this. This could then be expanded for other usage (including a 'doorbell is ringing' indicator, or you could set alarms if you need to be somewhere, or you could be notified somebody just badged in). But before going crazy, we built something with a defined purpose and scope.

Bloominglabs recently hosted Spark.io build nights thanks to Spark.io and Instructables. Without sounding like a salesman (hopefully), I was happy to get my hands on some Spark Cores to play with. I've long been interested in using wireless sensors for projects, but solutions were expensive, or cheap but slow and not necessarily reliable (433 MHz transmitter/receiver pairs), or hard to use. The Spark Core (and soon, the Photon) seemed to address all these issues, plus Spark.io provides an interesting cloud infrastructure I wanted to play with. So this was my chance to get my hands on some.

Step 1: Get Your Materials and Tools

Materials

2 Spark Cores

1 Spark 'Internet Button' (Unfortunately not for sale as of this writing, but Adafruit's Spark Neopixel Ring Kit would also work)

1 Breadboard (or PC/prototyping board)

1 4xAA Battery Pack, like this. The important thing is it must have the 4 batteries side by side, not 2 layers of 2 batteries (4x1 as opposed to 2x2)

1 Ikea Rusch clock or cheap clock from the Goodwill, your basement, etc

1 Door Open Sensor aka Reed Switch aka Magnetic Contact Switch

1 DC Barrel Jack Adapter (for example) (or, just use the micro-USB cable for power)

1 Wall Wart adapter, must provide 3.6VDC to 6VDC and >500mA

Lots of wire

Heat shrink tubing

Breadboard jumpers

A nice case for the door sensor part

Double-sided tape

An on/off switch, this or something similar

Tools

Soldering Iron

Solder

Dremel or other rotary cutting tool

Wire Cutters

Wire Strippers

Scissors

Exacto Knife

Cigarette lighter or other source of heat, to shrink the heat shrink

Your laptop or other computer

Step 2: Build the Door Sensor

The door sensor will be attached to the bathroom door. It is very simple, just a switch. It uses a reed sensor switch to detect door open/close state. When a magnet is near the switch, it closes, otherwise, it's open. You've likely seen these.

There is no reason this can't be extended to add a motion sensor, light sensor, gas sensor (heh), or other sensors to develop more sophisticated occupancy detection algorithms. For now we'll keep things simple.

Circuit

The simplest thing to do is build this on a breadboard. It's good to whip out the soldering iron and solder together the circuit so you can use that breadboard for future prototyping, but for purposes of this Instructable we'll get things going on a breadboard. Connect wires as shown in the Fritzing diagram.

Solder some long wires to the leads attached to the part of the door sensor that will be attached to the wall (the one without leads will be attached to the door).

Place the breadboard in the case. Drill a hole in the case so you can plug in the adapter. You do not strictly have to use the micro-USB socket to power the Spark, and you probably don't want to waste a cable leaving it in a permanent project. A DC Voltage of 3.6V - 6V applied at the VIN pin will do the job. We will use this when powering the flashing indicator,too.

Program the door sensor using the attached code.

Step 3: Build the Flashy Indicator Light: Hack the Clock

The Spark Internet Button (or other NeoPixel ring) is kind of an end in itself as far as generating (potentially blinding!) flashy, colorful light displays, so it gets us most of the way there. However, I wanted something I could easily mount on the wall that does not need to be plugged in. Clocks are nice portable things that hang on the wall and provide useful information, so I decided to take a cheap clock and change it to provide different information.

To hack up your clock:

Pop out the cover. On the back of the clock you will see tabs which can be pressed in either with a small screwdriver or fingernails (if you have them).

Pull off the hands of the clock. They come off easily. Be gentle though, maybe you want to use the mechanism to make something like this LP Clock. For now though, focus on this!

Pop the clock mechanism out of the back. As with the cover, there are tabs which, when pressed in, will allow you to pop it out.

Take a Dremel or other Rotary Tool and cut out a space for the battery case.

Print the attached image on card stock, and cut the holes with an Exacto knife. This will cover the numbers and allow you to connect the battery pack to VIN and GND on the Spark Core. Either use it to cut holes in the face with the numbers, or glue this in place to cover up the numbers.

Step 4: Flashy Indicator Light Continued: Power the Core

Solder red and black wires to the leads of the battery pack. First use a multimeter to make sure you know which is positive and which is ground. To paraphrase Woody from Toy Story, red is positive and black is ground.

Solder the leads of the switch to the red wire and to another wire.

Tin the leads so that red can be inserted into VIN and black can be inserted into GND on the back of the Spark Internet Button. Insert the leads through the rectangular hole in the face of the clock.

Before mounting the Internet Button, program it using the attached .ino code. You can always update the code later, that's one of the cool things about the Spark Core. It's much less hassle to change firmware if you don't have to take the light off the wall and plug in a cable.

Mount the Internet Button to the Clock with double-sided tape.

Replace the clear plastic face.

Put batteries in the battery pack.

Hang this up someplace nice.

Step 5: Some Notes of the Code: the Power of THE CLOUD

OK, get the eye-rolling out of the way. 'The Cloud' is as big a buzzword as any and you will sometimes hear doofuses go on about 'the cloud' who don't have a good grasp of what they are talking about. You may even work for somebody like that.

Let's focus for a moment on what the Spark.io Cloud is and what it gives us. When we register our Cores with our account and provide them with wifi access credentials, they are more than just Arduino-ish things with WiFi radios glued on. There is a service available to us that, first of all, allows us to program the Cores wirelessly. Beyond that we can 'publish' variables (like 'temperature' or 'isItSafeToUseTheBloominglabsBathroom' (according to the docs, variable names are truncated at the 12th character, so be concise)), and any program with the proper credentials can read that value by calling a URL, without us having to hack up a li'l web server with tons of gnarly String handling and socket programming just for this one thing.

Similarly, we can register functions that can be called via a URL and provide hooks for smartphone apps, websites, or services to send commands wirelessly to our Core, wherever we choose to put it (provided it has wireless access).

Also, we can both publish and subscribe to services, so we don't have to resort to polling for a value change (however, there are rate limits on publishing, about one message per second, so watch out).

Our bathroom indicator is a good fit for publish/subscribe. The indicator subscribes to the service that lets us know if the bathroom is open. It only does something if it gets a message.

So while in many ways this is a really simple thing, it gives us a taste of power and possibilities. The indicator can have an API and can be used by a wireless doorbell or another notification system in addition to its now modest role letting us know if the bathroom is ocupado.

Our sensor publishes when the occupancy state has changed, so we specify this in setup():

Spark.publish("bathroomStateToggle", "State", 0, PRIVATE); //Set up Spark.publish() so that the state is published to the Spark Cloud PRIVATELY

When we want to publish a change for our eager listeners, we do this:

Spark.publish("bathroomStateToggle", val ? "VACANT" : "OCCUPIED"); //publish the state to the Spark Cloud as VACANT/OCCUPIED

We also publish the occupancy value as a variable:

Spark.variable("bathroomState", bathroom, STRING);

Making use of these updates on the indicator is easy. In setup, we declare we are subscribing to this info and specify the function to call when we get an update:

Spark.subscribe("bathroomStateToggle", bathroomStateToggle, MY_DEVICES);

The function is quite simple:

// when we get something from published

void bathroomStateToggle(const char *toggle, const char *openClosed){
    connected = true;
    if (strcmp(openClosed,"VACANT") == 0) {
        Serial.println("VACANT");
        bathroomVacant = true;
        flashy(0,255,0,defaultDelay,10);
    }
    else {
        Serial.println("OCCUPIED");
        bathroomVacant = false;
        flashy(255,0,0, defaultDelay,10);
    }
}

Step 6: Conclusions: It's (relatively) Easy to Get Your Things on the Internet

Our Spark Build Nights were a lot of fun. Other projects included a crawlspace sensor (a prime example of a case where you wouldn't want to have to go get your device to re-program it), a web front-end allowing the user to play RTTL (Ring tones) remotely (to be further developed to do audio streaming), and a team had an ambitious idea to use Spark Cores as part of a wireless laser tag game. A couple guys were already building a glockenspiel played by solenoids from a player piano, so they figured why not make it wireless, too.

I found the Spark Cores to be pretty straightforward and simple to work with, once I (and a couple other people at Build Night) got over a few stumbling blocks with the process of claiming the core (long story short: use the Command Line Interface).

The 'Internet Buttons' were really fun - some people were enjoying playing with flashy light shows, or coming up with ideas for the on-board accelerometer. For somebody with programming experience who maybe hasn't done as much with electronics, they'd be a good gateway to Internet Of Things experiments.

I've ordered some more Spark Cores to play with and we'll see how the laser tag game progresses. This was my first Instructable, and that has also been a fun and interesting experience. My big take away lesson is documenting projects is a lot of work in itself, but I did learn a lot in the process and it's something I hope to do more of in the future. I've certainly benefitted from other people's Instructables over the years, so if I can contribute even something small back, that's a good thing.

On that note, thanks again to Spark.io and Instructables for making the Build Night possible!

<p>Well done!</p>
<p>Clever! I want this for the bathroom at work, outside the door (there are three stalls inside). That way I don't have to go in and then stand around awkwardly while I wait for someone to leave.</p>
<p>Thanks! Yes as silly as this is, there is some practical value.</p>
<p>so incredibly cool, thanks for sharing this! how long did this take for you to make? </p>
<p>Thanks for the kind words! We had two Build Nights at the space in November, each a couple hours long. I did most of the stuff then. Before that I spent some time working w/ the Spark Core on my own to experiment w/ some of its features.</p><p>As we all no, projects are never truly done, you just choose a stopping point. I intend to add extra features here and there (web page, more 'intelligent' occupancy sensing algorithm, etc.</p>
<p>I love that you put the indicator on a clock. Now you can also keep an eye on how long a person has been in the restroom, and then shame them... just kidding.</p>
<p>Somebody suggested adding a foghorn in case a time limit is exceeded. The possibilities are endless.</p>

About This Instructable

5,392views

53favorites

License:

Bio: I've been involved with Bloomington IN's hackerspace, Bloominglabs, since it started in 2009. I love making things and seeing cool stuff other people ...
More by sdcharle:Everstream USB Keeps The Stream Alive! Mint Tin AVR Programmer/Prototyper Hacking Skelito, a Talking Skeleton 
Add instructable to: