1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Power detector using 8051 microcontroller

Discussion in '8051/8951' started by paridhi jain, Oct 3, 2015.

  1. paridhi jain

    paridhi jain New Member

    Joined:
    Sep 2, 2015
    Messages:
    27
    Likes:
    0
    How to detect power in 8051 using optocoupler ?
     
  2. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,042
    Likes:
    541
    Location:
    AZ 86334
    Measure voltage, measure current, multiply...
     
  3. Jon Wilder

    Jon Wilder Active Member

    Joined:
    Oct 22, 2010
    Messages:
    859
    Likes:
    82
    Location:
    Fresno, CA
    Can you give us a more detailed description of what you mean by detecting power?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    9,906
    Likes:
    1,094

    Crystal ball says, Your trying to detect the presence of AC. My crystal ball has a crack in it, so I'm not really sure. It also can't seem to figure out what the mains voltage is either for some reason.
     
    • Like Like x 1
  6. Mosaic

    Mosaic Well-Known Member

    Joined:
    Jun 3, 2010
    Messages:
    2,568
    Likes:
    128
    Location:
    Caribbean
    A pinch of ochre dust, bone powder from a blind rat, some ancient amber grindings and verdigris for potency then using a flame from magnesium shavings......we have:

    Connect the output of the optocoupler transistor, emitter to 8051 ground, collector to a 10K pull up to the 8051 VCC. Then collector to 8051 digital input pin to read hi/lo logic.

    Supply the LED of the optocoupler with a resistor of sufficient value to limit the current thru the LED to about 10mA based on your supply voltage. Include a diode rectifier and a subsequent 100uF capacitor (of sufficient voltage rating) if you're dealing with A.C.

    Now when power is on...8051 in sees a logic low, when power is off 8051 sees a logic high.
    Be aware of the risks of line power (A.C.) if you're dealing with it.
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    If you are talking about a power meter, then you need an ADC and a transformer... The transformer connects to the AC and will give you an accurate voltage representation... Then you need a current transformer... Loads of these around the net.... One here?? For instance..

    If you are making a power cable detector then Read this!!!
     
  8. paridhi jain

    paridhi jain New Member

    Joined:
    Sep 2, 2015
    Messages:
    27
    Likes:
    0
    Actually I am making a real time project and I want to know how to detect power in microcontroller.
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    So you want to know how much power the micro controller is using??
     
  10. paridhi jain

    paridhi jain New Member

    Joined:
    Sep 2, 2015
    Messages:
    27
    Likes:
    0
    NO.
    I want to know if power is off then how my optocoupler detect the power
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    A picture is worth a thousand guesses....
     
  12. paridhi jain

    paridhi jain New Member

    Joined:
    Sep 2, 2015
    Messages:
    27
    Likes:
    0
    Is not the ans.
    I think u cant understand my ques...
    suppose u have a frequency 50Hz, after 20ms there is no power at diode input then my optocoupler detect that their is power cut but actually power is not cut... How can I detect actually power is cut.
     
  13. paridhi jain

    paridhi jain New Member

    Joined:
    Sep 2, 2015
    Messages:
    27
    Likes:
    0
    Did you understand my question
     
  14. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,142
    Likes:
    907
    Location:
    Rochdale UK
    ONLINE
    Not really!

    I don't know what the "power" is doing!! I don't know what the "diode" input is!! I don't know if the same "power" is supplying the micro....

    I think a basic sketch of what is required may help!
     
  15. Andrei_D12

    Andrei_D12 Active Member

    Joined:
    Aug 23, 2015
    Messages:
    177
    Likes:
    43
    Location:
    Craiova, Romania
    These words can be interpreted in dozens of ways. A micro, an octocoupler and a diode, that's all I understood. And you said something about power and AC. Mains power monitor via microcontroller, no?

    Draw a hand sketch of you circuit, take a photo, put it in attachment and the confusion will disappear!
     
  16. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,026
    Likes:
    951
    Location:
    NJ
    Hi,

    It sounds like all you want to do is detect the "voltage" not the power. The voltage to the uC chip.

    If so, then your description sounds strange because normally you would have a filtered and regulated power source to power the uC chip with, and that would not go to zero just because the line frequency happens to go through zero every 1/2 cycle.
    If you do it that way however, then you need to use another rectifier and filter cap to filter the power to the chip and then measure that with the opto coupler. That will tell you for sure if the power is lost to the chip. To filter it digitally, set a timer to time the amount of time it is seeing an 'off' condition. If it stays 'off' for more than say 50ms without coming back 'on' then it is off for good. If it comes back on within that time frame, then start the timer counter over again.
     
  17. Andrei_D12

    Andrei_D12 Active Member

    Joined:
    Aug 23, 2015
    Messages:
    177
    Likes:
    43
    Location:
    Craiova, Romania
  18. Andrei_D12

    Andrei_D12 Active Member

    Joined:
    Aug 23, 2015
    Messages:
    177
    Likes:
    43
    Location:
    Craiova, Romania
    However, this input is for a circuit with separate power source. I don't know if she wants a circuit with it's own power supply, or something which is powered by mains. It could be done one thing: it can be connected to the mains a battery charger circuit that charges a battery, which is the power supply of the circuit. When the mains drops, the circuit will operate for a long period of time until the mains recovers.


    I ''researched'' a bit the 8051 microcontroller and, seriously, such a B.I.G microcontroller for such a simple thing?? Or this circuit has additonnal features?
     
    Last edited: Oct 12, 2015
  19. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,042
    Likes:
    541
    Location:
    AZ 86334
    If you are sampling the voltage on the output side of the opto-coupler using the ADC, you time-average the voltage over an interval longer than 20ms. {Software: V(ave) < trip point}

    If the output of the opto-coupler is interpreted as a logic signal, then you start timing on any rising edge. If another edge doesn't happen within ~25ms, you conclude that the AC went off. (Software retriggerable one-shot multivibrator).
     
  20. paridhi jain

    paridhi jain New Member

    Joined:
    Sep 2, 2015
    Messages:
    27
    Likes:
    0
    can u please send me ur circuit
     
  21. MrAl

    MrAl Well-Known Member Most Helpful Member

    Joined:
    Sep 7, 2008
    Messages:
    11,026
    Likes:
    951
    Location:
    NJ
    Hi,

    So you need a circuit not a piece of software then?
    It isnt perfectly clear what you are tying to do here because your short descriptions are not good enough to describe what you want to do. Try explaining this in detail, not just one or two short sentences. I am sure that will help clear this up quick. If your English isnt good enough try to get someone to help you write it out.

    If you want to do it with a circuit then you have to have an alternate means to detect voltage levels. Probably a comparator and voltage reference. If the voltage falls lower than a certain level then an LED comes on or something.
     

Share This Page