Rectifying 240V AC to PWM power to lights

BrendanP

Senior Member
I went for a drive today to see about getting some pekin bantams for my girlfriend. She's got quite a few already but there's a woman up here in Queensland who has really good birds. Anyway while I was there she asked me if I wanted a incubator. I got it home and have powered it up and it runs ok. It has the old style thermostat and I was thinking about replacing it with a picaxe/DS18B20 combo.

I did a bit of searching on the archives and came across some posts where guys were making temp controlled composite curing boxes. They had been advised to use PWM to soft start the globes and to prevent temp oscillations.

I'll use the incandescent globes that are already in the box to as heaters. Its already fan forced.

If Im going to PWM the supply to the globes I need to rectify the ac to dc. (Correct me if Im wrong on this)
Can I run normal garden variety light globes on 240V dc?
 

Andrew Cowan

Senior Member
I don't think you do need to convert the AC to DC.

AC power is a sine wave that crosses the neutral point 50 times per second (in the UK, anyway). If you disconnect the circuit for one out of 50 cycles, you will have 1/50 of the power.

Light dimmer switches use triacs to do this - they latch and unlatch when the signal is at neutral. Driving motors requires zero volts crossover to ensure the pulses are smooth and even.

For a light, the pulses don't need to be perfectly smooth (as for a motor), so you could probably get away with just sending a PWM signal directly into a solid state relay (SSR).

Possibly using quite a slow PWM - 100Hz?

http://www.picaxeforum.co.uk/showthread.php?t=7594&highlight=pwm+240v

A
 
Last edited:

hippy

Ex-Staff (retired)
To control AC one uses a form of PWM but it's not free-running PWM, it's a PWM synchronised to the mains cycle cross-over, one common term for this is "phase angle control".

When the mains crossover is detected the mains signal is switched to pass through to the load some time later, the amount of mains passed ( how soon it is switched through ) determines how bright a controlled bulb gets.

A more complicated version switches the mains through and then off again, centred about the peak of the mains half-cycles. One consequence of any switching partial half-cycles is that there can be considerable electo magnetic interferance and also considerable audible noise from the filters used to supress that with high loads.

Another technique is to switch whole mains cycles through ( one cycle passes through, the next cycle doesn't etc ), though this can quickly lead to flickering and passing only half cycles is not ideal.
 

BCJKiwi

Senior Member
Since this is an incubator, the objective is heat rather than light so an SSR turned on/off for varying portions of say a 15 or 30 sec interval would be sufficient. There should be sufficient thermal mass/insulation in the box to maintain a reasonably steady temp.
 

QuIcK

Senior Member
attatch a servo to a standard light dimming switch (domestic wall mount ones). nice, quick, easy and safe.
http://www.hoelscher-hi.de/hendrik/english/dimmer.htm#power units
has some info on a "power pack" (dimmer pack)
you can get extremely cheap analogue controlled dimmer packs, used for theatre etc, then use a DAC with an op-amp to provide them with 0-10vDC control signal (you may be able to get 5v ones, cutting out the op-amp)
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en025234
has some more info, and some nice explanations
 

BrendanP

Senior Member
Thanks guys.
Whilst chickens (my girlfriends) are fairly easy to hatch, waterfowl (my birds) like geese and swans require more accurate temp control to get a good hatch rate.

I'd add humidity control for them too. Thats straight forward. There was a sil chip article on a humidity system for incubators using picaxe a while ago.

With the readtemp12 command I could very fine temp readout. A bit of good coding should allow me to hold the temp virtually spot on as long as I can control the globes/heater elements in small increments.

I've looked at all the links provided. I don't want to get too bogged down in the project. The wall dimmer switch-servo hack has merit. I have both already so thats possible if need be.

I also searched for serially controlled light dimmers. I thought there might be modules availiable that I could picaxe control. Closest I found are these.

http://www.velleman.be/downloads/0/velleman_dimmer_selection.pdf

I also came across some old forum posts that google had picked up re. these kits/devices.

I have had only passing involvement with velleman kits. Can anyone report/comment on these kits specificaly or Velleman in general?
 

premelec

Senior Member
I built a 4 channel unit many years ago [run by Basic Stamp I unit PWM] using 4 Velleman 8028 units - they still work fine and the quality of the kits is good... mine are running on 120VAC 60Hz in USA... I used a capacitor filter setup to smooth out the PWM to a varying DC voltage to drive the 8028 units... should work out fine...
 

BrendanP

Senior Member
Thanks Prem, is the cap filter set up critical to use? If so can you explain it a little more about its set up please.
 
Last edited:

premelec

Senior Member
My use is for fairly fast changing lights display - in your case that's not going to be an issue so probably you can use simple filtering on the Velleman DC input - I don't remember just what the Velleman input impedance is - I'll have to dig up the schematic. There are a couple of pots to set up the Velleman units sensitivity - so you can trim things up with them too. I'll find the schematic. If you are only using one channel you can use PWMOUT which runs constantly - I used bursts of PWM on 4 different outputs and needed more smoothing to avoid noticeable flicker.... Subsequently I've built 8 channel units with phase control and current control setups using TI 8 channel D/A converters which are set and forget outputs...
Much less trouble... the D/A outputs set LED currents or incandescent phase triggering [using a sawtooth reference 120Hz and TRIAC opto iso units...]... anyhow I need to look up the Velleman input - report later...

I just looked up my old file folder 1998 - I used Velleman K2003 units which apparently, from list referenced, are not available now -
They were about $20USD each - they show an opto isolator input directly through a resistor... The K8028 is one I'd bought for a different use... in any case the Velleman units are well done,in my opinion, and should work ok for you - a 10K resistor into a 100uF capacitor across input input is where I'd start - and don't forget to isolate high current spikes from itty bitty PIXACE! Hope this all helps some - I think you are on a right track...

Note that you could also use the PICAXE to vary an LED shining on an LDR patched across a potentiometer in a commercial light dimmer... if you want to fool around... the LED --> LDR make for good electrical isolation and are simple IF you have the parts...
 
Last edited:

BrendanP

Senior Member
Thanks prem, much appreciated. The LED/LDR is nice idea, I have a few LDR's in the parts box. I might go get a dimmer switch and do a bit of hacking.

I need to make two units, the chicks make a real mess when they hatch so its good to have one unit with automatic turning which entails a grid and actuator and another unit where you put the eggs for the last couple of days that is used only for hatching. As it doesn't have any turning mechanism the inside is much easier to clean.
 

MPep

Senior Member
I recall SiliconChip having an article on just this subject, or very similar. In the early days of PICAXE. Check in your local library. I cannot remember the edition however. Sorry.
 

BrendanP

Senior Member
Prem you're a legend!

After the previous post I went down the hardware and bought a dimmer switch. It was $47 au which is a lash in my view. Anyway this is a small town so they had me in a corner. Its a HPM au made unit p/n D300EWE.

I got it home was pleasantly surprised to find that it came apart easily. Theres a couple of clip tabs that hold the back on, you push those in with a screw driver and the back comes off. You pull the knob off the splined shaft on the front and the pcb slides out into your hand.

Theres a pot on the front, I put the meter on it and found its R varied between 0 and 200K.
I got a LDR out of my parts store and found that its R varied between 0 and a bit under 200K. I began to smell victory in the air like Colonel Kilgore.

I cliped through the three legs holding the variable R onto the pcb and soldered on the LDR in its place. I connected it up to the two lights in the incubator and fired it up. AND IT ACTUALLY WORKS! It controls the lights like perfectly according to how much light it gets.

Im going to hook up a LED under pwm now. This is one hack that is a good 'un. Im very impressed.

Usual caveat applies, your playing with lethal voltages so make sure you know what you're doing, or prepared to wear the consequences if you don't. (maybe death........)
 

BeanieBots

Moderator
This might be one of the very few occaisions when you might need to apply some smoothing to the PWM that drives the LED.
LDRs have a fairly slow response but when compared to AC mains, probably not slow enough.
If it works, great.
If you get lots of flicker and/or beat frequencies, then add some capacitance across the LED.
 

Dippy

Moderator
And maybe have a nice high PWM F?
I don't suppose PWM resolution is hugely important here.

I used one of those Silonex NSL-32 opto-resistive couplers in Simple Switcher circuit and I did have to RC the LED side. It suffered quite a lot from temp-related drift, but maybe for an incubator that won't be a problem as the 'system' doesn't need to be fast.
 

BrendanP

Senior Member
Thanks BB. It seems to be going OK.

I found a white ultrabright LED in the parts boxes and connected it up. I had to put a 20K R in series with it to dim it down enough because even with pwm at a low rate it was generating too much light and the 240V lights were coming on brightly even under a slow pwm rate. Now its working well. They comeon very faintly and slowly get brighter and then fade again. I've got the pwm rate in a for...next loop.

I've got the LED held closely against the LDR with some black insulation tape.

I'll play around with it some more and establish the minimum pwm rate to start illuminating the 240 globes. That will be the minimum setting to get max life out of the bulbs.

I'll have a think about some coding in the next few days that will be best be able to to hold the temp stable with out over/under shooting. Some thing that will ramp the lights up the most the further away the set temp the current temp is and then taper off the closer it gets to 37.5C. I suppose the smart thing to do would be to add a external DS18B20 so if the piacxe sees the outside temp suddenly drop (window open in room etc.) it would immediately begin to creep up the lamp output in anticipation of the internal temp of the incubator start to decline.
 
Last edited:

QuIcK

Senior Member
so the bog-standard light dimming switch you bought from a local hardware shop was just a big variable resistor?!
or did you take the pot off the rest of the dimming circuit?
 

Dippy

Moderator
It won't be just a big pot Quick. That would be asking for trouble.

I really don't think an LDR on its own could handle a 240V light bulb :)

It would be controlling an AC switching circuit.

Have a Google and look at the zillions of designs for dimming (or power control) circuits - then you'll see the general design methods - and chips available too.
 

premelec

Senior Member
LDR voltages...

The voltages LDRs can handle go from hundreds to tens so DO be careful in your testing and make sure the LDR will stand up ok... the big LDRs on street light heads are higher voltages and the tiny ones in garden lights are lower... My impression, from seeing street lights on all day is that the LDR fails at high resistance - but I don't know for sure... in any case you should rig a good old thermostat to give you warning if something fails... boiled eggs and roast chicken aren't what you want at this stage!
 

ad8bc

New Member
I just reverse-engineered a PIC board that I bought about 10 years ago to control a pedestrian traffic light that I turned into a table lamp (http://www.trafficlights.com/T2ad.htm and http://www.trafficlights.com/images/p2photo.GIF). The board runs on what looks like an 8 pin PIC (the pinout matches, anyway). The mains AC (120V here) is rectified with a bridge rectifier made of four 1N4004 diodes, and the 5 volts for the chip is regulated with a 33K resistor and a 5 volt Zener diode. The PIC outputs each go into the gate of a U43 mosfet which switches the 0VDC to a standard 120V light bulb which gets it's hot from the rectified 120VDC. Anyway, my whole point is that the standard household light bulb that normally runs on 120VAC is now running at 120VDC. And, since that DC voltage lights the bulb just fine, I am sure you could PWM that output to control the brightness.
 
Last edited:

BrendanP

Senior Member
No the dimmer switch is not a big variable R. This is Australia, not Burkina Faso.

Part is here:

http://www.walkershardware.com.au/showProduct/Electrical/Electrical+Switches/10510188/DIMMER+HPM+WHITE+300VA+#D300EWE


The trim pot is what you turn when you rotate the knob on the wall. There's a couple of Q's, a big cap, a inductor, a heat sunk triac (9?),several smd caps and r's on the pcb as well. I removed the pot and put a LDR in its place.

I'll put a alarm on the incubator in case of over/under temp problems. Maybe a GSM interface to sms in case of either, depends how much time I have to put into it.
 
Last edited:

BrendanP

Senior Member
I thought my explanation of what I had done was pretty detailed and straight forward.

I dare say that if it had been Dippy's post that Quick had been replying to/commenting on he might of received a somewhat more "colourful" reply.

Take care if you have a crack at the mod Quick. Theres traps in the game for young players.

Thanks ad8bc, I suspected it might be possible to light a normal globe with DC.
 
Last edited:

premelec

Senior Member
Sounds like you've got it all well controlled - just want to add a comment about DC - harder to have an isolated control and triacs [and solid state relays] don't turn off as there's no zero crossing - the other thing about high voltage or current DC is arcing - with AC there's time on the zero crossings to extringuish an arc - with DC once an arc strikes it tends to sustain till something melts [in my experience it was circuit breakers... :) ].
 

ad8bc

New Member
I suppose I should have made a comment about safety when I wrote my piece.

I had had that traffic signal curcuit board for about 11 years, and on Saturday I drew out the schematic by tracing out the PC board, I reverse engineered it because I wanted first to see if it was actually an 8 pin PIC (the manufacturer had ground off any identification fromt he chip), second I wanted to figure out how they controlled the outputs (turned out to be those MOSFETs controlling DC) and third I wanted to see how they powered the control circuits with no transformer and voltage regulator...

...I suppose in the back of my mind I always knew you could rectify the mains voltage and use a 5V zener diode and a large resistor (may need a larger one for the 230V you use) for your 5VDC control voltage, I just never thought about it since I enjoy building power supplies so much, and when I don't build my own, I use one of the (many) spare wall-warts I have collected over the years. As I get into the PICs, maybe I'll start using this power supply method more.

The rectified 120VDC output to the lamps was an angle that I didn't think of until seeing it. However, that sort of output may not work well with those silly little fluoroescent bulbs with an AC ballast, or with 120V LED bulbs (depending on if the internal power supply can handle the DC, if it has a bridge rectifier it probably could).

Be careful when playing with AC and whatever you do don't breadboard with mains power (voice of experience here...). By all means simulate your circuit at the DC level, but when done with the simulation build yourself some sort of stripboard or PC board and try to keep your high and low voltage separated as much as possible, Premelec's warning about DC arcing is also true.

What I like to do when working on AC projects that are not yet enclosed (for tweaking purposes) is to use an isolation transformer between the mains and the circuit board. This way, neither leg of your AC circuit has any respect for the ground you are standing on and you will only get shocked if you touch both legs in your circuit.

Also, I got to thinking of swiching that incandescent output with PWM. Your mileage may vary on that since the filamant does not immediately stop glowing when you turn off power. You may need to play with it, it may not be a linear relationship between actual light output and PWM frequency. Or it may be, I've never tried PWMing an incandescent light bulb. Let us know if and how it works for you!
 

hippy

Ex-Staff (retired)
I suppose in the back of my mind I always knew you could rectify the mains voltage and use a 5V zener diode and a large resistor
It's one way to do it but not recommended, even drawing just 10mA the resistor is dumping 2.5W and is just throwing energy away as heat. The preferred way is to use a suitable capacitor which has a high impedance at mains frequency.

As always - Direct mains supplies are not something experiment with unless suitably experienced and knowledgeable.
 

ad8bc

New Member
Agreed on the safety point.

I work almost every day with 480V 3 phase systems so I know the safety protocols. And I fear it every day. The day you stop fearing electricity is the day you should retire.

That being said, I don't want to discourage people from doing so. But I want them to know what they are doing first!
 

premelec

Senior Member
Hippy... the series capacitor has some serious drawbacks - when you get high frequency spikes on the line they see much lower impedance thence higher current to device or diodes - I've recently seen failures in commercial 6 LED light strips that had only series capacitance to reduce current - putting some resistance in series with the capacitor helps - especially if you use a resistor which will burn up without flaming if the capacitor shorts out :) . I've seen failures in solid state timer units also which used only the capacitor in series - I guess it turns out there a lot more spike activity on power lines than we'd like to admit.... a compromise resistor capacitor combination can work pretty well...
 

Dippy

Moderator
I post this with a little reluctance (no pun intended).

But I feel that if we are going to mess about with circuits for Mains then we should have something that works - when made correctly.

It is a general Mains to 5V circuit.

This circuit will be at MAINS voltage - it DOES NOT operate like a nice bench PSU or wall-wart. Do NOT use breadboard to make this circuit and I cringe even if novices consider using stripboard.

There are a number of notes concerning SAFETY.
1. The 'Ground' is NOT a safe 'Zero' volts. It is merely a ground for your circuit - which will almost certainly be at a HIGH and DANGEROUS voltage.
IF you made a PICAXE circuit using this circuit then DO NOT directly connect a cable to your PC. And DO NOT put your finger on it.
This circuit will be at lethal voltages - you WILL need proper opto-isolation to connect to a PC or any other circuit powered by a wall-wart or bench PSU.

2. IMPORTANT: The capacitors MUST BE be of the High Voltage types - look up X1/X2 Y1/Y2 type capacitors @ 400 to 1000V ratings.
DO NOT use 'any old' capacitors.

3. The MOV is to absorb Mains surges - recommend a 140J value. Volts depends on your AC supply.

Typical Values.
C16 would be typically 10nF (or less) rated at 400V(or greater pref.).
A value of 470nF (400V or greater pref.) for C17 would provide a few tens of mA.
D3 typically a 1W (or greater) @ 15V zener.
D2 typically a standard 1N4004.
C18 would be a low-Z 220uF/35V
Z1 & Z2 usally a couple of ferrite beads.

This circuit should NOT be used by novices without qualified Adult supervision.
ANYONE who is concerned by using a circuit like this should NOT even attempt it.
Get it wrong and it could be your last mistake - and I mean that SERIOUSLY.
Schoolkids , novices and smartasses - forget it.

Oh, add a suitable fuse in a suitable fuseholder too!

SORRY, I forgot.
If you use the 5V regulator, then add a 10uF/10V cap //d with 100nF ceramic.
The 'ground' side of the caps should be connected to the 'analogue' ground which is to the right of Z2.

Here it is...
 

Attachments

Last edited:

BeanieBots

Moderator
Isn't it illegal (in the UK at least) to have a deliberate path between line and gnd as shown on your diagram?

Z2 between neutral and gnd???

Other than the legal issues. Circuit should be fine with the caveats stipulated.
 

Dippy

Moderator
Not sure if we're at slight cross-purposes here and it can depend on app.

In my app Neutral is connected to Z1.
Live is connected to the 'ground' line of this circuit.
The ground is merely a reference , not an 'earth' type ground.
Hence the whole thing (and subsequent circuit) will be sitting at Mains voltage +/- a bit.

Hence my stressing of the dangers and the absolute necessity of opto-isolation if connecting to another circuit board powered by a wall-wart or Bench PSU or even a 'scope.


Z2 is the link between noisy digital ground and 'analogue' ground as used in Energy Metering.
Any subsequent 'analogue' AVdd should be connected via an RCRC circuit physically well away from the DVdd and Digital Ground.
Again, these are simple references used in energy monitoring designs.
Digital ground (by def) is to left of Z2 and 'analogue' gnd to the right. Its just a noise and definition thing.
 

Dippy

Moderator
ILLEGAL?

If you consider the circuit to be illegal, I reckon you should contact Microchip and Analog Devices which use this basic circuit in their Energy Metering products :)
 

BeanieBots

Moderator
I'm sure your intention is correct but maybe the use of the 'earth' symbol is misleading. Nicely demonstrates the caveat of "only if you know what you are doing".
I'm sure somebody will see that symbol and think (in the interests of safety) to connect it to earth. (then wonder why the ELB trips).

EDIT:
Intentional (unbalanced) current path between line and earth is illegal in the UK.
Maybe it's not in the US?
 
Last edited:

Dippy

Moderator
Yes, you're right to point that out.

To clarify therefore:-

The Ground/Earth symbol is the 'digital' (noisy) ground on your circuit. NOT mains earth. NOT Ground/earth of a PSU. NOT the ground of a PC or 'scope.

The Triangle Ground symbol (aka 'signal ground') is defined as the less noisy 'analogue' earth.

DO NOT connect either of these two 'grounds' to Earth/ground on any device you have in the house. It is a 'zero' reference level for use within that circuit ONLY.

I did actually mention the dangerous voltages at these two 'Grounds' and emphasized they are references, I hope it is now cleared up.

I should point out that these are the conventions shown in the Data Sheets from Microchip, Ananlog Devices and ST Microelectronics and Cirrus. Maybe they make some assumptions about their readership ;)
However, I'm not cricticizing the extra clarity - especially here.
 

Dippy

Moderator
"Intentional (unbalanced) current path between line and earth is illegal in the UK."

- there is no connection to 'mains' earth!!

The ONLY connections are to Live(Phase) and Neutral.
Don't confuse the circuits 'ground' with your plug-on-the-wall Ground/Earth.

Those energy meter designs are for use in US and Europe and UK.
 

Dippy

Moderator
As just pointed out by BB, the previously posted circuit could be considered ambiguous by inexperienced users.

Refer to original post for warnings etc.

I've changed it a bit for clarity.


NOTES.
This circuit operates at high (potentially lethal) voltages and should be treated with great care.
It should NOT be attempted by novices unless supervised by someone suitably experienced.
There must be NO direct connections to Mains Earths or equipment Earths or grounds.
If this circuit is used to power a PICAXE circuit then the PICAXE to PC connection MUST be safely isolated - either opto or other safe method.
Any connections from this circuit to another circuit powered by another supply must be isolated.
All components used MUST have a suitable rating.




There are 2 versions - Type A and Type B - basically reversed

Type A.
This connection is used for Energy metering chips and other circuits where the mains voltage is connected to a PIC pin.
In this way the Live becomes the 'ground reference' , thus LIVE connection to PIC pin will be seen as 'ground'.
For example an Energy metering i.c. using a 'Shunt' for current sensing.
In any event, only use this method if the chip/circuit Data Sheet says you can.
If in ANY doubt then don't do it. If it confuses you then don't do it.


Type B.
Is a general purpose connection for low power circuits where there is no other Live connection within the circuit.


Neither of these circuits are isolated and therefore should be treated like a High Voltage and potentially lethal device.

Safety and care should NOT be treated lightly.
If you don't understand the above notes then you should NOT attempt the circuit.
In all honesty, unless you are experienced and understand the risks then I recommend you DO NOT try it.

I am posting this as an example working circuit for experienced users - it is NOT a 'safe' general purpose PSU that replaces a wall-wart or other Bench PSU.
It should only be used as a building block for a mains powered circuit that is isolated electrically from the outside world.

There are other variations on this theme - each may have advantages.

Use entirely at your own risk. I'm not encouraging anyone to build it. E&OE :)
I'm sure there are plenty of circuits on the NerdyNet or in books that can kill you. This one is no exception and could injure or kill the incompetent.
 

Attachments

ad8bc

New Member
Another important point to remember is the difference between "grounds".

You Europeans sometimes refer to "Safety Ground" as "Protective Earth" and that is probably a better name for it. That is the most important "ground".

The "signal ground" is what you would find in a low voltage circuit is usually the 0VDC reference point. Often times, that is NOT connected to "earth ground" and that's OK. But it is used in schematic diagrams as a "reference".

I wish I had an easy way to draw the proper symbols right now to put into this post but I don't.

