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.

Here’s the effect in action.

Parts List:
Geeetech Infrared proximity switch module compatible with Arduino/Iduino
Waterproof Superbright 100cm White SMD Led Strip Light Lamp with USB Cable Port 5v
SainSmart Nano v3.0 Compatible with Arduino

See the code after the break.


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 *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>