Spooky Mirror

In December, a friend approached me and asked if I could create a visual effect for him. The requirements are to flash a strobe light, activate only when someone is in front of the effect for a couple of seconds, and wait for the person to walk away before it can be activated again. It had to be hidden in a two-way mirror to illuminate a picture behind the glass.

Here’s the circuit I came up with. Unfortunately I never got to see it in action.

The heart of this project is the adjustable Infrared proximity sensor. It triggers the Arduino when a person steps in front of the sensor. The one I used has a range of 20 inches, but can be adjusted as necessary.

For this you’ll need the Infrared proximity sensor, an Arduino, and 5V LEDs. I purchased the Geeetech Infrared proximity switch, but the reviews are now pretty mixed so I will let you decide which one to purchase. I used a 100cm strip of bright white LEDs, but any 5V LEDs or even WS2811 LEDs will work if you want to kick it up a notch. Since space was limited, I used an Arduino nano headerless and soldered the wires directly onto the board.

The connections are simple. The signal wire of the proximity sensor attaches to pin 2. The +5 side of the LEDs attaches to pin 13.

Here’s the sketch

const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
int resetTime = 3000; // the amount of time for effect to reset
int strobeRate = 25; // the blink rate of the strobe
int strobeTotal = 100; // the total number of flashes
int fireDelay = 2000; // the delay for the strobe to fire
int buttonState = 0; // the state of the proximity sensor

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the sensor pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the sensor value:
buttonState = digitalRead(buttonPin);
// check if the proximity sensor detects object
// if it is, the buttonState is LOW:
if (buttonState == LOW){
//delay before second check
//this prevents the effect from being triggered by someone walking by
delay(fireDelay);
// check button state to confirm someone is still in front of sensor
buttonState = digitalRead(buttonPin);
// if someone is still in front of sensor, fire LEDs
if (buttonState==LOW){
for(int flashLED=0;flashLED<=strobeTotal;flashLED++){
digitalWrite(ledPin, HIGH);
delay(strobeRate);
digitalWrite(ledPin, LOW);
delay(strobeRate);
}
//check if someone is still in front of sensor
while(buttonState == LOW){
buttonState = digitalRead(buttonPin);
delay(resetTime);
}
}
}else{
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *