My first Spark Project -- Door buzzer

So I’ve already put my spark to use on some fun projects.

I live in an apartment building in San Francisco, and my landlady charges an arm and a leg for keys to the front door of the building. Realizing that my old school buzzer inside my apartment was a simple relay away from being wifi enabled, i decided to use my trusty spark core and a little twilio magic to make my front door SMS enabled. The twilio script checks to see the caller-id to make sure its me (this is also adaptable for AirBnB users who want to let guests use the entrance)

Here is the inside of the buzzer in my apartment

I connected the “buzzer” to a solid state relay (i know i could have used a cheaper relay, but it was within arms reach during the project)

Since the SSR only needed 3v to activate, I simply connected the relay to a Digital Pin and ground. When I set the pin to high, the relay closes and the buzzer goes BUZZ.
To make it all work nicely, I made a twilio account that hits a web URL when it receives and SMS. For sake of scrapiness, I just made a basic PHP script that checks that the phone number is valid, and then hits the sparks url with a digital pin high, then waits to seconds, and then hits it with low (so the buzzer goes on for 2 seconds, then turns off)

…and here is the magic in action. sweet and simple.

(since i have many more projects in mind, and only one beta spark, ive since removed it from this install, and im now focused on another project…involving cooking!)


Hey that’s a pretty nice project :slight_smile:

Maybe adding nfc to it would be nice too?
Of course it would get a little more expensive

That’s a pretty sweet project @avidan! I’m surprised the Spark Core works well enough inside that metal enclosure, does it have a metal faceplate as well? I’m guessing it has to be plastic. Where does that USB cable go to to power the Core?

@Joris I don’t think NFC would be appropriate since this control interface is all of the way up in his apartment… you would need to hack the door latch which is probably prohibited.

@BDub – the spark works OK through the faceplate, but the router is within a few feet. I dont recall if its plastic.
The USB cable was initially run to a small USB battery, but I know have the wiring to direct wire it to a 110v through a little USB charger adapter wired into the incoming on the light switch right next to the buzzer. I was hoping that one of the wires going in to the buzzer had enough voltage, but my multimeter said otherwise.

This is actually for my apartment in SF that I rent on AirBnB when Im out of town (almost half the month).

I removed the core for now, since i wanted to use it for my halloween costume! more on that soon. time to get down the garage and start soldering!

@avidan this is an awesome idea. I might try it myself next. Thought of open sourcing the code? I’m looking for code examples

I did this with an arduino a few months back and still use it daily. For me I ran a tiny web server on the arduino that listened on a specific port. Then I opened that port on my firewall to route to the arduino, connected via an ethernet shield.
Lastly, I made a simple iPhone app that sends an HttpRequest to the correct address/port to trigger the door. I then set the app to make this request on startup, and exit() once the request succeeds. I named the bundle of the app “the door”. This lets me say “Open the door Siri” to Siri. She launches the app (same way saying “Open facebook” would launch the facebook app), it sends the request and opens my door :smile:

Taking this one step further, my pebble watch arrived the other day, I can now open the door from my watch too!

@jfernandez You’re welcome to my code. It should run on the spark as is, or you could customise it a little to remove the need for the http server and just use the spark cloud. This would avoid messing with port forwarding and stuff. I’ll put it on github in a few days.

I was motivated by this thread, specifically the idea of writing an app called “the door” and so this evening set about automating my door… I didn’t change any code in the core itself, or even write a script for it. Simply sent an API call to the cloud to toggle an output pin HIGH, then sent a second call to toggle low again.

A transistor and relay was added to the core output, this was attached across the existing push button.

I’d never written android code, so created a very crude application to POST the request to the cloud as soon as the application ran, it would then immediately exit again.


@hsinhai This is great!! Would it be okay if I share it on our social media channels?

sweet! i like the android app move. that has me inspired to put an NFC tag on the front door (or maybe a bluetooth beacon in my mailbox)…so many ideas.

very excited that this little project inspired so many (twilio tweeted about this page!)

happy to open source it. i didnt write any custom firmware for the spark (since it was an extra early prototype, and the tinker firmware was sufficient)

all i did was create a twilio account and point SMS to this PHP script I whipped up (sorry if there are typos, i didnt make a separate copy of the source for my halloween costume, and didnt get to re-test).

here it is.


	// make an associative array of senders we know, indexed by phone number
	$people = array(
		"+XXXXXXXX"=>"My Friend"

	// if the sender is known, then greet them by name
	// otherwise, consider them just another guest
	if(!$name = $people[$_REQUEST['From']]) {
		$name = "Guest";

	header("content-type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$key =   'XXXXXXXXXXXXXXXXXXXXXXX'; //put in your spark API key herer

if($_REQUEST['Body'] == "Open")
$pin = "D7";
openDoor($key, $pin); // open the door

function openDoor($key, $pin)
$result = hitTheSpark($key, $pin, "HIGH");
sleep(2);  //keep the buzzer pressed for 2 seconds
$result = hitTheSpark($key, $pin, "LOW");

function hitTheSpark($key, $pin, $pin_level)

$post_data = "access_token=$key&pin=$pin&level=$pin_level";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '');  // make sure to change your URL to reflect your spark ID
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));   
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$response = curl_getinfo( $ch );
return $result;

	<Message>Thanks <?php echo "Welcome home " . $name . "!"; ?></Message>
1 Like