Motion Activated AC Dimmer with Arduino Controller





This project was built for the "Create Denver Economic Garden" exhibit. It was part of the window display for the "pop-up store" at 1600 Glenarm Place. The display was built around an Arduino Duemilanove that was connected to a Velleman K8064 AC dimmer. The whole thing was activated via a PIR motion detector. The components were donated by Sparkfun who deserves great credit for being so generous.

Here is the Arduino code:

/* Brightens and dims a set of LEDs and an AC source via a Velleman dimmer. Dimming action is triggered by PIR sensor.

The circuit: * LEDs attached from digital pin 9 to ground.
Velleman dimmer from pin 13 to ground.


Zac Taschdjian 4/9/10
zac@tasjian.com

*/

// class level variables
int ledPin = 9; // LED connected to digital pin 9
int pwmPin = 10; // output pin to Velleman
int PIRSensor = 2; // the PIR sensor will be plugged at digital pin 2
int state = 0; // variable to store the value read from the sensor pin
int statePin = LOW; // variable used to store the last LED status, to toggle the light


void setup()

{
pinMode(pwmPin, OUTPUT); // sets the pwmPin as output
pinMode(ledPin, OUTPUT); // sets the ledPin as output
pinMode(PIRSensor, INPUT); // declare the PIRSensor as input
}

//main program

void loop() {
state = digitalRead(PIRSensor); // read the sensor and store it in "state"

if (state != 0)
{
// fade in from min to max in increments of 5 points:
for(float fadeValue = 0 ; fadeValue <= 30; fadeValue +=0.01)
{
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
analogWrite(pwmPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

// fade out from max to min in increments of 5 points:
for(float fadeValue = 30 ; fadeValue >= 0; fadeValue -=0.01) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
analogWrite(pwmPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
delay(50); // delay to avoid overloading.
}





top