Using 12v and 0v to trigger digital input

I have a project that is using a grounding signal to trigger a digital input, but I also need an automotive 12v signal to trigger the same input wire as if it were being grounded. It doesn't need to necessarily need to be the same digital input pin, but the signal will be coming in on the same wire. So my logic table would be something like:

Input signal voltage at digital pin Logic
12v-14v ? 0
Floating 5v 1
Gnd/0v Gnd/0v 0

I am using a 7805 to convert the automotive 12v into 5v for the 328p pro mini 5v 16mhz Arduino. Does someone have an idea of how to best design a circuit to do this?

You can edit your post and fix the table.

Input signal voltage at digital pin Logic
12v-14v ? 0
Floating 5v 1
Gnd/0v Gnd/0v 0

Add this between the top row and the rest:

| --- | --- | --- |

I suggest to measure the voltage with a analog pin and decide in software what the logic will be.
If you already use a internal voltage reference, then you can use that or else use the default 5V as voltage reference.

A voltage divider is two resistors. With R1 = 22k and R2 = 10k, you can measure up to 16V. You can increase the values for more safety. Up to 220k and 100k should still work.

A third large resistor can be used to pull the signal towards 5V when nothing is connected. You will not be able to check if the signal is floating or 5V. You need a second (digital) pin to test if the input is really floating.

Other possibilities are using two inputs with two voltage dividers, or a single digital input with extra hardware. With a analog input, you can make the decisions in software.

1 Like

Automobile is a dirty environment and simplicity is best in these environment, so a 12V sealed relay like below is a good way to design (optical isolator js also a choice)

I'd go with @Koepel; use a single analog input.
trying to use two seperate digital inputs is complicated.

However to reduce the input impedance I'd use smaller resistance values - say R1=2k5, R2, R3 = 470 ohm; and a capacitor from the R1/R2/R3 - A0 junction to eliminate interference.

With those values +12 would give you around 4.5V; 0V around 2.0V; o/c very close to 2.5V

The higher the resistors values, the more the Arduino input is protected against high voltage peaks, assuming that 1mA may be pushed into the Arduino pin.

With 22k and 10k, the maximum voltage peak is 39.6V (that is theory, in real life the current into a pin can be more).
I think a circuit for in a car is supposed to allow a peak of 120V, so the resistors can better be higher.

I don't understand why you want such a extremely low input impedance. In all the years that I use Arduino and read this forum, I have never seen the advice to go so low.

Hi @Koepel - just that the car environment has a LOT of interference going on, and a high impedance input will be more susceptible to picking it up. Of course I agree you need to protect the arduino input.

It's not clear from your post if you know how to wire the relay.
Your wording suggests not.
If what you are saying is you need a TTL LOW (0V) input to a 5V digital circuit
to be triggered by a 12V relay, then of course the contacts of the relay would
have COM tied to the 5V GND and the N.O. (Normally Open) contact tied to
the 5V input that you want to ground. When the relay engages, the contacts
close connecting the input to GND. There should be no issue with connecting
a high impedance TTL/MOS input to GND. There will of course be some
contact bounce which can be suppressed by adding a 1k pullup to 5V connected
to a .1uF to .47uF cap to GND. The N.O. contact would connect to the junction of
the resistor and cap and from there to the digital input. Steady state of the input
would be High until the contacts close shorting it to GND but the added resistor
and cap should suppress the bounce.