dimming AC light

I am new to Arduino. I am wanting to dim and fade in and out an AC light bulb. I have Arduino UNO main board. When connected to a dimming board labelled Firing angle method I can get it to do what I want. I ordered a 8 channel board that said Firing Angle Method in description but the actual board is labelled "leading Edge dimmer" and it does not dim. Obviously these are different boards. Any suggestions on how to write sketch to control dimming on leading edge dimmer board?

i am trying very simple sketch to check function

int led = 9;
int brightness = 20;
void setup() {
pinMode(led, OUTPUT);
}

void loop() {
analogWrite(led, brightness);

Posting in an area that CLEARLY says dont post questions will get you into trouble.

Moved your topic to a more suitable section.

You may want to READ THIS for future reference.
It will help you get the best out of the forum.

Bob.

A link to the data sheet of your mysterious board were very helpful.

We will need the specs for your dimming board.

AC dimming is DIFFERENT from dimming a simple LED and depending on the interface it usually requires different software.

[u]This page[/u] explains how a phase-controlled AC dimmer works.

The dimmer needs to find the AC zero-crossing so it knows when to trigger the TRIAC during each AC half-cycle. Normally, that’s done with an (isolated) input to the microprocessor, but it’s possible for that to be built-into the dimmer module and in that case the dimmer module may accept regular PWM as input.

There is an industrial dimming standard that uses 0-10V DC or 10V PWM (with the phase detection built-into the dimmer) and there is a DMX stage lighting standard, again with all of the dimming control/logic built into the lights.

Your mains operated LED units may not be suited to dimming, regardless of leading or trailing edge dimmers.

IDK what board you use, so I cant help with its code.

DVDdoug made a very good reply.
AC mains dimming is NO JOKE.
Take care not to kill yourself, watch where everything is touching, properly rectified mains voltage can go higher then effective mains AC, so don't blow up your bulb, always discharge HV capacitors after turn off, before you touch them using a resistor, or an incandescent filament bulb.

for your code to work, you could try rectifying the mains, and dimming it with analogout, using a HVmosfet in series with the bulb, operated by gate power supply of some sort, and an optocoupler instead of the board if the board dosen't accept standard pwm. If you don't know much about electronics, or if the bulb is not old school incandescent, disregard this.

If you want to build yourself a real one, I have seen this gentleman do it pretty terrific for dimming a heater without interrupt messing with everything. I think that the scheme he used may even be close to what you probably have if your board is based on this kind of design (probably is).

disregard the serial, the probe, and the pid, so make code 3 slim almost like code 1.
in main loop (code 3) on FireTriac1 = PowerMap[Pid_out], instead of Pid_out insert a variable and map it to the power map 0-255, that can be changed either by buttons or a potentiometer.
use a snuberless type triac for anything but resistive load (incandescent bulb).
figure out the principles, and tinker with it untill it works
best triac dimmer ever :slight_smile:
If you need just a simple thing, ask google about Arduino phase angle, there are plenty of in depths on this topic online.

There are various ready-made AC dimmer boards out there. That's the safest and easiest way to go.

Some require you to handle the zero crossing signal and the TRIAC triggering; others can read a PWM input signal and do this for you (those come with a small MCU on board).

Could an SSR be turned on and off like PWM?

GoForSmoke:
Could an SSR be turned on and off like PWM?

I don’t think so.
As far as I know many SSRs actually use zero detection to switch on at zero crossing, in order to make the switching as smooth as possible; phase cutting leads to power spikes. That alone makes PWM not work.

GoForSmoke:
Could an SSR be turned on and off like PWM?

you can use PWM but it must be at frequency of the AC and synchronized to zero-crossing.
on AVR I start the PWM and I reset the timer counter in zero-crossing interrupt.

const unsigned long AC_WAVE_MICROS = 10000; // at 50 Hz
const int TIMER_PRESCALER = 8;

void zeroCrossing() {
 TCNT1 = 0; // restart the timer
}

void triacSetup(byte zcPin, byte triacPin) {

 attachInterrupt(digitalPinToInterrupt(zcPin), zeroCrossing, RISING);

 pinMode(triacPin, OUTPUT);

 uint32_t topPeriod = ((F_CPU / 1000000)* (AC_WAVE_MICROS)) / TIMER_PRESCALER;
 ICR1 = topPeriod; // fast PWM with ICR as top = set WGM11, WGM12, WGM13
 TCCR1A = _BV(WGM11) | _BV(COM1A0) | _BV(COM1A1); // set OC1A on Compare Match HIGH
 TCCR1B = _BV(WGM12) | _BV(WGM13) | _BV(CS11); // prescaler 8
 OCR1A = topPeriod; // must be set here to have pin LOW on start
}

/*
* r is from interval <0.0, 1.0>
*/
void setPeriod(float r) {
 unsigned long period = ((F_CPU / 1000000) * ((1.0 - r) * AC_WAVE_MICROS)) / TIMER_PRESCALER;

 OCR1A = period;
}

on SAMD I use timer one-shot pulse started at interrupt by event system. so after setup() the CPU is not involved in Triac control

https://github.com/jandrassy/Regulator/blob/master/TriacLib/TriacLib.h

A sine wave dimmer with an IGBT in a full wave rectifier is independent from zero crossing, and makes a smooth output wave. The IGBT is designed for turning high voltage and current DC on and off, while thyristors and triacs only can be turned on, and will go off only if the current stops, near the next AC zero crossing.

I have seen house light dimmers work in the 70's, maybe a filter clips the wavetops...

GoForSmoke:
I have seen house light dimmers work in the 70's, maybe a filter clips the wavetops...

I had one in the 1970's. It was a small variac(variable transformer) that fit into a large metal outlet box in the wall.

Paul

I've built light dimmers in the 70's using a Triac with embedded Diac. A nice christmas gift for all my family members :slight_smile: