AC dimmer with Arduino mega 2560 not working

I used this but replace with arduino mega 2560, change D8 to D53, below is my sketch:

int mydelay = 0;
int myvalue=0;
int last_CH1_state = 0;
int firing_pin = 3;
int zero_cross = 53;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
pinMode (firing_pin,OUTPUT);
pinMode (zero_cross,INPUT);
PCICR |= (1 << PCIE0);
PCMSK0 |= (1 << PCINT0);
Serial.begin(9600);
while (! Serial);
Serial.println("Enter value to control");
}
void loop() {
if (Serial.available())
{
String ch = Serial.readString();
int dataIn = ch.toInt();
if (dataIn >= 0 || dataIn <= 1024)
{
myvalue = map(dataIn,0,1024,7200,10);
}
}
if (mydelay == 1)
{
delayMicroseconds(myvalue);
digitalWrite(firing_pin,HIGH);
delayMicroseconds(100);
digitalWrite(firing_pin,LOW);
mydelay=0;
}
}
ISR(PCINT0_vect){
if(PINB & B00000001){
if(last_CH1_state == 0){
mydelay=1;
}
}
else if(last_CH1_state == 1){
mydelay=1;
last_CH1_state = 0;
}
}

But It's doesn't working, the bulb not response anything when I change value to control AC. Any help really appriciated.

1 Like

Hi, have you checked your dimmer separately? While disconnected from the arduino?

1 Like

yeah, uhm, moc3020M seem to be broken after run for a while, after replace It run again.

Hi,
you are using a very low R5 value (100 Ohms).
This generates a current, (approximately 50 mA), much higher than recommended for the Arduino pin (it may damage your Arduino), and very close to the maximum current supported by the MOC203 LED.
This current could be damaging your MOC3020.
Use a resistor to allow a current close to 20 mA.
use a 270 Ohm or 300 Ohm resistor.

MOC3020 datashee:
https://www.mouser.com/datasheet/2/239/MOC302-1175440.pdf

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.