Sense 12V and trigger microcontroller I/O input ( automotive ) - Page 1
Forum section: electronics / beginners

author: misiek303
author_rank: Contributor
timestamp: April 04, 2023, 02:29:44 am
content: Thanks for helping with the 12V DC-DC 5V converted in the other post. Aside from the powering mega 2560, I would like to trigger an IO.I will try to explain this way. I have the below connector on the board...[] GDN[] 12V Battery -> DC - DC 5V ( constant power to mega 2560, potently mega will go to sleep and wait for a trigger )[] 12V Ignition KeyIf 12v will be supplied from Ignition Key, I would like to wake mega ( or check the pin if it's HIGH run something )I have been searching and found that simply an optocoupler could do it. But to be honest I don't know how that's different from the DC-DC converter in my other post.I attached an example of the circuit.Can you advise here as well?Thanks

author: james_s
author_rank: Super Contributor
timestamp: April 04, 2023, 03:23:12 am
content: The optocoupler is the safest method as far as limiting the possibility of damage to the microcontroller. A resistor divider will also work, or a resistor and zener diode.

author: misiek303
author_rank: Contributor
timestamp: April 04, 2023, 11:24:40 pm
content: Will this do the job with this optocoupler (PC817X2NIP1B ) and resistor values?.I think I need only 20mA to turn on Mega IO, but in my case when I pull it down, does it matter?1. Is this attached version pull-down, but the previous attachment pull-up option, correct?2. In case where I want to pull-down the pin, should I just shorten it to the GND?, do I need the 5V tall?Sorry I am learning.Thanks

author: misiek303
author_rank: Contributor
timestamp: April 04, 2023, 11:27:40 pm
content: To continue my second thought from point number 2. Does the attached circuit make any sense ?

author: redkitedesign
author_rank: Regular Contributor
timestamp: April 05, 2023, 08:30:39 am
content: You only need a few uA to drive the GPIO of an MCU. Those GPIO's can often source (or sink) 20mA when used as an output, but to actually drive them takes much less.And only the first of your two circuits will work. You will always need either a pull-up or pull-down in combination with the optocoupler.Pull up is more common, and should work slightly faster as the high/low detection levels on most GPIO's are not symmetrical (often, everything below 0.8V is LOW, and everything between e.g. 2V and 5V can be HIGH. So, you'll want to use a pull-up as that gives you an easy way to pull the GPIO down and create a real LOW on the GPIO.)The disadvantage is that the configuration with pull-up is inverting. You can easily solve that in software. And get used to it, because it is very common for hardware to assume that software will invert things whenever hardware likes it

author: Terry Bites
author_rank: Super Contributor
timestamp: April 05, 2023, 12:57:32 pm
content: Add noise and over voltage and reverse polarity protection at the input. This will save you tears later on.Automotive transients can be 100V(!) at start up -so choose input protection diodes to suit, 200V or higher.If you use an opto 100V will kill it stone dead with out reverse polarity and over voltage protection at the input.You might have to fiddle with the cap value. Make it a lot bigger.It depends on how well your GPIO test code rejects false triggering.Test that the trigger is there for some fixed period before acting on it.