Need help to detect 3.3v on GPIO on ESP32

I think I can do this, but need some clarity. I need to detect automotive ignition ON status. I have a buck converter coming for 12v to 3.3 v. Can I simply create a binary sensor and feed the 3.3v from the buck converter straight to the GPIO pin (and of course all the grounds are shared)? I am afraid of frying my $6 ESP 32 module :). The 12v source will be from a fused panel from the van, I will make sure it’s HIGH only when the motor is running. As such, I am pulling a momentary contact (as an example) to HIGH? vs the typical LOW that I would do with a momentary contact switch. Or is it better that I use a relay and power the coil with the 12v ignition source and use that as a switch?

You don’t need the buck converter or relay. A simple resistive divider would do.

https://ohmslawcalculator.com/voltage-divider-calculator

How are you powering the ESP32?

You could use the buck regulator for that.

Thank you. So the POSto the GPIO?

No. The POS to the resistor divider, the output of which goes to the GPIO.

Apologies, I mean after resistor divider at 3v. Thank you for the simple circuit!

If you happen to have optocouplers in your drawer, that would be even safer. Automotive voltages can have nasty spikes.

Modern cars aren’t that bad and any minor ignition noise will be current limited limited by the input resistance.

I would add TVS anyway…
But reading OP’s description more carefully, I got doubts what he is actually willing to do here… Esp is powered from that buck? And then?

Yeah that’s still not clear. I did ask.

TVS diode would be good insurance.

Guys,

Thank you again for the concern. The ESP 32 will be independently powered. By 3.3 V source. The point of this project is to create an automation to let Home assistant know that the engine is running. With that knowledge, I can create other automations in the van based on that.
I just need to have a dashboard indicator that the motor is on. And the way I was planning on doing this is to monitor 12 V ignition signal via a GPIO pin. In my puni electrical mind, the easiest method was to have the 12v ignition current power the coils of a simple SPST relay. And I would pull the GPIO pin to ground using binary sensor protocol. Basically recreating a momentary push button switch. I also was planning on using a buck converter that is 12v powered to 3.3v to provide the GPIO pin that the ignition is on. Again the ESP32 would have a separate power source. All suggestions welcome! And thank you again for trying to help me.

While relay or buck converter approach is technically doable, voltage divider or optocoupler is more reliable and cheaper.

Power relays are not good for logic signals. If you really want to go with relay, look for automotive signal relay.
Buck converters, especially those commonly available online, are often bad quality. And they can fail undesired ways…

Thank you once again! Optocoupler will be. My goodness I am reliving my ancient college days!

Problem solved and thank you for all the help!

Using this simple PC817 board:
Optocoupler

12v to the input + and -

GND to ESP32 GND, OUT to GPIO27 on the ESP32 (this is what I used), with the following simple YAML:

binary_sensor:

  • platform: gpio
    pin:
    number: GPIO27
    mode: INPUT_PULLUP
    inverted: true
    name: “Ignition Switch”

And a dashboard card, a 12v power supply voltage was reported as an event to GPIO27. Very cool! Now my HA will know when my van’s motor is running. (Will have to tap an appropriate ignition fuse on the van). Love the ESP32!

Simple automation for sure, but important none the less.

Thank you to all for the help in this thread.

BTW, the GND and OUT had 86 ohms resistance with the provision of 12v on the INPUT side.

Hope this helps someone who is interested in this.

Given the nature of binary sensor, it will always stay ON with the application of 12v and OFF when 12v is shut down.