Detect 240V with a PIC


Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 40 of 49
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default Detect 240V with a PIC

    Hi, Ive got some new smoke machines for halloween and the buttons use 240V. Ive got the control part sorted. Im using triacs. The light also runs on 240V. Is it possible to connect that into a PIC chip somehow so the PC can detect when the smoke machine is ready? I know it would be pretty stupid to connect it directly. I have some opto isolators that i use for controlling the triacs. Could i use a resistor and connect the 240V into the opto isolator?

  2. #2
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Most PIC pins have clamping diodes so (assuming you are using a pin with these diodes) you can connect it directly using a 10M resistor to limit the current.

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


    Did you find this post helpful? Yes | No

    Default

    Thats good. I need to order some more stuff from Rapid soon so ill add some of those resistors to the order. As its 240V i think i will still use an isolator just to be on the safe side.

    Thanx

  4. #4
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    In that case you won't need 10M resistors. Here's a circuit you can modify for your app...

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Question Are those LEDs actually LEDs or what?

    Quote Originally Posted by dhouston View Post
    Look at the LEDs on page 77 of that document
    Must've been an off day for the editors...

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


    Did you find this post helpful? Yes | No

    Default

    The circuit diagram in the PDF looks good. Nice and simple.

    How do i know what value resistors to use? Do i stick with 130K as shown in the diagram? I would have thought it varies for each type of optoisolator. I tried to calculate it based on the maths from a site macrakit linked to Designing LED lighting. I worked out that for my opto isolator the resistors should be 3K975. I think ive gone wrong somewhere because i wouldnt have thought it would vary that much. Im using a MOC3020M.

    I take it the diode is just to stop reverse voltage going into the optoisolator. Would it work the same if it was in series with it?

    I think im missing some of the document. skimask mentioned page 77 but all i see is a single page with a short writeup and a link to a PDF file. I dont see any kind of navigation for multiple pages either

  7. #7
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    How do i know what value resistors to use?
    Look at the datasheet for your optoisolator - there's an Absolute Maximum Ratings section with an entry for Continuous Forward Current. Ignoring the forward voltage drop of the LED, you need about 4000 ohms total for 60mA @ 240V. The lower values in the example probably factor in the forward voltage drop. In this case, you want the current to be near the max to improve the coupling. If using the PIC pin directly you can limit the current to much lower levels, hence the larger resistor I recommended.

    I take it the diode is just to stop reverse voltage going into the optoisolator. Would it work the same if it was in series with it?
    I would stay with the example or use an optoisolator designed for AC.

    I think im missing some of the document. skimask mentioned page 77 but all i see is a single page with a short writeup and a link to a PDF file. I dont see any kind of navigation for multiple pages either
    I don't see it either.

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


    Did you find this post helpful? Yes | No

    Default

    About 4,000 ohms is what i got. 3,975 taking into account the voltage drop of the opto. The confusion is because the example shows 130K resistors. Together thats 260,000 ohms. I work that out to be a voltage drop of 15,600 (i think)

  9. #9
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    They may also be taking into account that it's AC so the average current can be a bit higher as it's not steady state (i.e. continuous).

  10. #10
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    The circuit diagram in the PDF looks good. Nice and simple.
    Nice....except it'll never work!!!

    I think im missing some of the document. skimask mentioned page 77 but all i see is a single page with a short writeup and a link to a PDF file. I dont see any kind of navigation for multiple pages either
    That page 77 doesn't have Page 77 marked on it, but it is between page 76 and page 78.

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


    Did you find this post helpful? Yes | No

    Default

    Why wont that circuit work?

    I dont get the page 77 thing. I only see 3 paragraphs on that page.

    Maybe i should just go with the direct to PIC chip idea. The only problem i have there is that i will be fiddling with this a lot and i have a habit of forgetting to turn the power off first (Ouch :P)

  12. #12
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Why wont that circuit work?
    I dont get the page 77 thing. I only see 3 paragraphs on that page.
    Sorry, forgot to mention, you have to open up the PDF link under the article itself.

  13. #13
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    He is talking about this

    Name:  temp1.jpg
Views: 1925
Size:  71.8 KB
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    Ahh, I see. I thought i clicked that link earlier but i must have only clicked the one in the text. That string of LEDs does look incredibly usefull! :P

  15. #15
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Ahh, I see. I thought i clicked that link earlier but i must have only clicked the one in the text. That string of LEDs does look incredibly usefull! :P
    Maybe that's why they need the boost-drive...to overcome the reverse voltage...
    Heck, for all I know, those are actually LEZDs...Light Emitting Zener Diodes

  16. #16
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    He is talking about this

    Attachment 2922
    Which has absolutely nothing to do with the topic nor with the article I cited.

  17. #17
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dhouston View Post
    Which has absolutely nothing to do with the topic nor with the article I cited.
    You're right. Sorry.
    On my screen, after opening the PDF, the LED booster came up first. I had to scroll UP to see the voltage monitor circuit.

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


    Did you find this post helpful? Yes | No

    Default

    Im going to get components to try both methods just incase one fails. How do i work out the wattage i need for the 10M resistor method? I can use the maths from that LED page to work it out for the opto but i dont know about the PIC. I assume the PIC counts as some kind of load but only a small one

  19. #19
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    240 (E) / 10000000 (R) = 0.000024 (I)
    0.000024 * 0.000024 = 0.000000000576 (I squared)
    0.000000000576 * 10000000 = 0.00576 watts (I squared * R)
    or
    240 * 0.000024 = 0.00576 watts (I * E)

    The clamping diodes will conduct when the voltage is > Vdd (+ diode drop) and when the voltage is < Vss (- diode drop) so, in essence, you have the resistor in series with a diode with 240V applied. The above calculations have ignored the forward voltage drop of the diodes as that's insignificant in comparison to 240V.
    Last edited by dhouston; - 23rd October 2008 at 15:04.

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


    Did you find this post helpful? Yes | No

    Default

    Ive just realised that skimask has already given me the formula for that.

    E = IR, P = EI, therefore P = IIR
    I should have realised but i was thinking of the formulas on the LED page. They also use ohms law so it must be the same kind of thing but as i understand it they work out the wattage based on the current required by the LEDs.

    Im gonna read through all 3 ways of doing it again and see if i can understand exactly whats happening in all of them. I can see that the one you just gave me and the one skimask gave me are practically the same just written a little different.

  21. #21
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Ive just realised that skimask has already given me the formula for that.
    I did? Oh boy...shouldn't have done that... Well, the damage is done... Pass it along when you get the chance

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


    Did you find this post helpful? Yes | No

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


    Did you find this post helpful? Yes | No

    Default

    Hi, my 10M resistors arrived today. Just before i blow myself up (or even worse another PIC :P) i wanna be sure what im doing. Ive looked in the datasheet for my PIC and the only mention of "clamp" is input/output clamp current which is 20mA. Does that mean it has those clamping diodes or is that something else?

    To connect it up am i right in thinking that the neutral wire connects to VSS and the live wire connects through the resistor into an input pin and thats all there is to it?

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Just before i blow myself up
    Exactly how much before?

    Seriously...I was just thinking...and about something safe too.
    Couldn't you wrap a few turns of wire around the power line and look for a bit of voltage induced into that wire? Run that thru a diode and read that wire with the PIC?

    Sounds a lot safer than what you are planning on attempting now anyways...

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


    Did you find this post helpful? Yes | No

    Default

    Wouldnt that need a load on the end of the wire? The wire goes from the smoke machine then straight into the circuit

  26. #26
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Wouldnt that need a load on the end of the wire? The wire goes from the smoke machine then straight into the circuit
    Never tried it...but...if my thinking is right...
    A coil of wire around the power cord itself (around, not touching...), a high value resistor in series with the coil, one side of the resistor to ground, one side of the resistor to the PIC pin. The resistor should show a voltage across it if there is current flowing thru the power cord. You'll probably have to put a diode inline with the PIC pin and maybe a small R/C network behind that to filter out the 50hz half-wave and get a decent reading at the PIC.
    Unless my thinking is really jacked up (entirely possible), it should work... Not sure how many turns you'd need, might be 10, might be 1K...

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


    Did you find this post helpful? Yes | No

    Default

    That sounds a little complicated. Anything upto 1000 turns :O Ive got to do this 3 times too. I think the 50Hz part will be a problem with every method.

    It would be best if i could do the opto way. Problem is i think i need something daft like 20W resistors for it

  28. #28
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    You said something about a ready light? There is half of the opto-coupler. A photo diode is the other half.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    I wish id have thought of that. I dont have any photo diodes or anything else to sense light. Those ready lights wernt going to be connected. The idea is that the PC can display all that. It wouldnt be hard to connect them back up though.

    I guess if i dont connect it to the PC and just use the origional lights then it wont be a problem. I do have a future project that will use this type of thing though so i wanted to get it right now.

    Ive just connected a transistor up to the mains through a 10M resistor and with a diode across it plus a 100K grounding resistor for the base. It seems to be working perfectly. The LED turns on when the mains is turned on. Ive had it running the whole time ive been writing this post and nothing is smoking so it seems this method will probably work. Just incase, i do have a stack of spare PIC16F877As

  30. #30
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Just incase, i do have a stack of spare PIC16F877As
    What about a fire extinguisher near by?
    Dave
    Always wear safety glasses while programming.

  31. #31
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    That sounds a little complicated. Anything upto 1000 turns :O Ive got to do this 3 times too. I think the 50Hz part will be a problem with every method.

    It would be best if i could do the opto way. Problem is i think i need something daft like 20W resistors for it
    Shouldn't take a 1000 turns to do what I'm thinking. I would think maybe 10 or 20 would handle it just fine. 50hz shouldn't be a problem either.
    All you're doing is making a 'transformer' of a sort, tapping into the expanding/contracting alternating magnetic field that naturally surrounds a wire that is carrying a current, inducing a current into that coil, and developing a small voltage across a high value resistor which is the load for that coil.

  32. #32
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi, Master

    may be there's your idea here ...


    Alain
    Attached Images Attached Images
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  33. #33
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    Hi, my 10M resistors arrived today. Just before i blow myself up (or even worse another PIC :P) i wanna be sure what im doing. Ive looked in the datasheet for my PIC and the only mention of "clamp" is input/output clamp current which is 20mA. Does that mean it has those clamping diodes or is that something else?
    What PIC? What pin? The datasheets have diagrams of all the inputs showing the clamping diodes. For example, the 12F683 datasheet section 4.2.5 PIN DESCRIPTIONS AND DIAGRAMS has block diagrams of each pin. All but GP3 have clamping diodes to Vdd & Vss. GP3 only has one to Vss. Every datasheet I've ever seen has a similar section. You can also look at Microchip AN236 to see how they detect ZC in an X-10 application.

    If you are concerned about the high voltage then your best bet is to use a wall transformer type of DC power supply. It will give you an isolated DC output of whatever voltage you wish.

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


    Did you find this post helpful? Yes | No

    Default

    mackrackit, I have a glass of water here that i was using to test the water sensor.

    skimask, The problem with 50Hz or any oscillating input is that the PIC detects multiple inputs. Im sure its easy enough to program around that but ive not got that far yet

    Acetronics, that looks just slightly complicated. I dont think ive got half the components in that diagram anyway

    dhouston, Its a PIC16F877A. Doesnt really matter much about which pin. I guess it wouldnt hurt to add diodes in myself just to be sure. I did a search for "clamp" in the datasheet so thats why i didnt find anything. "clamp" wont find a diagram

  35. #35
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    mackrackit, I have a glass of water here that i was using to test the water sensor.
    For an electrical fire ?

    skimask, The problem with 50Hz or any oscillating input is that the PIC detects multiple inputs. Im sure its easy enough to program around that but ive not got that far yet
    Rectifiers do not care...do they?
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    That was a joke by the way! I probs should get a fire extinguisher though with some of the things i do.

    My point with 50Hz is that the PIC thinks the smoke machine is ready then not ready 100 times a second. Ive been thinking about the code for that and it should be really easy. Just a variable that counts down to 0 from whatever value (i havnt worked that out yet). If it gets to 0 then there is no power, otherwise the input will turn on again before it reaches 0 and reset the variable to its start value

  37. #37
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    My point with 50Hz is that the PIC thinks the smoke machine is ready then not ready 100 times a second.
    Ahh...
    But what if there was a capacitor across that PIC and ground along with a high-ish value resistor to bleed that charge off the capacitor?
    Anything click yet?

  38. #38
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by The Master View Post
    That was a joke by the way! I probs should get a fire extinguisher though with some of the things i do.
    And safety glasses. I always wear them when I write code.
    My point with 50Hz is that the PIC thinks the smoke machine is ready then not ready 100 times a second. Ive been thinking about the code for that and it should be really easy. Just a variable that counts down to 0 from whatever value (i havnt worked that out yet). If it gets to 0 then there is no power, otherwise the input will turn on again before it reaches 0 and reset the variable to its start value
    As skimask said
    You'll probably have to put a diode inline with the PIC pin and maybe a small R/C network behind that to filter out the 50hz half-wave and get a decent reading at the PIC
    Should not be a problem.
    Dave
    Always wear safety glasses while programming.

  39. #39
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking Can't believe it ... !!!

    Quote Originally Posted by The Master View Post
    Acetronics, that looks just slightly complicated. I dont think ive got half the components in that diagram anyway
    LOL ...

    .... just think you only need D1,D2,D3,D4, R1 and IC1 ... and you do what you want with the O.C. transistor.

    Is there someone with a brain, on this forum ???????????????????????????????

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  40. #40
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Is there someone with a brain, on this forum ???????????????????????????????
    Alain
    I've got one...bought it at Walmart on sale...rarely use it though...it gets in the way too often...

Similar Threads

  1. SMS via pic
    By kenandere in forum GSM
    Replies: 15
    Last Post: - 10th March 2010, 10:00
  2. Detecting 240V with a PIC (Part2)
    By The Master in forum Off Topic
    Replies: 7
    Last Post: - 18th March 2009, 19:10
  3. 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
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14
  5. pic detect amperage
    By jetpr in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 11th February 2005, 05:02

Members who have read this thread : 1

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