Go Down

Topic: Pimp Your Pumpkin - An Arduino Jack-O-Lantern 2.0 (Read 873 times) previous topic - next topic


Oct 06, 2013, 08:36 am Last Edit: Nov 01, 2013, 04:26 am by DCrosby Reason: 1
I followed the original how-to, to get prepared for this year's celebration and did a couple things different, and added others.

Original Article is here : http://forum.arduino.cc/index.php?PHPSESSID=loe4mbup8sh2f9cumiac1482t6&topic=8476.15

This is a true "HALLOWEEN(c) Pumpkin" as it plays John Crpenters Haloween theme when mad / activated.

It uses the same orange / red led's for activation. It does use a PIR  Motion Sensor, which I found at my local electronics supply shop. I used about $13 incl. sensor and wires, not including the Arduino Board. I as of right now don't have a pumpkin, as I'll wait a bit closer to the date, but will see if my wife has a plastic one to test drive, and I'll make a small video.

For Right now here's the source.

Code: [Select]
#include "pitches.h"
int ledPin = 13;                // choose the pin for the LED
int inputPin = 8;                // choose the input pin (for PIR sensor)
int candle = 4;
int mad = 2;
int musicPin = 10;
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                     // variable for reading the pin status
int flickerInterval = 25;
long yellowTimer = 0;
long redTimer = 0;

//Halloween Theme
int noteDurations[] = {4,4,4,4,4,4,4,4,4,

void setup() {
 pinMode(ledPin, OUTPUT);      // declare LED as output
 pinMode(inputPin, INPUT);     // declare sensor as input
 pinMode(candle, OUTPUT);
 pinMode(mad, OUTPUT);

void loop(){
 val = digitalRead(inputPin);  // read input value
 unsigned long curMil = millis();
 if (val == HIGH) {            // check if the input is HIGH    
   digitalWrite(ledPin, HIGH);  // turn LED ON
   //Play Music
   // iterate over the notes of the melody:
   for (int thisNote = 0; thisNote < 58; thisNote++) {
     // to calculate the note duration, take one second
     // divided by the note type.
     //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
     int noteDuration = 1000/noteDurations[thisNote];
     tone(musicPin, melody[thisNote],noteDuration);
     // to distinguish the notes, set a minimum time between them.
     // the note's duration + 30% seems to work well:
     int pauseBetweenNotes = noteDuration * 1.30;
     // stop the tone playing:
     digitalWrite(candle, LOW);
     digitalWrite(mad, HIGH);        
   if (pirState == LOW) {      
     // we have just turned on      
     //Serial.println("Motion detected!");
     // We only want to print on the output change, not state      
     pirState = HIGH;
   } else {
     digitalWrite(ledPin, LOW); // turn LED OFF
     unsigned long currentMillis = millis();
     if (pirState == HIGH){                
       // we have just turned off
       //Serial.println("Motion ended!");
       // We only want to print on the output change, not state
       pirState = LOW;      
       digitalWrite(mad, LOW);        
     if(currentMillis - yellowTimer > flickerInterval)
                   yellowTimer = currentMillis;
                   analogWrite(candle, random(0, 256));

I had some issues I wanted to have it play the song, regardless how long it was, and so I added a sizeof statement into the play music loop, it ended up not working so I copied the comma separated list into a spreadsheet had it count the indexes and manually populated the number. Very frustration, if I used the sizeof statement it would always buzz at the end... very annoying. So I may still have some unnecessary  noTone(musicPin);'s in there due to my paranoia of buzzing the house to death.

NOTE: pitches.h can be found here : http://arduino.cc/en/Tutorial/tone   at the bottom of the page.

YouTube Video

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131