Pages: [1]   Go Down
Author Topic: AC dimmer 220V 50Hz  (Read 2855 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have schematic:



and code:

Quote
// AC dimmer with zero-crossing detection
// First edition by Niels Oestergaard
// !!!!!!!! not verified !!!!!!!!!!!!!
// based on design Andrew Kilpatricks tutorial: http://www.andrewkilpatrick.org/blog/?page_id=445

//strategy for dimming part of the sketch:
//
// set counting interval to reach 255 in one half-period (50 hz = 10 millis pr. half-period / 60 Hz 8.3333333333333 pr. halft periode )
// set output to 0 - 255
// detect zero crossing (on interrupt pin)
// in interrupt rutine calculate time for turning on
// when millis reaching time, turn on for a short while
// turn output off to be sure not to trigger to early in next halfperiod

// interrupt 0 - (pin 2)


int dimmer1Pin = 10;         //output to opto triac (MOC 3010/3020)
int ledPin = 13;             //reserved for sanity check and visual feedback
volatile int freqAdjTime = 20;   //set to 10 for 50 Hz, and 8 for 60 Hz
volatile long nextOnTime = 0;    // variable for storing a time (in millis) for when to fire the output next
volatile int outputValue;      // Varialble for storing the output value 0-255
//unsigned int inputValue;     // Variable for storing input value (ie. a potentiometer)
long lastMillis;             // for timing purposes


void setup()
{
  pinMode(ledPin, OUTPUT);    // sets the digital pin as output
  // sanity check
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  // end of sanity check
  attachInterrupt(0, zero, RISING); //Attachment of zero crossing detection, which means the interrupt rutine "zero" is called each 20 millis
}

void loop()
{
 //
  if (nextOnTime < millis()) {       //is it time to set pin on?
    digitalWrite(dimmer1Pin, HIGH);    // then set it
    delay(2);                  // wait a bit to be sure the triac is on
    digitalWrite(dimmer1Pin, LOW);     // turn of the trigger to be sure it is not trigger in the very beginning of next halfperiod
  }

// A loop that slowly increases outputvalue
if (millis()-lastMillis > 250 ) {     //increase output each fourth of a second
    outputValue++;                //increase outputvalue by one

    //Check if max is reached
    if (outputValue  > 255) {         // output = maximum
      outputValue = 0;            // set output to zero
    }
  }
}

void zero()
{
// set a volatile variable with the millis value + (the value of the desired output (0-255) multiplied by the freq adj time)
nextOnTime = millis() + (freqAdjTime * outputValue); //how long will this calculation take? too long to enable low output??

But it's not working smiley-sad

Please help...
Logged

SW Scotland
Offline Offline
Edison Member
*
Karma: 13
Posts: 1327
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What do you mean by "it's not working" 
What type of load do you have connected to the lower pair of terminals (on the right of the drawing)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not working = does not change the brightness

load - is lamp 60Watt

p.s. sorry for my english
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 241
Posts: 24480
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What debugging have you tried?
Are you even getting interrupts?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Topsham, Vermont USA
Offline Offline
Edison Member
*
Karma: 24
Posts: 1766
... in The Woods In Vermont
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
The 4N35 is probably damaged.  You need a regular diode in the reverse direction across the 4N35 LED to handle the reverse voltage.

The 82K  resistors need to be 1 watt rated; total dissipation is 2.2W

Logged

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

why damaged?

can you give me schematic?
Logged

Topsham, Vermont USA
Offline Offline
Edison Member
*
Karma: 24
Posts: 1766
... in The Woods In Vermont
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
why damaged? can you give me schematic?

Look at your schematic.  The 220V AC Waveform goes both + and - .  When it is + the 4n35 LED conducts in the forward direction at about 10 ma.

BUT what about the opposite polarity? The reverse voltage across the 4N35 LED will be about 220 * (Square root of 2 = 1.414) or about 311 volts.  The 4N35 LED is only rated at about 10 volts reverse voltage, so it has almost definitely broken down electrically.

You need to put a diode across the 4N35 LED in the reverse direction. It will conduct and protect the 4N35..

Try it. Also, check the output of the 4N35. Does it ever change now??

OH: Other problem? The MOC3061 is, I believe, a "Zero Crossing" type, so it will not work in this application. Check the data sheet..
Logged

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

SW Scotland
Offline Offline
Edison Member
*
Karma: 13
Posts: 1327
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd also suggest you replace the 82k mains resistors by type y capacitors rated for mains voltage.  They will offer suitable current limiting impedance with zero heat output (current is out of phase with voltage or cos phi = 0)

If you want 41kohms at 50Hz the  capacitor values should be a nominal 0.1uF  (uF meaning microfarad)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you repost your schematic KNYAZ 2020  ? Can't see the schematic you've posted some time ago,
I've tried out some other circuits but this one I think is close. http://postimage.org/image/epi813wmx/
Thing is, in the simulation program there is just MOC3021 and I've tried out your code in my simulation. Looked at the
datasheets for 4N35, MOC3021 and the triac BT139. Tried adjusting the forward and holding currents on triac manually
but with no luck. The bridge rectifier is a 400V 1A,and triac is currently standing on 1mA forward and 5mA holding current. Someone who can help me on this ?
« Last Edit: November 25, 2012, 11:19:06 am by Tesla_pow » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To be honest, I do not fully understand the code that you have written, but you may antto have a look here:
http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/
That has a working circuit+software

The circuit is probably not so much different from what you are using.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

further to my post of just now, the MOC3061 will certainly not be working in this circuit coz it is a zero-crossing optocoupler and that is exactly what you NOT want, as you pick up your zeroXing from the 4n35.  Use a MOC3020 instead.

Again, have a look here: http://www.instructables.com/id/Arduino-controlled-light-dimmer-The-circuit/
Logged

Pages: [1]   Go Up
Jump to: