Introduction: The Jack’O Lantern Early Warning System

This was originally going to be a tutorial on how to hook up a pumpkin to the internet so that the lights inside it could be controlled via twitter, text message, motion or more.

To get started I carved a pumpkin for the first time in 20 years. Needless to say I was proud of the results. I set it out on my deck here in Minneapolis to await the addition of a Core the next day.

However, my neighborhood squirrels were evidently in the mood for pumpkin that night because within 24 hours my pumpkin masterpiece had been destroyed.

Thus was born: The Jack’o’Lantern Squirrel Early Warning System.

(also known as a fun way to bring hardware and the interwebs into your Halloween)

**Huge thank you to my friend and colleague David for helping me out with this!

Step 1: Gather Your Supplies

Carving tools

Garbage collector (this may just be a paper bag but seriously, it's important)

Spark Core + breadboard + usb cable

6 - Jumper Wires (6)

1 - PIR sensor (link is for similar sensor as the one used in the project)

1 - Piezo Buzzer

1 - 1K Ohm Resistor (order of lines on resistor = brown-black-red-gold)

1 - NPN Transistor

1 - USB Power Bank

I got a bunch of this stuff from a Spark Maker Kit we had at the office, but you can also order parts via Adafruit, MakerShed or SparkFun. Pumpkin and carving kit were purchased at my local grocery store Kowalski's.

Step 2: Carve a Pumpkin

Most of you have carved a pumpkin before, and there are other awesome Instructables specifically about this so I won't go into much detail. Technically you could make this without a carving but to attract the squirrels you want to make sure they can smell the pumpkin :)

I originally bought that $5 carving kit as a joke - but honestly it's kind of awesome. I'd like to say my artistic sensitivities allowed me to craft both pumpkins but really it had a lot to do with tracing and just general perseverance.

After spending several hours gutting and then carving your pumpkin it becomes a lot more evident why it's upsetting when a squirrel eats it only minutes after you've finished.

Step 3: Set-up Your Spark Core

1. Set-up your Spark account - You can either set one up via the Spark Core app on your phone (set-up screen is pictured above) or visit spark.io/build which is where you'll be writing your code later on.

2. Connect your Core – You can follow instructions found here: http://docs.spark.io/connect/

3. Name your Core - This is an important step. Do you want to go for a pumpkin or squirrel pun? A frightening name to scare off pesky squirrels? Maybe a simple nod to Doug from UP? I went simple and chose "apumpkin" - partially out of laziness and partially because I had already overextended my wit trying to come up with pumpkin tweets.

Step 4: Connect PIR Sensor and Buzzer

To follow along with the below you'll want to set your Spark Core up so the usb connector is overhanging the back of the breadboard. This will put the front pins of your Core in c19 and h19.

When in doubt, follow the photos above:

1. PIR Sensor + 3 (male to male) jumper wires

a. Take off the top plastic bulb of your PIR sensor so you can see what pin/header is what - GND, OUT, VCC

b. Attach a wire from GND on the PIR sensor to i9 (GND on the Core)

c. Attach a wire from OUT on the PIR sensor to i19 (pin A0 on the Core)

d. Attach a wire from VCC on the PIR sensor to i30 (VIN on the Core)

2. Piezo Buzzer + npn transistor + 1K-Ohm resistor + 3 (male to female) jumper wires

We're going to use an NPN transistor so we can amplify the current going to the buzzer, but in order to use that transistor we're also going to add a resistor to our project. Connections listed below:

a. Piezo buzzer plugged into c1 (+) and c4 (-)

b. npn transistor plugged into a10 (collector), a11(base), a12 (transmitter)

c. jumper wire - a30 (3v3 on the Core) to b12

d. jumper wire - a27 (GND on the Core) to a4

e. jumper wire - b10 to a1

f. 1K-Ohm resistor - b19 (pin D0 on the Core) to b11

3. Attach your USB power bank.

You'll want to power your Core without using your computer unless you have more faith in squirrels typing abilities then I do.

Step 5: Get Twitter Ready

The whole point of this is that your pumpkin is tweeting, so, assuming you yourself are not already tweeting as a pumpkin (which I realize is a dangerous assumption to make) it's time to set-up a new twitter account.

I chose @pumpkinwatch201 - mainly because @pumpkinwatch2014 was already taken. Once you have your account set up it's time to get an OAuth token to help post a message to that account.

David pointed me at an awesome site (created by @NeoCat) that helps you quickly get this token without a whole lot of pain. Without really any pain.

So step by step:

1. Create a punchy new Twitter handle (https://twitter.com/signup)

2. Visit http://arduino-tweet.appspot.com/ and click on "Step 1 : Get a token to post a message using OAuth."

3. Save that token somewhere because you'll be using it later (and yes, it should be that long)

Step 6: Load Your Pumpkin Watch Code Onto Your Core

Load this code into your build site and you'll be ready to go in no time: https://gist.github.com/stephpalm/4c1a11f11547de17bb1c

New to the Spark build system? It's pretty straight forward but you can find additional instructions and guide here: http://docs.spark.io/build/ (quick tip: be sure to save your code as an app before trying to verify or flash!)

*Note that this code has been designed to be easy to use without necessarily having to understand all of the ins and outs of the code, so you can go ahead and get your project running without necessarily understanding every line or having experience with writing firmware code.

Step 7: Personalize Your Code

Things to personalize and keep in mind -

1. Make sure to put in your own Twitter access token up at the top (seriously, i forgot to do this when I updated code after sanitizing it for public use)

2. Write out your own calm and alarm tweets because no pumpkin is the same as another.

3. One last thing to keep in mind, Twitter can get defensive if you're tweeting over and over again so don't get discouraged, you may just need to wait for a little while to get things going again. The larger variety of tweets you have, the more often it will allow you to tweet. Time to get creative (or sneaky...)

Already familiar with Spark, Arduino or C in general? Go onto the next step.

***

If you haven't had a chance to play around with this type of code before I wanted to make a few notes that may answer some of the questions you have as you start poking around in this code. Mainly, I'll just write a few things below that mirror questions I originally had when I was getting goin, and I'll also point you in the direction of additional resources

  • Programming for a Spark Core is a lot like programming on an Arduino - both use a language called Wiring, which is based on a language called Processing, and is a friendlier version of C. You can also program in C/C++ if you are so inclined.
  • Within the code, I've written out a number of comments to help give some context for the different sections. Comments are indicated with // and are not actually part of our program.
  • The main meat of our code lies in void setup() and void loop(). I've found some great definitions below, courtesy of Arduino's resource site
    • "The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries, etc. The setup function will only run once, after each powerup or reset of the Arduino board."
    • "After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond"
    • void is used to indicate that a function is not going to actually return any data, it's just going to be a function.
  • You'll notice the use of bool in this program. bool is short for boolean. As the name implies, this holds one of two values - true or false. You can see another example of it here.

Additional Resources (i.e. where to go for much better explanations then I've given here) ->

Spark community - http://community.spark.io/

Spark firmware documentation - http://docs.spark.io/firmware/

Arduino reference page - http://arduino.cc/en/Reference/HomePage

Adafruit tutorials - https://learn.adafruit.com/

Step 8: Protect Your Pumpkin

It's go time.

Well, first, I recommend doing a few tests to make sure your motion sensor/buzzer/twitter combination is working and then it's time to tackle the squirrels.

We ended up just setting the Core right on top of the pumpkin so the motion sensor was kind of hanging down in front.

And...just a few minutes into our watch I managed to catch a squirrel getting ready to have his way with our pumpkin....just as he approached the buzzer scared him away and our pumpkin tweeted out the alarm.

Success.

Halloween Decor Contest

Participated in the
Halloween Decor Contest

Pumpkin Challenge

Participated in the
Pumpkin Challenge