controlling AC phase (AC dimming light)

Talk about Arduino board, sheilds. Sharing Arduino projects, program, problems, solutions, suggestions..... many more, all are welcome.

Re: controlling AC phase (AC dimming light)

Postby fitri » Wed Mar 07, 2012 11:33 am

why did i need GP2 pushbutton?
when i need to press that button?

sorry i didnt understand... :oops:
fitri
Apprentice
 
Posts: 42
Joined: Mon May 02, 2011 8:20 pm

Re: controlling AC phase (AC dimming light)

Postby ABSF » Fri Mar 09, 2012 11:18 am

ABSF WROTE:I use the cytron example for detecting a push button to poll the GP2 pulse. Not sure if the flow is correct.


I only use the software example to detect the pulses from GP2 pin. GP2 is not a push button. If you refer to the schematics in Page one, you can see that GP2 is connected to the Collector of the NPN which detects the zero_cross pulse. This pulse is used to synchronise with the AC so the ON and OFF of the AC wave would always start from a particular point. You can change "GP2" to something like "zero_cross" if that makes you comfortable. 8-)

I dont own an Arduino so I cant try out the program until I bought one. There is a code that I downloaded from the Arduino forum and I am trying to understand how it works. Once I know how it works I can modify it to work with the circuit that I posted. The complete code is here...
CODE: SELECT_ALL_CODE
// 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 routine "zero"
                                    //is called each 20 millis at digital pin 2.
}

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??


It uses 2 interrupts to operate. One from "Digital Pin2" and one from "Timer1".

Here are some of the references from Arduino useful for this program:
Arduino - AttachInterrupt
http://arduino.cc/en/Reference/AttachInterrupt
Arduino - Millis
http://arduino.cc/en/Reference/millis
Arduino playground - Timer1
http://arduino.cc/playground/Code/Timer1
Arduino - Reference
http://arduino.cc/it/Reference/HomePage

Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Re: controlling AC phase (AC dimming light)

Postby ABSF » Sat Mar 10, 2012 7:08 am

Hi, I am very concerned whether you should use 220V AC to test your circuit. Why dont you use 12V lamps (<1A) from signal light or 3rd brake light of cars to test your circuit. A mistake like using under-rated components like opto-coupler or TRIAC can easily toast your Arduino or yourself since you sound like you're a newbie.

The MOC3021 can stand 400V AC according to the specs. If your opto cannot withstand that voltage from the mains, it will explode inside the chip and as you can see the chip is so small, both the LED and DIAC inside are constructed on the same silicon wafer so the high voltage might leak/short over to the LED side and burn off your MCU in your Arduino.

I wrote to my expert friend about your dimmer circuits and this is what he replied me.

As for the person who asked you that - tell him/her that AC currents are very dangerous and dimmer circuits must be constructed with the supervision of another person.


Btw, can you advise him to find examples of these AC light dimmer online elsewhere? It is not very safe to design it by the hand if he/she has insufficient knowledge on Power Electronics.

It is because I don't want him to destroy himself/herself, his/her Arduino, and the optocoupler.


Allen
The next war will determine NOT who is right BUT what is left.
User avatar
ABSF
Professional
 
Posts: 810
Joined: Wed Nov 10, 2010 9:32 am
Location: E Malaysia

Previous

Return to Arduino Based

Who is online

Users browsing this forum: No registered users and 21 guests

cron