Continue to Site

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.

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

Measure car battery voltage with PIC, from optocoupler ??

Status
Not open for further replies.

settra

Member
Hello forum ! i want to measure the voltage of my car battery, (and alternator output), with a microcontroller.
I don't want to use a simple voltage divider circuit, because i am afraid of the large voltage spikes.. (i dont trust my alternator at all)

As i understand, i can use an optocoupler, to completely isolate the input of the microcontroller. with a circuit like this :
X0P2e.png

My problem is, how do i set up , R1 and R2 so that the output is in the correct range??
for example in the PC817, in the datasheet, it says : CTR : 80 to 160 ... is there something i dont know?? becouse i am not able to make any calculation based on such a big diference... :/
 
If measuring a voltage level you need a linear device, there are opto with this type of output such as H11F1 etc.
Max.
 
have you looked at Texas Instruments ina220? or other current/power monitors, might be just the ticket:woot:.
 
.............
As i understand, i can use an optocoupler, to completely isolate the input of the microcontroller. with a circuit like this : View attachment 97404
My problem is, how do i set up , R1 and R2 so that the output is in the correct range??
for example in the PC817, in the datasheet, it says : CTR : 80 to 160 ... is there something i dont know?? becouse i am not able to make any calculation based on such a big diference... :/
That's correct. The transfer gain of an optocoupler has a large variation.
The only way to use your circuit is to calibrate it after you build it.
Also you probably want to place R2 in the emitter to ground, so that the output voltage increases with the input voltage.
You can adjust the sensitivity for calibration by using a pot for R2.
 
A frustrating thing throughout all of electronics is that there is no such thing as a DC transformer (stupid Ampere's Law!!!). There are circuits thatcan be good enough, and I think Wally has a posting on this. But the simplest solution is to use a simple voltage divider and learn how to deal with the spikes. It is not as difficult as you think it is. Besides the two resistors, one diode and one or two capacitors should do it.

ak
 
I measure battery voltage all the time with PICs. There are capacitors to smooth the signals, and there are the clamping diodes in the PIC. The resistors in the potential divider will prevent excessive current in those diodes even if the voltage is large.

I've seen opto-isolators used as linear devices and they are terrible.
 
I've seen opto-isolators used as linear devices and they are terrible.

Garden variety parts like 4N35 certainly are, but there are specialty parts designed specifically for analog voltage transfer that don't completely suck. Still, for DC accuracy the amount of compensation circuit tricks needed far outweighs a little input protection. However, I would not rely on the PIC's input for the primary protection. I think it can handle what is left over after an external zener clamps whatever is coming in.

ak
 
How do you suppose that all of the other electronics in cars deals with spikes? (Hint: they are no way as bad as you think, and it is quite easy to deal with them)
 
Use a simple voltage to frequency conversion to pulse the opto then measure the frequency at the other side with a microcontroller.

Otherwise, as Nigel suggested, voltage divider and a couple of transient protection devices should be more than adequate - even a half decent RC filter will protect you from the majority of issues.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top