How to monitor a wire for 12v with a 3.3v microcontroller

Thread Starter

ba58smith

Joined Nov 18, 2018
62
I'm trying to monitor a bilge pump on my boat, so I can get an alarm whenever it comes on. It's a 12V pump with a float switch that turns it on. I want to "tap into" the wire between the float switch and the pump, and when the float switch closes, and the pump comes on, I want to "see" that on a microcontroller. The microcontroller has 3.3v GPIO pins. I also want to power the microcontroller from the boat's 12V system so I don't have to worry about replacing little batteries periodically, and the microcontroller is powered by 5V.

I have used a simple LM7805 voltage regulator to provide power to the microcontroller. I have used a voltage divider and then a Zener diode on the "tap wire" to step the voltage from 12V (approx) down to 3.3V. All of these subsystems work fine by themselves. But when I actually connect the "tap wire" from the pump wire to the voltage divider / Zener diode / GPIO, the voltage just before the voltage divider is only about .75 volts. Is the problem that almost all of the 12V is taking the easy way to ground through the pump, and only a small fraction of it is going to the microcontroller through my "step down" circuit? I thought I'd have the full 12V at my voltage divider / Zener diode, but I surely don't.

If this is indeed what's happening, then I guess I'm starting from scratch with this question: How can I "tap into" a 12V wire and monitor it with a 3.3V microcontroller?
 

WBahn

Joined Mar 31, 2012
30,058
We really need a schematic to see how you are connecting things.

Is the pump on or off when you are measuring the voltage in the divider?
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
This is what I have to provide power to the microcontroller and to step down the 12V that powers the boat's four bilge pumps to get to 3.3V to the GPIO pins. (The Zeners say 4.7V, but they're not - they're 3.3V.) Now, imagine the wire that powers the 12V bilge pump running along the left side of this diagram, with a small wire "tapped into" it and going into R1. (The ends of the wire that powers the pump are, for simplicity, the boat's 12V battery and the pump itself, so it has 0V when the pump is off and 12V when it's on.) When the pump turns on, I expect 12V to come from the "tap wire" and into R1 and be reduced to 3.3V before it gets to the GPIO pin. But instead of 12V at R1, I'm getting about 0.75V.

upload_2019-2-9_19-28-26.png
 

WBahn

Joined Mar 31, 2012
30,058
This is what I have to provide power to the microcontroller and to step down the 12V that powers the boat's four bilge pumps to get to 3.3V to the GPIO pins. (The Zeners say 4.7V, but they're not - they're 3.3V.) Now, imagine the wire that powers the 12V bilge pump running along the left side of this diagram, with a small wire "tapped into" it and going into R1. (The ends of the wire that powers the pump are, for simplicity, the boat's 12V battery and the pump itself, so it has 0V when the pump is off and 12V when it's on.) When the pump turns on, I expect 12V to come from the "tap wire" and into R1 and be reduced to 3.3V before it gets to the GPIO pin. But instead of 12V at R1, I'm getting about 0.75V.

View attachment 169878
What does the voltage read at the left side of R1 when the pump is ON and when it is OFF?

It's possible your pump is pulling the bus down heavily, though that seem pretty excessive.

How is the switching of the pump actually done? Can you measure the voltages at that switch?
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
I've taken everything apart to do some bench testing (it's impossible to reach when it's installed). When I can get it all back together again, I'll get the voltage reading at R1.
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
I think I have figured out the problem. My voltage "tap" is into the negative side of the pump's wiring, not the positive side. And if I tap into the positive side, the GPIO pin will always be HIGH. So I guess there isn't a way to "tap into" 12V in this case. Back to the drawing board.
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
If you want voltage look at the LT6700 series of comparators. Overvoltage it the inputs OK.

You can also use current. See these hall effect sensors. https://www.pololu.com/search?query=current+sensor&x=0&y=0
I've not used a comparator before. Looks like it compares two voltage sources, then outputs HIGH or LOW based on which input is greater. So, since my input is going to be about 0.75 volts, I just need a reference voltage that's always less than that, say, 0.5V?
 

djsfantasi

Joined Apr 11, 2010
9,163
How much current does the pump draw, maximum? If you put a shunt resistor in series with the pumps ground, you should be able to use the ADC function on the microcontrollet to measure the voltage drop across the resistor. An almost zero voltage means the pump ain’t running. A higher value (depends on the current draw and the resistor value chosen) means the pump is a’pumpin’.
 

crutschow

Joined Mar 14, 2008
34,432
My voltage "tap" is into the negative side of the pump's wiring, not the positive side.
So does the switch ground the negative side of motor to turn it on?
If so, then the voltage will be high when the pump is OFF and low when the pump is ON.
You just need to reverse the logic in you microcontroller sense input.
 
