Go Down

Topic: Dimming AC lights (Read 11913 times) previous topic - next topic


Hi Arduinos,
I'd like to use the arduino with sensors to dim AC lights. I've never interfaced a microcontroller to dim AC and would like to know some tips and tricks and bypass the traps that you might have encountered while doing so.


I can recommend buying a  velleman K8064 dimmer kit as suggested by Massimo:

it was really quick to get everything up & running...


As someone who's gone the light&arduino path.. it only really ended when i bought dmx equipment..
which by itself is a fragile protocol, but as least it dims lamps easily..

I've also built the arduinoDmx (http://www.arduino.cc/playground/Learning/DMX)
it worked but i had a lot of sync problems with my dmx lamp - although to really debug these problems you
must have a dmx testing device, or at least some more dmx equipment to try on.

Ciao, oori


Hi Oori,
For this project, I wanted to control normal house lamps and not rely on DMX equipment.
I've gone the DMX way and had my share of DMX problems, btw search for my posts on DMX for a more precise code for Arduino DMX if your DMX lamps are picky.

also Thanks Tomski for the velleman kit reference.


X10 with a "firecracker" controller? That should be easy to drive from an Arduino. You can get the firecracker, transceiver, hand held remote, and a dimmer for $20. Looks like extra dimmers go for about $10 each. Those are 110v 60hz units, I presume there are variants for folk with more deadly mains.

It looks like the firecracker works by using RTS and DTR as both power and signaling. I don't know if you'd have to drive them with more than 5v. http://www.rentron.com/FireCracker.htm As if I didn't have enough to do.. it looks interesting.


Apr 09, 2009, 03:45 pm Last Edit: Apr 09, 2009, 03:46 pm by jeep1984 Reason: 1

This might be a useful link for people trying to dim AC lights through a Velleman K8064 kit and an arduino:


It includes sample code and circuit diagram, and it works.



I've already interfaced to the firecracker -
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom."
~ Clifford Stoll


May 11, 2009, 04:41 pm Last Edit: May 11, 2009, 04:43 pm by t.m.assman Reason: 1

I used an Arduino and a Velleman K8064 to make my own WakeUpLight.

The electric circuit scheme of brakmolotov.net posted by jeep1984 above was very helpful, thanks!

Everything works fine, I've placed a movie on Youtube.

Code: [Select]

// Define pins

int pwmPin    = 9;    // select the output pin for the dimmer
int analogPin = 1;    // select the input pin for the alarmclock
int ledPin    = 13;   // select the pin for the LED

// Program variables

int pwmVal    = 0;     // Variable to store the value to send to the pin
int analogVal = 0;     // Variable to store the value read from the analog pin
int fadeCount = 0;     // Loop counter
int stopCount = 0;
int wait      = 250;   // 250ms delay; shorten for faster fades

void setup()
 pinMode(ledPin, OUTPUT);   // declare the ledPin as an OUTPUT
 pinMode(pwmPin, OUTPUT);   // sets the pins as output
 analogWrite(pwmPin,   pwmVal);   // Write current values to pwm pin

// Main program
void loop()
 analogVal = analogRead(analogPin);   // read the value from the sensor
 if (analogVal==0)                    // if no alarm beep is received
   stopCount += 1;
 else                           // if alarm beep is received
   fadeCount += 1;
   stopCount = 0;
 if (fadeCount==20 && pwmVal!=255)
   pwmVal += 1;
   analogWrite(pwmPin,   pwmVal);   // Write current values to pwm pin
   digitalWrite(ledPin, HIGH);   // turn the ledPin on
   digitalWrite(ledPin, LOW);   // turn the ledPin off
 if (stopCount==60)
   pwmVal = 0;
   analogWrite(pwmPin,   pwmVal);   // Write current values to pwm pin
   delay(wait); // Pause for 'wait' milliseconds before resuming the loop




I have built the circuit exactly like in brakmolotov's example.

I can see the value going up and down between 0v and 5v nicely on pin 9 when I run his code.

But I am not getting past the transistor. When I measure at the output to the velleman I see a constant 6v

Any clues as to why this might be? Have I got something the wrong way around?


here's the schematic


I noticed the schematic has a GND connection going to the Velleman. This is wrong it should go to the analogue input line on SK3. These are not the same as gnd on the Velleman




That's what it says on the data sheet.


Hi Mike

I get what you mean, but not what it means...

The SK3 has "+" and "-" connectors, "-" is not ground?




Jun 25, 2009, 06:06 pm Last Edit: Jun 25, 2009, 06:06 pm by Grumpy_Mike Reason: 1
The SK3 has "+" and "-" connectors, "-" is not ground?

No it is the other side of an opto isolator. So it needs to be connected to this and not ground as shown in the diagram. In fact the 1M and capacitor are rubbish. But it will work if you connect what is marked gnd to the SK3 - and the 5V to the SK3 +


most excellent sir

thank you


Go Up