Halloween Haunt Hack

About: The picture is from the starting line at Grandma's Marathon in Duluth, MN. I'm in there somewhere near the middle of the pack.

This is a pretty quick hack to trigger sound and lightning flashes for a simple Halloween Haunt. It uses a light dependent resister to detect a shadow passing over the sensor. An Arduino reads the sensor and triggers a sound to be played and simulates lightning by flashing a bright LED. The sound is played from a Radio Shack digital recording module.A

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: Video Tour

Step 2: The Code

// Lightning
//
// Credits to Rob Tillaart for the lightning simulation code. I don't remember now
// in which forum I (Google) found this code but I think the timing is spot on.
//
// I expanded on the lightning code to trigger a hacked Radio Shack recording module
// when a photo resistor detects darkness below threshold. Hey, it's a cheap form of
// motion detection for a Halloween prop.
//
// Credits to David A Mellis
// and Tom Igoe for the sensor calibration public domain code at
// http://arduino.cc/en/Tutorial/Calibration
//
//
#define BETWEEN 2579
#define DURATION 43
#define TIMES 7

#define SENSORPIN A0
#define TRIGGERPIN 7
#define FLASHPIN 13

unsigned long lastTime = 0;
unsigned long triggerTime = 0;
int waitTime = 0;
int sensorValue = 0;
boolean lightning = false;

int sensorMin = 1023;        // minimum sensor value
int sensorMax = 0;           // maximum sensor value
int sensorThreshold = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("lightning 0.0");

  pinMode(FLASHPIN, OUTPUT);
  pinMode(TRIGGERPIN, OUTPUT);
  pinMode(SENSORPIN, INPUT);
  delay(1000);

  // Calibrate
  // 
  // Sensor readings during the first five seconds of the sketch
  // execution define the minimum and maximum of expected values
  // attached to the sensor pin.
  // This allows the circuit to be used in a variety of lighting conditions
  // by exposing the sensor to the brightest and darkest values to be seen
  // from it's resting position.
  //
  while (millis() < 5000) {
    sensorValue = analogRead(SENSORPIN);

    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }

    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }
}

void loop()
{
  if (millis() - triggerTime > 15000) {
    sensorValue = analogRead(SENSORPIN);
    // apply the calibration to the sensor reading
    // sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
    Serial.println(sensorMin);
    Serial.println(sensorMax);
    Serial.println(sensorThreshold);
    Serial.print("Sensor value: ");
    Serial.println(sensorValue);
    sensorThreshold = (sensorMax - sensorMin) * 2 / 3;
    if (sensorValue < sensorThreshold) {
      digitalWrite(TRIGGERPIN, HIGH);
      triggerTime = millis();
      delay(500);
      digitalWrite(TRIGGERPIN, LOW);
      lightning = true;
    }
    else
    {
      lightning = false;
    }
  }
  if (millis() - waitTime > lastTime)  // time for a new flash
  {
    // adjust timing params
    lastTime += waitTime;
    waitTime = random(BETWEEN);

    for (int i=0; i< random(TIMES); i++)
    {
      // Serial.println(millis());
      if (lightning)
        digitalWrite(FLASHPIN, HIGH);
      delay(20 + random(DURATION));
      digitalWrite(FLASHPIN, LOW);
      delay(10);
    }
  }

  // do other stuff here

}




Hack It! Contest

Participated in the
Hack It! Contest

DIY Audio

Participated in the
DIY Audio

Halloween Decorations Contest

Participated in the
Halloween Decorations Contest

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions