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

Using PIC microcontroller to measure high voltage andcurrent

Discussion in 'Microcontrollers' started by GraveYard_Killer, Aug 8, 2004.

  1. GraveYard_Killer

    GraveYard_Killer New Member

    Joined:
    Aug 21, 2003
    Messages:
    121
    Likes:
    0
    Location:
    Philippines
    how do I measure high voltage like 220V as well as the current running through it using PIC? I would like to build one with 2X16LCD as its display.
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,199
    Likes:
    640
    Location:
    Derbyshire, UK
    Re: Using PIC microcontroller to measure high voltage andcur

    You simply convert any required readings to 0-5V DC (assuming you're using the 5V rail as a reference).

    Reading 220V DC requires a simple resistive attenuator, if it's AC you'll need to rectify it in some way as well. To measure current you measure the voltage drop across a small resistor, you'll probably need to amplify this using an opamp. Again, for AC, you will need to rectify it.

    To do both at once you will have to give it some careful thought, you need both readings to have the same 0V point.
     
  3. Oznog

    Oznog Active Member

    Joined:
    Apr 21, 2004
    Messages:
    2,879
    Likes:
    11
    Location:
    Austin, Tx
    And the ADC, microcontroller, and LCD need to have to same ground unless a complicated isolation scheme, probably optical, is employed.

    Problem is, the only thing available to use for a ground is going to be the high voltage neutral instead of an earth ground. This isn't entirely safe to touch and shouldn't contact earth ground, but it is possible to use if everything is insulated. It will be a more major issue if you want to interface it with another device or a computer.
     
  4. dave

    Dave New Member

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


     
  5. Exo

    Exo Active Member

    Joined:
    Sep 18, 2003
    Messages:
    1,953
    Likes:
    1
    Location:
    Belgium

    To add a degree of safety to the pic you could always look for a current transformer, and use a small, normal transformer to bring the 220V into the pic's range...
     
  6. kentken

    kentken New Member

    Joined:
    Jan 10, 2004
    Messages:
    222
    Likes:
    0
    Location:
    Washington State
  7. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,199
    Likes:
    640
    Location:
    Derbyshire, UK
    I notice we all seem to be assuming this is an AC supply?, yet this has never been stated - it 'might' be a DC supply?.
     
  8. GraveYard_Killer

    GraveYard_Killer New Member

    Joined:
    Aug 21, 2003
    Messages:
    121
    Likes:
    0
    Location:
    Philippines
    yeah, im gonna use 220V AC. how will i make 220V AC scaled to 5V? do i have to use voltage divider principle?
     
  9. Exo

    Exo Active Member

    Joined:
    Sep 18, 2003
    Messages:
    1,953
    Likes:
    1
    Location:
    Belgium
    A small transfo seams the safest option to me... It doesn't have to drive any load, so it can be a really small one.

    rectify the output, put a fairly big cap on it, and keep in mind you then have a RMS value and you're off
     
  10. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,199
    Likes:
    640
    Location:
    Derbyshire, UK
    Actually you have a 'peak value', not an RMS one - but, as long as it's a sinewave, you can recalibrate to give an RMS value.

    I think we still need to know more about what he's trying to do, so far the questions have been too vague for any thing other than general answers.

    I'm 'presuming' he's wanting to measure power consumption, like an electric meter does?. If so, EPE did a project years ago using a 16C84 with an external A2D, using a hall-effect transducer to measure the current. The same sort of design could be done far easier now with the more modern PIC's.
     
  11. BartSimpson

    BartSimpson New Member

    Joined:
    Jul 30, 2004
    Messages:
    51
    Likes:
    0
    Nigel, did that use an inductive clamp ?

    I'd be a little nervous about telling someone to just use a voltage divider on mains potential when they dont know what they are doing...

    I couldn't quickly find a link to something (clamp based) that may have worked and decided it was better to stay away.
    Being new here, I wasn't sure what the protocol was when death is a possibility :)

    BTW, not meaning to imply that you have given any potentialy dangerous info.
     
  12. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,199
    Likes:
    640
    Location:
    Derbyshire, UK
    No, it was a complete potted device, you connected one side of the mains to it, and took the output from the other side - when I'm at home I'll try and find the original article. The finished device works really well, I actually built one 8)

    There was never any mention of mains until well down the thread, and that was only after asking!.

    Almost anything has the potential to be dangerous, a soldering iron or a craft knife? - to give two simple and common examples. This is a serious forum for people interested in electronics, we shouldn't need to 'baby' members - although I often do give serious warnings about truely dangerous devices like microwave power supplies!.

    While you can measure the current with a clamp device, you can't do the same for voltage - a simple potential divider is commonly used for this purpose, and as also suggested you could use a mains transformer to lower the voltage and measure that. But, again at that time, we didn't even know it was an AC supply.
     
  13. mohdroos1

    mohdroos1 New Member

    Joined:
    Nov 21, 2008
    Messages:
    3
    Likes:
    0
    thanks for you all
    i am working on graduation project and calculating power is a part of it .
    i need to connect isolator to protect PIC from high voltage.
    i have question about how to connect isolator to protect PIC from high voltage.
    i used 4n26 IC but it doesn't work ...

    i used a voltage divider to minimize voltage and shunt resistor to sense current
    help please
     
  14. janaka

    janaka New Member

    Joined:
    Nov 2, 2008
    Messages:
    1
    Likes:
    0
     
  15. mohdroos1

    mohdroos1 New Member

    Joined:
    Nov 21, 2008
    Messages:
    3
    Likes:
    0
    you have to use voltage divider to minimize the peak to 5 volts or less
    then use this valu to enter it the the ADC.
    the values of the ADC must be stored in array eg. 50 values
    divide this values by 50 you will get the RMS value of the volt
     
  16. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,199
    Likes:
    640
    Location:
    Derbyshire, UK
    Sorry, but that doesn't give you anything like the RMS value.
     
  17. smanches

    smanches New Member

    Joined:
    Mar 5, 2009
    Messages:
    986
    Likes:
    8
    Location:
    Oregon, USA
    I use the Allegro current sensors in my projects. Easy to use, fully isolated, accurate, and can measure both AC and DC currents. Specifically this one...

    Allegro | Products | ACS712 Fully Integrated, Hall Effect-Based Linear Current Sensor with 2.1 kVRMS Voltage Isolation and a Low-Resistance Current Conductor

    Gives you 0 to 5V out based on the current. Can hook it right up to a uC without any other external circuitry.

    For voltage, I use an linear opto-coupler, or just a single opto-coupler in the linear range if I don't need that great of accuracy.

    I like to isolate everything. Mains scare me. :)
     
  18. mohdroos1

    mohdroos1 New Member

    Joined:
    Nov 21, 2008
    Messages:
    3
    Likes:
    0
    i tried this before
    i used pic 16f877a and it worked.
    i noticed that the ADC reads only the positive values, the negative values is considered zeros.
    so you have to ignore zeros while filling your array. using simple if statement.

    about the current you can use shunt resistor.
     
  19. abicash

    abicash Member

    Joined:
    Feb 12, 2007
    Messages:
    427
    Likes:
    3
    Hello smanches..and apology to hijack this one.I am doing a similar thing here

    If you have easily interfaced the ACS712 to the ADC of your MCU can you share something with me?..I am having a hard time doing this..since basically my 3.3v Vdd is a bit unstable but the 5v Vcc to the ACS712 (boosted from the 3.3v) is very good.

    Please get back if you can here or my thread.

    Thanks and regards
     
  20. smanches

    smanches New Member

    Joined:
    Mar 5, 2009
    Messages:
    986
    Likes:
    8
    Location:
    Oregon, USA
    If you need very good accuracy, use a 5v reference IC to the AVdd pin, if you have it.

    I have noticed lots of noise on PICs using the internal voltage reference. The ADC will also pick up some internal noise from the processor itself, so it's best to use some sort of averaging on the input to help eliminate that.

    What specific problems are you having? Just noise from the 3.3V internal reference?

    EDIT: Nvm, I'm reading the other thread now...
     
    Last edited: Jul 1, 2009
  21. millwood

    millwood Banned

    Joined:
    Jun 17, 2009
    Messages:
    191
    Likes:
    2
    if the original poster is reading wattage (from current and voltage readings), wouldn't it make more sense to see how those electronic electric meters work?
     

Share This Page