Continue to Site

# [SOLVED]How would I create an input to an MCU pin that could be anywhere from 5V to 12V?

Status
Not open for further replies.

#### jumanji

##### Newbie level 6
I want to design a "trigger" input into the pin of a microcontroller that is running at 5V. However, the input voltage of the trigger for a "high" could be 5V or 12V. Can I just tie the input to the base of a transistor and use it to turn on or off a 5V signal to the actual pin on the microcontroller?

If you feed your your trigger via a resistor of 1-10K and at the MCU end connect a small fast diode from the input pin(anode) to the 5V line (cathode) then the actual voltage at the MCU pin is limited to 5 +diode volt drop (.8?). repeat this with another diode to the MCU input pin (cathode)and the earth rail (anode) this will clamp any negative spikes to -.8V.
Frank

jumanji

### jumanji

Points: 2
If the MCU pin has an internal pullup resistance it is already high otherwise you need to add one from the pin to 5V (say of value 4K7).
You are right, you can connect the collector to the the pin and the emitter to the ground. At the transistor (npn) base you add a resistor in series to limit the base current. Its value could be rather high (say 100K if you like). It is better to add also a resistor between the base and ground having a value about 1/4 of the previous one (say 22K).

Added (another solution, using a zener diode):
If there is an internal pullup resistor (otherwise you need to add a 10K external resistor) and you have a 4V7 zener, you can connect its cathode to the MCU pin and its anode to ground. Then you add a resistor having a relatively low value (as 1K) between your input source (5 to 12V) and the MCU pin.

Last edited:
jumanji

### jumanji

Points: 2
The clamping diode can be used to limit the input voltage to the mcu.
The other solution is to use either a transistor or even an optocoupler if you want to isolate the mcu from the input voltage.
If you use a NPN and the output (going to the mcu) is from the collector then the outpout will be inverted , LOW with positive input and HIGH with no input.

Alex

jumanji

Points: 2