I've not used a comparator before. Looks like it compares two voltage sources, then outputs HIGH or LOW based on which input is greater. So, since my input is going to be about 0.75 volts, I just need a reference voltage that's always less than that, say, 0.5V?
The 6700 has a 400 mV reference in it. Another p/n is a single comparitor based on the same technology. Both have various sub-parts which determine what pins the 400 mV reference connects to. High value resistances can be used for the voltage divider.

So, you divide the .75 down to 0.400 or divide by 1.875.

There are a number of things that like to invert here and comparitors basically have an open collector output. Once you divide it, you have to figure out what pin gets the signal and what pin gets the reference and provide a pull up resistor because the output is open collector.
 
Last edited:

jbeng

Joined Sep 10, 2006
84
A bit late to the game here, but you could use an optocoupler, like in the attached image. When the switched lead (the motor tap) is grounded, the LED in the opto goes on (drawing 9mA when powered by 12v) and the output pin of the phototransistor (connected to your MCU pin and normally pulled up to +3.3v), goes low.
For R1, I'd use a (minimum) 1/4w resistor, since it will be dissipating ~97mW. Negligible current will flow through R2, so whatever size you have handy should be fine.

opto.jpg
 

Reloadron

Joined Jan 15, 2015
7,517
You may want to give this a read:
The Values for High and Low on The ESP8266EX

With the above logic levels in mind you may want to rethink your divider circuit. While you have the 3.3 volt zener diodes in there do you really want that? I would just use the zener diodes as a safety measure. Also if the boat is anything like most marine or automotive electrical systems the true voltage is likely between 12.6 and as much as 14.0 volts under normal running conditions. Running at 12 VDC a 4:1 divider will output 3.0 VDC which is fine for a logic high and at 13.6 VDC you would get about 3.4 VDC. You may just want to replace the resistors with 10K pots and adjust with the engine off and at full charge for a convenient logic level high.

Just a few thoughts on the subject.

Ron
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
So does the switch ground the negative side of motor to turn it on?
If so, then the voltage will be high when the pump is OFF and low when the pump is ON.
You just need to reverse the logic in you microcontroller sense input.
Yes, the switch grounds the negative side to turn it on.

Do you mean that would be the case if I tap into the positive side of the switch? I see that the voltage would be HIGH when the pump is OFF, but why would it be LOW when the pump is ON? Sorry, I'm sure that's a real basic question, but it doesn't make sense to me. Seems like it would always be HIGH, regardless of the status of the switch.
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
I see no reason to use a comparator here.
There appears to be plenty of voltage swing to give an adequate signal to the microprocessor without one.
The ground wire coming out of the pump has a diode in it with a 1V forward voltage. By putting my "tap" into the anode side of the diode, I get about 1V between there and ground. And that's enough to turn the GPIO to HIGH. The pull-down resistor will keep it LOW when the pump is off. So, all in all, this looks like a pretty good solution, and far simpler than many others that have been considered. Thanks, all, for your input. I've learned a LOT!
 

crutschow

Joined Mar 14, 2008
34,432
Yes, the switch grounds the negative side to turn it on.

Do you mean that would be the case if I tap into the positive side of the switch?
No.
I meant you tap into the negative side, where the switch is.
When the switch is off, the voltage is 12V (from the voltage through the motor).
When the switch is on, it's connected to ground and the voltage is zero.
(At least that's my understanding from how you've described the motor connections).

But if the diode monitor works, that's better since it detects the motor current, not voltage, which is more likely to show that it's actually running.
 

Norfindel

Joined Mar 6, 2008
326
When using zeners, you don't need to have a resistive voltage divider with two resistors and then the zener. All you need to do is to provide one resistor that will allow the zener's rated current thru the zener, then connect the I/O pin to the junction between the zener and the resistor.

For example: if the max voltage is 12v, the zener is 3v3 and the zener's current is 5 mA, they you need (12v-3v3)/5mA = 1740 ohm
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
No.
I meant you tap into the negative side, where the switch is.
When the switch is off, the voltage is 12V (from the voltage through the motor).
When the switch is on, it's connected to ground and the voltage is zero.
(At least that's my understanding from how you've described the motor connections).

But if the diode monitor works, that's better since it detects the motor current, not voltage, which is more likely to show that it's actually running.
Oh, I get it - put the "tap" after the motor and before the switch. Yes, your understanding is correct, and that makes sense now.

I will try that, and I will also try using the diode forward voltage. One may give a more reliable result. Thanks.
 
Top