Dimming AC lights

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.
Thanks!

I can recommend buying a velleman K8064 dimmer kit as suggested by Massimo:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1150063488

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 (Arduino Playground - 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.

Hi,

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

http://www.brakmolotov.net/blog/Meriol_Lehmanns_blog/Entries/2009/2/23_How_to_control_an_AC_dimmer_with_an_Arduino.html

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

Jaap

@jims
I've already interfaced to the firecracker -
http://www.arduino.cc/playground/X10/CM17A

Hi,

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.

// 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)
  {
    fadeCount=0;
    pwmVal += 1;
    analogWrite(pwmPin,   pwmVal);   // Write current values to pwm pin
    digitalWrite(ledPin, HIGH);   // turn the ledPin on
  }
  else
  {
    digitalWrite(ledPin, LOW);   // turn the ledPin off
  }
  
  if (stopCount==60)
  {
    stopCount=0;
    fadeCount=0;
    pwmVal = 0;
    analogWrite(pwmPin,   pwmVal);   // Write current values to pwm pin
  }
  
    delay(wait); // Pause for 'wait' milliseconds before resuming the loop

}

Tim

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?

Thanks

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

SK3?

SK3?

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?

thanks

fubbi

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

fubbi

Regarding that capacitor, what should it's working voltage be?

Hi Mike,

I got slightly confused...
Do you mean that we can remove that capacitor and resistor and it will still work fine?
Is the diagram still the same as before but without the cap and resistor?
When you say "it will work if you connect what is marked gnd to the SK3 - and the 5V to the SK3 +" do you mean its exactly the same diagram but instead of having GND above "to Velleman Dimmer" its SK-?
I find it strange that the transistor is grounded to the Arduino twice, why is that?

Regarding that capacitor, what should it's working voltage be?

Well it only sees 5V so 6.5V working would be fine. However it is a bit useless.

Do you mean that we can remove that capacitor and resistor and it will still work fine?

Yes. When the transistor is on the capacitor is discharged. When the transistor is off the capacitor charges up through the resistor, thus keeping current flowing through the opto for a short time. BUT as it is through a 1M resistor it only has 0.005mA flowing and that is not enough to do anything to the LED in the opto isolator.

Is the diagram still the same as before but without the cap and resistor?

yes

When you say "it will work if you connect

Yes on the data sheet this connection is not called ground. The two connections are marked SK3+ and SK3-. Connect the SK3- to where it says ground on the diagram and SK3+ to where it says +5V in the diagram.

I find it strange that the transistor is grounded to the Arduino twice, why is that?

It's not!
The two grounds on the arduino are in effect the same point electrically speaking, one is connected to the emitter and the other to the redundant capacitor.

Don't you blow up the Arduino if you feed it 9 volts?
I thought it can only handle 5 volts like other microcontrollers...

Another thing what I don't understand is that the Velleman K8064 needs 0..12 volts input. You only putting 9 volts in it? How is is possible then to turn the light 100% on??

With kind regards,

Atmoz

Don't you blow up the Arduino if you feed it 9 volts?

No. The Arduino Vin pin is the same path as the extenal power connector input voltage, and it routes the voltage to the on-board +5vdc voltage regulator, so the micro still gets the 5vdc it needs.

Lefty