12V signal reading

Active today
Viewed 29 times

One of my experiments has lead to two seemingly dead GPIO pins on my Raspberry Pi Zero WH. I’ll explain what I did to seemingly cause this; please help me understand what happened.

The goal: Have a 12V power source convert to a 3V3 signal, plugged in to a GPIO pin that is set as an input. When the 12V is present, the converted 3v3 will bring the GPIO pin high.

Background: This is for a car project. Essentially when I press the brake pedal, a certain wire (brake lights, cruise control override, etc) has 12V. I want my Raspberry Pi to be able to sense when I press the brake, so I need to lower the 12V from the brake light wire to a 3v3 converter that signals a GPIO input pin.

Application: I picked up this 3V3 converter and as a test, I set GPIO pin 17 as an input pulled down. The Raspberry Pi was plugged in to a USB 12V to 5V converter and plugged into a 12V battery. The 3V3 converter was fed by the same 12V battery, and was outputting about 3.2 Volts when I tested the output leads with my multimeter, so far so good. Because they all share the same ground, I just plugged the positive 3v3 lead from the converter into GPIO pin 17.

What went wrong?: For some reason, instead of pulling GPIO 17 high as it should have, and giving me a high signal, it was still calling GPIO 17 “Low”. Hm? Then I tried again on GPIO 21 and the same thing happened. Now coincidentally, both GPIO 17 and 21 not only don’t seem to read inputs correctly anymore, but they don’t output either, so it seems like the pins are just dead now. Why?

A little more background: What’s more confusing to me is I have done this same exact concept before on a different RPi Zero WH, and it seems to work flawlessly. In my other application, I have a 3V3 signal that I tapped directly from my PC’s power supply, and I plugged the 3v3 OUTPUT from my PSU directly to GPIO pin 21 on the RPi. In Python, I pull GPIO 21 LOW, and when I turn the computer on and the PSU is outputting 3v3, GPIO will read HIGH. When the computer is off and the PSU is not outputting 3v3, GPIO 21 stays LOW. Perfect.

I’m basically doing the same exact thing here, so why did it fry the pins in the other case?

The only difference in the way I wired these was, because the PSU 3v3 was a completely separate circuit, I plugged both the positive and ground from the PSU to the RPi header board, 3v3 + to GPIO 21 as an input, and the PSU ground to Rpi ground.

In the other case, both the 5V and 3V3 sources from the converters, as well as the 12V battery powering those converters, already all share the same ground. So logically I figured the ground from the 3v3 converter was not necessary to tie into the Rpi ground because there would already be continuity, so only the positive 3v3 lead from the converter was necessary. Am I correct here, or could this possibly have something to do with it? That is the only difference I can think of between the way I wired the two, otherwise the scripts and fundamentals seem identical.

Analog vs Digital Voltage?: One final detail, I have seen people refer to analog vs digital signals before, but as far as I know, the voltage is what it is, any 3v3 signal should trigger a high signal on a GPIO input right? Is there such thing as digital and analog 3.3 volt signals? The only reason I ask is because my power supply is advertised as a “digital power” supply, so I wonder if somehow the 3V3 being output by my PSU is somehow different than the 3.2V created by the converter coming from the 12V source.

 New contributor
  • Hi @cornerpocket, Ah let me see. I am 80% sure that it is this DC/DC 12v Step Down to 3.3v 3A Power Supply Module that fried your two GPIO pins: amazon.com/dp/B00H2CKFXQ. Reasons: (1) This DC/DC 12V to 3V step down power module is a “switching power supply unit” which has a high frequency (of the order of 100 kHz) oscillator used to switch the 12VDC source to charge up a capacitor to 3V. When 3V is reached, oscillator stops. And when 3V drops because drawing current out, oscillator starts again, and so on. / to continue, … – tlfong01 9 hours ago
  • Now let me dig deeper into the oscillator circuit which, non stop, at a high frequency, switches current on and off from 12V battery to charge up a capacitor to 3V. What cause trouble is the that the oscillator itself is switching on/off an inductor and this switching inductor current on/off causes “Back EMF“ which causes big current in a short time, causing voltage spikes which might be many times higher than 3V. And this spike might “radiate” outside the oscillator circuit to the Rpi GPIO pin circuit. Sorry for the electronics circuit analysis which I think might be too hard for you. – tlfong01 9 hours ago
  • I am just thinking aloud, to help finding the culprit. Never mind the above boring electronic “lecture”. What I want to say is (2) You made a mistake of using a switching mode DC/DC step down 12V supply unit, to convert a 12V “power” to a 3V “power.” What you should use instead is a logical signal step down converter, to convert 12V logical signal (OK, I know it is from a 12V battery, but you can see it as a “signal” which draws very very little current, not like a power supply) to 3V logical signal. – tlfong01 9 hours ago
  • Now let me suggest a couple of circuits to replace the switching power supply. (1) A simple 2 resistor voltage/potential divider, say 9kR + 3 kR in series, with 9k end connected to 12V, 3kR end to ground. Then the 9k 3k connection point would be 12V * (3K / (9K + 3K)) = 12V * (3/12) = 3V. This is the signal you can connect to the Rpi GPIO pin to read. BUT there is a 5% chance that this simple voltage divider will still fry the GPIO pin. Since you already have fried two pins, you still got a lot more spare GPIO pins to fry. (2) Using a voltage divider with a optical isolation buffer, – tlfong01 9 hours ago
  • (3) Using a CMOS NAND gate with open drain (sort of pull down) output HC03A to convert (12V voltage divided to) 5V input signal to 3V3 output signal. This is safer than the simple two resistor voltage divider, but not that safe as the optical isolation circuit. And coming back to your question of why one Rpi survives but not the other. One possible reason is that one Rpi is “stronger” than the other! 🙂 PS – I am making a quick and dirty explanation and suggestion. There should be better explanations and suggestions. But bed time for me now. So see you tomorrow. Cheers. – tlfong01 8 hours ago


Your question is too vague and imprecise to answer definitively, but contains a number of misconceptions.

I need to lower the 12V from the brake light wire to a 3v3 converter that signals a GPIO input pin.

You are using a 12v Step Down to 3.3v 3a Power Supply Module – these are designed to supply power – NOT to convert logic levels. They often work poorly if unloaded, and are unstable on startup!

There are logic level converters, but there is no need; a simple resistive voltage divider would suffice (and be safer) – although I would use a diode clamp in addition to prevent transient damage.


simulate this circuit – Schematic created using CircuitLab

I would NOT directly connect a foreign voltage source to a Pi (or any other logic circuit) without protection. NOTE you do NOT need 3.3V – indeed an engineer would use a circuit designed to safely exceed the logic threshold. See https://raspberrypi.stackexchange.com/a/104897/8697 (I normally aim to supply 2.2V to a Pi GPIO input). I wouldn’t even connect the Pi 3.3V power to a GPIO without protection.

Finally you seem to be working in an automotive environment; these are a hostile environment for electronics, and require special design for safety – especially the routing of ground cabling. I would aim for an isolated circuit, either an opto-isolator or relay.


Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: