I have read numerous topics on detecting high voltages on 5v microcontroller input pins. It all seemed quite complicated, until I remembered how NPN transistors worked: a voltage on the base allowed current to flow from the collecter to the emitter (or something like that).
So, if you can use a microcontroller output pin on the base to control 12v on the other two pins, can you use 12v on the base to control an input with a pullup resistor by tying it to ground? Or will I let the magic smoke escape?
Keep in mind that if, for some reason, the transistor junctions are damaged, your MCU can have 12V on its input.
Providing galvanic isolation (with an optocoupler for example) between the digital circuitry and the high voltage circuitry can avoid this.
It is, of course, not needed, but it does reduce the chances of burning the MCU if something goes wrong.
Is the large voltage always 12V, or is that just an example? You only need the transistor if you want a wide range of voltages to appear as 'connected'. Or an optocoupler if there isn't a common ground or large voltage spikes.
The circuit where 12v is either present or absent could just be a potential divider to ground.
No it doesn't you have a relatively high resistance leading to the pin's input protection
diode. You can add a zener across the bottom leg or an extra protection schottky diode
to the +5V rail if you want, but if you limit the divider current down at < 1mA level you
should be OK - certainly not high enough to trigger latch-up in modern devices.
MarkT:
No it doesn't you have a relatively high resistance leading to the pin's input protection
diode. You can add a zener across the bottom leg or an extra protection schottky diode
to the +5V rail if you want, but if you limit the divider current down at < 1mA level you
should be OK - certainly not high enough to trigger latch-up in modern devices.
I wanted to use a transistor instead of an R divider because I prefer to keep the BOM small. Adding a bunch of diodes and unnecessary resistors defeats my entire purpose.
By the way, the +12V is just an example. It just represents something >5V5.
EDIT: By the way, it would be extremely helpful to provide some simple schematics.