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.println("lightning 0.0");


  // 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.print("Sensor value: ");
    sensorThreshold = (sensorMax - sensorMin) * 2 / 3;
    if (sensorValue < sensorThreshold) {
      digitalWrite(TRIGGERPIN, HIGH);
      triggerTime = millis();
      digitalWrite(TRIGGERPIN, LOW);
      lightning = true;
      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);

  // 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


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest