PDA

View Full Version : Detecting 240V with a PIC (Part2)



The Master
- 17th March 2009, 21:25
Hi, im doing some initial tests for this years halloween circuits (a little early yes but also well prepared). There were some good ideas in the previous thread (http://www.picbasic.co.uk/forum/showthread.php?t=9845) but i found something on the net that looks like it should do the job perfectly. Mains LED (http://www.marcspages.co.uk/tech/6103.htm).

My plan is to use the capacitor circuit with an optoisolator. Ive already tested the circuit with an LED and it works. Ive switched to an optoisolator and for some reason my PIC chip isnt seeing an input. I think this is likely to be a problem with the opto.

The opto im using is a MOC3020X (http://www.rapidonline.com/netalogue/specs/58-0870e.pdf). Im pretty sure the input side is fine. I think the opto might need some kind of a load (like a triac) to turn on. If im looking at the right part of the datasheet then that load is 30mA. I know a PIC probably doesnt take that much so i connected up a 60mA LED and it still doesnt work. Driving the opto from a normal 5V PSU doesnt seem to help either.

Where should i start looking for problems? Am i just using the wrong type of opto? Do i need more load?

Darrel Taylor
- 17th March 2009, 22:35
The Opto you're using has a Triac type output, which is meant to switch AC voltages.

You need one with a Transistor output, could be either NPN or PNP, but NPN is more common. Then with a pull-up resistor on the collector and the emitter to ground ... it should work.

The Master
- 17th March 2009, 22:47
Good idea thanks!

I found some transister ones in rapid. Some even have AC input so i can drop the diodes and they are cheaper anyway. They dont seem to have any datasheets so ill request those tomorrow and maybe buy a few of each type.

Thanks for your help :)

Melanie
- 18th March 2009, 08:32
Do a search for a K1010 (available from RS). Put a 1N4007 across it (in reverse to clamp the negative cycle because the reverse voltage will almost certainly exceed the opto's max rating and you're in danger of blowing it up). Feed that with a 270K Resistor (mains rated... the CR25 types are marginal here - unless you use say 2 x 150K - one in each input leg). Use a PIC pin with a pull-up (internal weak pull-ups are just fine) and set your software to detect the 50/60Hz AC pulses (no pulses - no mains).

PS... just in case anyone reading this is in a part of the world where they have toy voltages coming out of the wall, the above is good for 220-240vAC.

The Master
- 18th March 2009, 13:25
Melanie: I dont see a capacitor mentioned anywhere. Are you saying to use one of the original ideas from the other thread which uses only resistors? I did try that last year with a normal LED and it fried the resistor. This new capacitor method i found on the net works perfectly and seems to be fine for 100-400V.

EfkKIiE2: I get a 404 error when i try to view that link

Melanie
- 18th March 2009, 14:15
There are advantages and disadvantages to both methods, and both methods are equally valid in their use.

The Capacitor... doesn't generate heat, but costs 20x the price of a Resistor. You need to use an X2 grade because if it fails, it will take out the protection Diode and the Opto.

The Resistor... is far smaller and a lot cheaper, but it's entire raison d'entre is to dump heat into the planet, so it may not be the most appropriate component to use if for example you're planning to use a sealed unvented box. At 240V, you're going to have to deal with around 0.2W being wasted. Now, you have two dozen opto channels monitoring two dozen mains Fuses, and you suddenly have a fair amount of heat being generated.

The Master
- 18th March 2009, 18:29
I think i had better stick with the capacitor then. For a start ive actually got the capacitor to work with an LED while the resistor only blew up. The capacitor circuit does use a resistor too and the website i got the circuit from says that resistor acts like a kind of fuse. The whole circuit will be inside an IEC plug so yes, it will be a small enclosed space. I was also thinking of putting some kind of glue or silicon stuff over the whole thing but ill decide on that later.

The capacitor i was using costs 9p. If i buy 100 of them then its down to 6.8p. I guess thats not so bad. Its not like i plan to sell thousands of them where every penny counts. I was hoping to have another capacitor anyway to keep the opto on during the zero crossover. Compared to the rest of the circuit 9p is nothing.

Melanie
- 18th March 2009, 19:10
> the website i got the circuit from says that resistor acts like a kind of fuse

Well, if you know your X2's then you'll realise that it has a Fuseable Resistor inside it already... that's the bit that makes it fail-safe.