Detecting 240V with a PIC (Part2)


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default Detecting 240V with a PIC (Part2)

    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 but i found something on the net that looks like it should do the job perfectly. Mains LED.

    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. 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?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    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.
    DT

  3. #3
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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.

  7. #7
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default

    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.

  8. #8
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    > 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.

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. HSERIN & Interupts (aka controlling PIC programs from a remote PC)
    By HankMcSpank in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th June 2009, 14:46
  3. Detect 240V with a PIC
    By The Master in forum Off Topic
    Replies: 48
    Last Post: - 28th October 2008, 20:21
  4. pic to pic ir link versus wired link : help please anyone
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 30th May 2008, 21:01
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts