Electronics > Beginners
Sensing 12v line with 5v MCU
(1/6) > >>
vmallet:
I have the following existing circuit (in a car, 12v battery):


I would like to know the state of the switch (open, closed) with a 5V MCU. The only place I can tap into the circuit is in A. What would be a good way to do it?

Would something like this work?


In this case:

* Should I worry about the <2mA that are going to flow through the coil at all times now? Could it damage the relay over time?
* Would I need a pull-up resistor to 5V in point C? (to prevent a "closed" read say in case the fuse blows?)
* Do I need to worry about the relay coil's kickback?
* (@Ian) would I need a small capacitor across the zener to ignore RMI (10nF)?
* If I didn't want the <2mA to flow through the voltage divider while the car is turned off (no power to the MCU, but the +12V is always hot), would I / should I add a  switching transistor / mosfet between the divider and GND?
Circlotron:
If C is going directly to the MCU port pin then you could increase the resistor values X100. That and put say 100nF in place of the zener and you're ready to go. Any high voltage transient from the relay coil switching off will not push any worthwhile current through to the port pin, and the ESD diode in the MCU should be just fine. Done this many times with HC08 micros, I expect yours should be much the same in this regard.
digsys:
...  or for absolute safety / simplicity, just use an opto-coupler + resistor. Removes any pulse / fault / ground issues getting to the micro.
vmallet:

--- Quote from: Circlotron on April 23, 2019, 01:54:30 am ---If C is going directly to the MCU port pin then you could increase the resistor values X100. That and put say 100nF in place of the zener and you're ready to go. Any high voltage transient from the relay coil switching off will not push any worthwhile current through to the port pin, and the ESD diode in the MCU should be just fine. Done this many times with HC08 micros, I expect yours should be much the same in this regard.

--- End quote ---

You mean like this?


Wouldn't the circuit be super sensitive with such high value resistors?
Also with the 100nF there, wouldn't that introduce a delay from when the switch goes to GND to when the MCU can detect the drop while the capacitor slowly discharges through the resistors? (RC would be ~22ms with R=330K//680K)?

Thanks!
vmallet:

--- Quote from: digsys on April 23, 2019, 03:18:46 am ---...  or for absolute safety / simplicity, just use an opto-coupler + resistor. Removes any pulse / fault / ground issues getting to the micro.

--- End quote ---

How would you wire that up? I was trying to turn that around in my head but I'm not seeing it... Thanks.
Navigation
Message Index
Next page
There was an error while thanking
Thanking...

Go to full version
Powered by SMFPacks Advanced Attachments Uploader Mod