Wednesday, October 30, 2013

Halloween pumpkin LEDs and IR project

What's Halloween without a carved pumpkin? And what's the point of lighting the pumpkin with a candle when we have LEDs?


The LEDs flicker for 30s when someone is close to the pumpkin. Notice the IR-detector in the nose




In this post I will show how I built my pumpkin powered with a ATtiny85 microcontroller, some LEDs and an IR detector.


Firstly, I soldered 10 LEDS in two groups of five, driven by BC547 transistors. The transistors are driven by two pins on the ATtiny85. A third pin on the ATtiny is used to read a IR sensor (similar to the Parallax PIR). The electronics is driven by three 1.5V AA batteries.


10 LEDs driven by ATtiny85. The IR electronics is wrapped in plastics to protect it from pumpkin juice.

 

The purpose of the code is to let the LEDs flicker for 30s when the IR sensor is activated. The code is super simple and should not need any further comment. 

int led = 1;
int led2 = 0;
int pirPin = 2;
int calibrationTime = 10;

void setup() {               
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT); 
  pinMode(pirPin, INPUT);
  digitalWrite(pirPin, LOW);
  for(int i = 0; i < calibrationTime; i++){
      delay(1000);
  }
}

void loop() {
  if(digitalRead(pirPin) == HIGH){
    for(int i=0;i<300;i++){
      analogWrite(led, random(120)+135);
      analogWrite(led2, random(120)+135);
      delay(100);
    }
  }
  else
    digitalWrite(led, LOW);
    digitalWrite(led2, LOW);

}


The LEDs are PWM driven with some random functions inspired by the Realistic Flickering Flame Instructable. The ATtiny was programmed using the Arduino IDE and my DIY programmer.


Once the electronics is completed it is time to carve the pumpkin. I used a template I found on the Internet to create the scary(?) face. It sure helped a lot.



After the pumpkin is carved and the face is completed, the pumpkin is washed, and the electronics is fitted. The IR detector was fitted in the nose of the face.

Once the pumpkin head is assembled, you might want to roast the pumpkin seeds. If you threw them away, you can enjoy a cup of tea instead. I followed this recipe and was fairly happy with the result.


Roasted pumpkin seeds (or what's left of them anyway)


No comments:

Post a Comment