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

Thread Starter

ba58smith

Joined Nov 18, 2018
62
I see no reason for a more complex circuit or the need for a Zener.
Just use the same diode circuit that you used for the first pump.
In this case the low motor impedance when off will pull the input to ground, so the input low is motor OFF and high is ON.
I made a circuit to test this, and my OFF output was about 2.4V, and my ON was 4.7V. I thought maybe you meant I would need to use a pulldown resistor instead of a pullup, so I tried that, and got 0V for both ON and OFF. Then I tried it w/o a pullup or pulldown, and 0.28V for OFF and 0.58V for ON - not high enough for a logical HIGH. In short, I couldn't make it work any way I tried it.

@ba58smith yes you need R3. You do not need or want the other two resistors.

Bob
Then I tried what Bob suggested, and I got exactly what I thought I'd get - the output of the Zener, which as I noted above, is in the 3.3 - 3.7V range for the 3.3 Zeners that I have (and more than the safe GPIO input max of 3.6).

Then I tried what I had asked about, with R3, and I got exactly what I was hoping for - 1/2 of the voltage of the output of the Zener.

Thanks to everyone who contributed. I have learned a lot.
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
I would consider an opto isolator with an AC (back to back LED) input with an appropriate series resistor to limit the LED current and a 100-300 ohm resistor across the LED terminals to set a current threshold. That way any and all electrical horribleness that occurs in the bilge, including effects of ham handed reverse-wiring installers, won't be transmitted to your delicate 3V3 uC. I've actually dealt with things like resistor dividers, zeners and back biased diodes and .... now I always use optos.

Also, consider using an automotive rated voltage regulator instead of the 7805. ST makes lots of them and they are specifically designed to withstand the other electrical horribleness - reverse polarity, alternator load dumps etc. - that auto/boat electrical systems can dish out. Again.. been there.

YMMV
@JohnInTX, I am considering optoisolators, because of the potential for "horribleness" that can occur in a boat's electrical system. I've pursued that in another thread, and ended up with what seems like a pretty clean design using a 4N37, which seems like it will safely handle 8 - 20V (which covers the range of all the things on the boat I want to monitor for on/off status).

I just looked at the ST automotive voltage regulators (https://www.st.com/en/automotive-an...egulators.html?querycriteria=productId=SC1036) - there are so many choices... can you suggest one that you've used yourself? Thanks!
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
What was your input for those voltages?
The input needs a low impedance to ground (such as the motor) for the OFF state.
I was testing with an Arduino Uno, so my input voltage was 5V from the 5V pin. My "motor" was just a 330 ohm resistor and a small LED - just something to induce a load. What could I use in a test circuit that would simulate the low impedence to ground of a motor?

But even if an actual motor would take the GPIO to LOW when OFF, what about the 4.7V when the circuit was ON? I need to have no more than 3.3.
 

PhilTilson

Joined Nov 29, 2009
156
Two things: first, why are some people determined to make this more complicated than it is?? Optical isolators, zener diodes, double-pole relays? For goodness' sake, all it needs is ONE diode and ONE resistor! And, as Crutschow says, the same circuit will be perfectly adequate for both requirements, just the sense of the input needs reversing (ie high for on, low for off).

Second, to the TS, you need to read up on the action of diodes. When a diode is reversed biased, as long as you don't exceed the max reverse voltage, it is effectively an open circuit. So the voltage on the 'far' side of the diode is irrelevant - you don't need any potential dividers. And the reason your test circuit didn't work is probably because you used a 330 ohm resistor and an LED as a load - rather than the probable 6 ohms or so of the bilge pump! Try using a 12V bulb - a halogen one, not an LED - as a load and I think you will find it will work fine!
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
<snip>
Second, to the TS, you need to read up on the action of diodes. When a diode is reversed biased, as long as you don't exceed the max reverse voltage, it is effectively an open circuit. So the voltage on the 'far' side of the diode is irrelevant - you don't need any potential dividers. And the reason your test circuit didn't work is probably because you used a 330 ohm resistor and an LED as a load - rather than the probable 6 ohms or so of the bilge pump! Try using a 12V bulb - a halogen one, not an LED - as a load and I think you will find it will work fine!
I really do know how diodes work, but I can see how my reply wouldn't indicate that! But now that I'm reading your reply, I think I see how the whole circuit should work, when the sequence of what I'm tapping into is 12V -> switch -> my "tap wire" -> the pump -> GND.
- When the switch is open, the tap wire has a fairly easy path to GND: going through the motor, which doesn't offer much resistance for electricity to flow through it, even when it's turned off. So the GPIO pin would be pulled to ground, through the diode, the tap wire, and the motor.

- When the switch is open, the diode doesn't let any of the voltage that's going to the pump go into the GPIO, so the pullup resistor to the 5V would make the pin read HIGH. (My uC is 3.3V, so the 5V in your original schematic would be 3.3, which is perfect for the pullup.)

Is that right? Do I pass? :) (Seriously - thank you guys for not throwing up your hands in disgust, and sticking with it. I truly appreciate the education!)
 

PhilTilson

Joined Nov 29, 2009
156
Is that right? Do I pass? :) (Seriously - thank you guys for not throwing up your hands in disgust, and sticking with it. I truly appreciate the education!)
Almost! Your second paragraph should read "When the switch is CLOSED, the diode...", otherwise you are on the nail!

Good luck with your project.
 

Thread Starter

ba58smith

Joined Nov 18, 2018
62
Almost! Your second paragraph should read "When the switch is CLOSED, the diode...", otherwise you are on the nail!

Good luck with your project.
Damned typo! Those C, L, O, S, E, D, P, and N keys are so close together on the keyboard, I often type "open" when I mean to type "closed". :)

Again, sincere thanks for all the input, from everyone. Now I'm going to go build and test this, finally understanding how it's going to work.
 
Top