# Read -5V Signal with Microcontroller

I have the following problem. I want to read an -5V Signal using my Microcontroller. I have the following circuit setup, but it does not work.

My problem is that the the signal is high while the signal is not there (0V).

Thank you for every hint! :)

• You want microcontroller to read 1 when there is -5V at pin and 0 when there is 0V? – Golaž Jul 25 '15 at 13:15
• Also, what microcontroller do you use and what is its supply voltage? – Golaž Jul 25 '15 at 13:17
• @Golaž exactly thats what I want. I am using an Atmega328 with a supply voltage of about 5V. – xDarcade Jul 25 '15 at 13:30

You can use this circuit to change the level of your -5V signal to something that can be read by the micro controller.

This circuit will give a logic high (+5V) output when the input is not connected or a small negative voltage.

If the input is -3V or more the output will be a logic low.

kevin

simulate this circuit – Schematic created using CircuitLab

• Thank you for your solution! I think it fits the best as solution :) When I get it to work I'll mark it as solved my problem! – xDarcade Jul 25 '15 at 21:21

I assume that this is a binary signal of {0V, -5V}, since you show it going directly to your MCU.

In which case, you should check your signal source to see whether there is something that provides an ENABLE control signal. Put an inverter or level shifter, depending on your system, in series with your source and the MCU, with the inverter or level shifter being controlled by the ENABLE signal.

It doesn't work, because the PNP transistor turns on when there's a voltage on the input that's more than 0.7V below the +5V. Well that's putting it very simply, but that's what happens here, because the μC doesn't require much current on its input.

You need something that turns on when the signal is below 0V, not below 4.3V (which yours is).

The easiest to explain without any op-amp or comparator like chips would be a 3-transistor discrete solution:

simulate this circuit – Schematic created using CircuitLab

When the input is 0V the Emitter-Base voltage of Q1 is 0V and Q1 is off. This means R4 pulls the Q2 to off, which then means R6 can pull Q3 to the off state.

Then the input is below -1V the Q1 will start turning on, it will then power up Q2 (since GND is higher than -5V), when Q2 is on, Q3 will also turn on and +5V will show on the output. When all transistors are off R7 will pull the output to 0V.

Another option, using a single LM311 analogue comparator, would simply be:

simulate this circuit

You can connect the -5V to VEE, the +5V to VCC and the 0V to GND. The chip will then pull the output to 0V/GND when the - input is higher than the + input. It will not actively pull the output back to VCC, so you need to add an external resistor to do that. You still need to connect VEE to -5V, because else the input voltages cannot be negative.

R1 and R2 make the + input a little below 0V, using the -5V rail. Then if the - input is at 0V the output will go to 0V, because the + is lower, if the - input goes to -5V it will be below the + input, so the output will go to +5V.

There are transistor tricks to use to achieve your purpose with fewer components and no comparator, but I don't think this is the point to start talking about more complex things. Get this working first.

Having used a proper simulator rather than the CircuitLab one, it seems I got that completely wrong (the CircuitLab thing gave the results in the original answer which are completely wrong!). The below circuit would actually map to $V_{IL} = 1.8\mathrm{V}, V_{IH} = 3.4\mathrm{V}$.

Unfortunately that means it is outside what would be considered a logic 1 and a logic 0. You can adjust the resistor values, but the closest you can get is to set the lower resistor to be $33\mathrm{kOhm}$ but that would leave you with $V_{IL} = 1\mathrm{V}, V_{IH} = 3\mathrm{V}$ which is fine for a logic 0, but is pushing what would be a logic 1.

Now what you could do is adjust the resistors further to get $V_{IL}$ to 0 and then feed that signal into a transistor to act as an inverter. I've draw up the revised circuit below. Note that the transistor needs to be a logic level MOSFET which will be on sufficiently to drive the output low when $V_{gs}$ is above $1.5\mathrm{V}$.

simulate this circuit – Schematic created using CircuitLab

I'm leaving the old answer here for reference, but beware, it won't actually do what was expected!

Of course depending on what the signal is, there is a really simple way to do it.

The following circuit assumes that you have an input signal which is 0V to -5V digital and is feeding a digital input using standard +5V CMOS logic levels. This circuit will map your signal ($V_{OL} = -5\mathrm{V}, V_{OH} = 0\mathrm{V}$), to a compatible digital signal of $V_{IL} = 1\mathrm{V}, V_{IH} = 4\mathrm{V}$.

• @xDarcade See my revised answer, got it wrong unfortunately - always double check simulations! – Tom Carpenter Jul 25 '15 at 15:10