twitter
Search

Entries in halloween (1)

Wednesday
Feb012012

Arduino Haunted Pumpkin

For the Radio Shack Great Create, I crafted a motion-sensitive haunted pumpkin with pulsing red eyes. When motion was detected, it would blink wildly and issue a wicked laugh. The full how-to with pictures and video is posted on instructables.

Full source code:

 

/*
This is the source code for the motion sensitive
haunted pumpkin built for Radio Shack.
Original code by Daniel Gentleman, thoughtfix.com
*/

// Set up pin assignments
int leftEye = 3; // PWM pin 3
int rightEye = 5; // PWM pin 5
int redBlink1 = 9;
int redBlink2 = 10;
int whiteBlink = 13;
int laughBox = 12; // transistor to voice module
int pirSensor = 7; // passive infrared sensors
int pirState = 0; //Initial IR state

// Setting up pin modes
void setup() {
pinMode(leftEye, OUTPUT);
pinMode(rightEye, OUTPUT);
pinMode(redBlink1, OUTPUT);
pinMode(redBlink2, OUTPUT);
pinMode(whiteBlink, OUTPUT);
pinMode(laughBox, OUTPUT);
pinMode(pirSensor, INPUT);
}

void loop () {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(leftEye, fadeValue);
analogWrite(rightEye, fadeValue);
// wait for 30 milliseconds
delay(30);
}
pirState = digitalRead(pirSensor); // read the state of the pirsensor value:
if (pirState == HIGH){ // If motion is detected
freakout(); // Call the freakout routine
}

// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(leftEye, fadeValue);
analogWrite(rightEye, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
pirState = digitalRead(pirSensor); // Same as above
if (pirState == HIGH){
freakout();
}

}

void freakout(){
digitalWrite(laughBox, HIGH); // Send intial ON for all pins
digitalWrite(leftEye, HIGH);
digitalWrite(rightEye, HIGH);
digitalWrite(redBlink1, HIGH);
digitalWrite(redBlink2, HIGH);
digitalWrite(whiteBlink, HIGH);
delay(250);
digitalWrite(laughBox, LOW); // turn off laugh button
for (int i=1; i<=40; i++){ // Start blinking mayhem
digitalWrite(leftEye, HIGH);
digitalWrite(rightEye, HIGH);
digitalWrite(redBlink1, LOW);
digitalWrite(redBlink2, LOW);
digitalWrite(whiteBlink, LOW);
delay(50);
digitalWrite(leftEye, LOW);
digitalWrite(rightEye, LOW);
digitalWrite(redBlink1, HIGH);
digitalWrite(redBlink2, HIGH);
digitalWrite(whiteBlink, HIGH);
delay(50);
} // Finish blinking mayhem, turn everything off
digitalWrite(redBlink1, LOW);
digitalWrite(redBlink2, LOW);
digitalWrite(whiteBlink, LOW);
}