Basic safety rules apply. Don't mess with mains voltage if you are new to electronics. But the point will come when you gain experience that you may need to mess with it. Be careful, don't touch under power, make sure your test leads are well insulated, use an isolation transformer for open-enclosure testing. Understand that it takes very little current to kill you. Learn and be cautious.
 

premelec

Senior Member
eureka! Commercial photocell units would work....

I woke up this morning realizing that I've missed the obvious - [back to the original problem - I digress :)].

There are integrated photocell light controllers which screw into a light socket and then the bulb is screwed into that with a photocell exposed out the side - these have very little delay in their action - this can be demonstrated by using a mirror to have the light dim itself from the reflected light from the lamp it's controlling...

I'm not sure how many watts are being controlled in the apparatus mentioned but I looked at a commercial compact photocell unit in my junk box and it says 150 watts incandescent is ok - and it's a cheap integrated weather resistant approved unit... add an LED and some black shielding and you have a controlled AC power source - which however is fail ON rather than fail OFF and more current to the LED means less to the lamp circuit... It would be easy to gang several of these units to one control by running all their LEDs to the same control signal... case solved... perhaps :)
 

Dippy

Moderator
Apologies. My fault for digression. I saw a long protracted and potentially very unsafe debate on this subject starting so I thought I'd chuck in one version of a proper circuit. Sadly, I started an even longer protracted debate, sorry.

Premelec: Glad its sorted.

ad8bc:
Yes, always confusion with international standards and yes, we can warn people forever can't we :)
I hope the notes clarified things a bit.
The original image was c'n'p from an Analog Devices Data Sheet.
Application Note AN-559 ; available to every 12 yo schoolboy in the world!
I assumed they use American International symbols.
Anyway, it works. Take it or leave it - and for most people I'd say leave it.
And I'll leave it at that.
End Digression // By me at least ;)
 
Top