Dimmer

cooldude4u2no

New Member
Hello Again Everyone!

Quick Question; Being a electrician and all I thought it would be fun to figure out how to turn household lighting on and off (120v) via PC using wireless communication. (I know its probaly not practical, but a learning experience none the least) Well i have accomplished that project. Using a 14M Picaxe, MOC3021 OptoCoupler, and a Q6015L5 Triac (These are 15A 600V Triacs)

My question now, Is it possible to use the picaxe to control the current lets say to make a dimmer switch? Ive read about 3 articles on dimming and i have Tried PWMOut going into the OptoCoupler (Controlling the internal LED of the OptoCoupler) and works to some degree but not like id expect, once the Duty gets so low the light will dim but has a annoying flicker.

Im just not sure what road to take here or if its even possible. Ive read that Ill need a OptoCoupler with Zero-Cross detection, i have five of em (MOC3041) but i cant even get it to work just on and off and not sure what other parts ill need.

Im just looking for some guidance and a pointing in the right direction.

Thanks!


Ouh, Can someone tell me the big difference in a MOC3020 and a MOC3021?
 
Last edited:

hippy

Ex-Staff (retired)
Current isn't controlled in most lamp dimmers, what's controlled is the amount of the sine wave mains which goes through the lamp; half the wave half the brightness. The triac is controlled so as to switch the mains to the bulb, how far through the mains cycle - and some circuits turn the wave off again having turned them on rather than waiting for the wave cycle to end.

The zero-crossover is used to synchronise the start of the wave to when you turn the triac on so each wave is the same as the one before. That's still called PWM but it's not free-running PWM, it's synchronised PWM.

The project is practical and I recall there was at least one project described on the forum which did this.

Usual disclaimer - Take care with mains, it can be lethal, steer well clear of it if not qualified or not suitable experienced.
 

boriz

Senior Member
“I know its probaly not practical”

How do you know that? I say you’re wrong. I say your premise is flawed. I say you are predicting failure and therefore anticipating it.

Dimmers work on phase synchronisation control. NOT current limiting. See: http://home.howstuffworks.com/dimmer-switch.htm

50 (or 60) Hz is fairly slow compared to the Picaxe, and it can probably easily cope with your dimming problem in several different ways.
 

Dippy

Moderator
I've just been doing something similar - albeit for controlling an induction motor using a PIC.

For lamp dimming you do NOT want a zero crossing triac driver if controlling using a micro. No to ZX opto-isolator/coupler.

You have 2 options for flicker-free (ish) operation.
1. Switch on at ZeroX and off at a certain threshold.
2. Switch on at a threshold and off at Zero Cross.
If you start switching on and off at ZX then you could end up with a lot of flicker. You don't want to switch whole cycles for lights, just parts of cycles with good consistency.

ZX is fine for Heaters of course, where it doesn't matter if it flickers :)

Using a PIC you can , potentially, get far better Zero Cross performance than many ZX opto-isolator chips anyway.

In the circuit design you have two basic options.
1. A transformerless PSU with the whole board at nasty volts. Makes programming testing difficult without isolation devices. Potential disater for novices. Advantage of simple transistor drive for Triac and no opto-iso needed as circuit is following the phase.
2. A transformer design. Bigger and more fiddly but safer. Non-ZX opto used. ZX detection done by PIC. Very fast ADCing required so I'm hoping that PICAXE is fast enough for consistent operation.

For a guide get Application Note AN958 from Microchip website. That'll give you a starter and a basis for a non-isolated schematic.
If you use this circuit then NEVER connect your programme cable or a 'normal' oscilloscope whilst the mains is connected.
If you do then something will explode. Be damned careful!!! Not for novices.
Note: AN958 is aimed at a heater so keep that in mind when reading through. But it does give some handy info on switching.

If can excuse the mess here is a quick schematic for a transformer version for prototype purposes. Apologies if there any typoes I did it a bit quickly.
It does mean that the programme cable can be connected without a special isolator circuit.
It shows an 18F25K20, but anything butch enough will be fine.
You will need a NON Zero-Cross Opto isolator for lighting.
And yes, it works, I did it the other day.
Sorry, code is not PICAXE BASIC.

And note that you may need to add a bit of snubbering/suppression too.
 

Attachments

Dippy

Moderator
"Ouh, Can someone tell me the big difference in a MOC3020 and a MOC3021?"
- 1. :)

Actually, I think it's just the trigger current.
 

hippy

Ex-Staff (retired)
Having worked on dimmer circuits which connect directly to the mains I'd say stay well clear of that in general and certainly for initial prototypes.

You should be able to work with a lower and safer AC voltage out of a transformer both for zero-crossover detection and switching a load from that lower voltage AC - if you even need to do the later, just looking at zero-crossover signals and triac firing pulses should be enough to start with and in getting the code to perform as it should. The later stage is getting the code to work with real world hardware.
 

Dippy

Moderator
For anyone totally new or inexperienced or unsupervised I'd agree to stay clear of mains stuff full-stop.
Headline: Don't do it. It could be lethal.

A transformered down AC is a very good idea.
Lower voltage and isolation - good idea.
However, you will have to make some adjustments for your PSU section.

Cooldude, however, says he's an electrician so I assume he has considerable experience with (and respect for) nasty voltages. So, I'm not going to patronise him or even be his nanny.

The code is fairly simple.
A loop or timer interrupt to perform a fast ADC.
Determine level and direction, therefore you know where you are on the phase. (and also detect ZX)
Another loop or timer interrupt to read the potentiometer or whatever.
Correlate your pot input to phase position.
(You may like to introduce smoothing or hysteresis here as an anti-noise filter).
read ADC fast over and over ... wait for it.. wait for it.... trigger.... sense Zx. Off.
Repeat.
 

Dippy

Moderator
LB: I think hippy might have wrong end of stick re: Triacs .

Just for the audience, a triac will allow current to pass until the half-cycle
is completed and then revert to the (nearly) 'off' state.
I say nearly off as it is a high impedance state and not 'OFF' like a mechanical switch.​

So, if you briefly trigger the triac anywhere on that phase it will complete the half-cycle phase conducting and then off.
If we know where zero is and set a time we can start that trigger anywhere on the phase.
So, sense ZX, delay,trigger-pulse and let it go. Repeat...
Some may actually sense the V value to derive the threshold V to set the trigger point instead.
Therefore you are controlling how much of the cycle you are letting through.
EMI filtering required strictly speaking.​

The trigger pulse can be very brief, maybe just a few mS. This is why you do NOT want a ZX opto. Your micro should be doing this.
If you use a non-isolated design you can use a transistor to trigger the triac and a transformered design needs an iso.​

 
Last edited:

hippy

Ex-Staff (retired)
Power MOSFET's and IGBT's apparently.

The theory in using a pulse which widens about the half-wave peak is it reduces EMI and 'magnetism' which stops the filter coils vibrating so much. Likewise turning on at crossover and turning off later. Audible noise from dimmer racks is a big problem in TV studios and for outside broadcast use in small rooms. The coils are also what usually makes dimmers so heavy.

More and an interesting idea on chopping the sine wave up here ...

http://www.tvtechnology.com/article/12058
 

Dippy

Moderator
Looks like Google got a pasting there, well done Sir :)

I had assumed as OP and hippy et al had mentioned triacs previously that we were talking triacs...
I have a feeling this is going to go off at a tangent so I'll wish you good luck.
 

hippy

Ex-Staff (retired)
I did work for 15 years producing stage lighting control software so it was more a throwaway comment that there are alternatives to triac circuits but triacs will work and are what most people will use.
 

boriz

Senior Member
Only if you programmed it :)

Oh, he's deleted it now. Ah well.
Are you by any chance referring to a post of mine? I assure you I deleted nothing, though Techincal has indeed done some appropriate pruning. I was posting while drunk as a skunk Thursday and can sometimes get a little belligerent on tequila. I can’t even remember what I posted. Though I have a complete record of the embarrassing emails I sent. Sorry if I upset anyone. :eek:
 

SAborn

Senior Member
I have not read the full thread here but has anyone surgested using a solid state relay as it is a lot easier, but might be a bit bulky.

SS relays are not over exspencive off fleabay.
 

Dippy

Moderator
Maybe he could, though he'd have to select the correct type.

Is that sort of stuff safe off Fleabay? Do you trust the markings on devices? Which vendors would you recommend?
Personally, I wouldn't even buy bog roll from Ebay or Alibaba, let alone something that could burn my house down.
There is SO much dodgy stuff sold (mainly from you-know-where) that it would be nice to have a list of reliable suppliers. Recommendations?

(I'll stick to the Big Boy distributors but there may be others that are tempted by Ebay).
 

MFB

Senior Member
One very safe way to drive mains devices from a PICAXE would be to use one of the many IR remote control power distribution systems that are available from Homebase etc. These products can be simple ON/OFF or dimmer types. Not sure what code the handheld remote transmitters employ but there is probably a good selection.
 

MFB

Senior Member
Yes, and I bet he rolls his own capacitors from old cardboard tubes, tin foil and paper.
 

geoff07

Senior Member
Velleman have PIC-based dimmer boards, both scr with a bridge (late start and ZX off) and mosfet (ZX start then off later). The former are for incandescent and wire transformers and the latter for electronic switch mode transformers, which like the start of the waveform to be intact apparently. Their manuals are online and would show you suitable isolated circuits, though not the code!

My own kitchen is now lit by MR16 leds switched by Picaxe. I did build in a PWM dimming function but the leds don't really like it.
 

Dippy

Moderator
Has cooldude lost interest?

Without experience or decent guidance maybe a kit like Velleman's is the safest option.
 
Top