Proximity Sensing Pumpkin Carving




Introduction: Proximity Sensing Pumpkin Carving

I love Halloween. It is my favorite day of the year easily. Free candy and costuming; how could this get any better?! And no holiday better sums up DIY than halloween :) 

This ible will show you how to make your pumpkin carving a bit more interactive. By adding a IR distance sensor along with a couple of LEDs and a buzzer (all of which are optional) you can turn your carving into something way cooler.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Materials

First off, you will need a pumpkin (duh) and all the pumkin carving tools as normal. The rest of the materials are all electronic parts that you can order easily or may even have (depending on what type of robot you are), so you will also need a soldering iron. 

  • 1 Red LED (as bright as possible, >15000mcd)
  • 1 Amber LED (>15000mcd)
  • 2   220 ohm Resistor
  • ATtiny85
  • Buzzer / Speaker
  • Switch
  • 3 AA batteries + holder
  • 2N2222  NPN transistor
  • 10 uF electrolytic capacitor
  • wire

Step 2: Code

There are several ways you can program the ATtiny. You can use a programmer such as this one from adafruit. Or you can program directly using an Arduino. I will be using the arduino method today. I can help people if they want to use a programmer though, just message me.

A great ible for how to use the Arduino as a programmer can be found here. I highly recommend reading it even if you aren't going to make your own pumpkin as it is very helpful and well put together! What I have done here (as shown in the picture) is hook up the arduino to the ATtiny as described in the above ible link.

The yellow (or white) line on the sensor returns a value between 0 - 1023. You can set the threshold accordingly.

The code that you will write to the Arduino is below:
I think it is right, I lost the original code that I programmed mine with, but this looks right... someone want to double check me?
It is very similar to the arduino version you will see in 2 more steps...
long a = 0;
long c = 0;
void setup() {
      pinMode(0, OUTPUT); //amber
      pinMode(1, OUTPUT); /*red + buzzer*/ }
void loop() {
      if (analogRead(3) > 85){
            if (c >= 5){digitalWrite(0, LOW);
                        digitalWrite(1, HIGH);}}
      else {digitalWrite(1, LOW);
            c = 0;
            unsigned long b = millis();
            if(b - a > 25){
                  a = b;
                  analogWrite(0, random(0, 256));}}}

Step 3: Circuit

The diagram explains everything better than my words can. If you have any questions, feel free to ask!

Step 4: {alternative} Arduino Circuit + Code

Here is the equivalent circuit circuit if you just want to use an arduino.


The wiring is shown below. 

The amber LED has its + lead connected to Arduino pin digital 11. The - lead is grounded.
The red LED has its + lead connected to Arduino pin digital 7. The - lead is grounded.
The buzzer has its + lead connected to Arduino pin digital 4. The - lead is grounded.
The IR distance sensor had its red (+) lead connected to Arduino 5V line.
The IR distance sensor had its black (-) lead connected to Arduino gnd line.
The IR distance sensor had its yellow / white lead connected to Arduino analog in pin 0.


The code below is copied from "pimp your pumpkin" or you can download the sketch now.
#define CANDLELED 11
#define REDLED 7
#define BUZZER 5
#define SENSOR 4    //nvm not using
#define PROXIMITY_THRESHOLD 85   // modify this # to change sensitivity
#define PROXIMITY_CONSECUTIVE_READINGS 3  // I may suggest increasing this to perhaps 5-8

long previousMillis = 0;
long closeReadings = 0;

void setup() {
      pinMode(CANDLELED, OUTPUT);
      pinMode(REDLED, OUTPUT);
      pinMode(BUZZER, OUTPUT);
      pinMode(SENSOR, INPUT);    //nvm not using
      delay(1000); // Allow the proximity sensor to initialize
void loop() {
      if (analogRead(0) > PROXIMITY_THRESHOLD) // Is someone close?
            if (closeReadings >= PROXIMITY_CONSECUTIVE_READINGS) // require n consecutive "close" readings before going into EVIL mode. This prevents little blips of the buzzer.
                        digitalWrite(CANDLELED, LOW);
                        digitalWrite(REDLED, HIGH);
                        tone(BUZZER, BUZZER_FREQUENCY);
      { //regular candle flicker. Based on Arduino example BlinkWithoutDelay.
            digitalWrite(REDLED, LOW);
            closeReadings = 0;
            unsigned long currentMillis = millis();
            if(currentMillis - previousMillis > FLICKER_INTERVAL)
                  previousMillis = currentMillis;
                  analogWrite(CANDLELED, random(0, 256));

Step 5: Happy Halloween

Put the circuit inside the pumpkin. Perhaps wrap the circuit in electrical tape to prevent any shorts. You can prop the lights forward if you want, but its not necessary.

The sensor can sit in the back of the pumpkin if you can get it to work. It can be hard to align properly though. So if you have problems aligning the sensor, you can instead cut a rectangle to shove the sensor into. Alternatively, you could just mount the sensor on top of the pumpkin.

you can look at a concise summary of this circuit design at my website.

inspiration notice!!!
self designed, but found the Arduino version while doing some searching during the design process at I tested the Arduino version before programming the ATtiny. However, the ATtiny85 is my original crude design (although I fully expect and hope that other people have done similar things). The code and circuit are both very simple and very quick. 

Halloween Decorations Contest

Participated in the
Halloween Decorations Contest

Make It Glow

Participated in the
Make It Glow

Be the First to Share


    • Toys and Games Challenge

      Toys and Games Challenge
    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge