# Convert 5V (low) 10V (high) logic to 3.3V or 5V

I have a sensor that outputs 5V for low and 10V for high. I'm trying to use it on a GPIO input pin, but it doesn't seem that a voltage divider solution exists which would drop 10V to 5V or 3.3V, and 5V to 0.

Does anyone know a way to achieve this?

ingenium13: I have a sensor that outputs 5V for low and 10V for high. I'm trying to use it on a GPIO input pin, but it doesn't seem that a voltage divider solution exists which would drop 10V to 5V or 3.3V, and 5V to 0.

Does anyone know a way to achieve this?

Would be really helpful if you identified the sensor and a link to the data sheet describing it. What is powering the sensor and do you have access the the sensor ground or common connection to it's power?

The Arduino pin does not have to be 0 volts to be a "zero". But the pin cannot go above 5. So, if you can drop the voltage to less than 1/2 the measured voltage, it would work. I don't have the value that would work for zero right here, now.

Paul

Yes, it's always best to know which sensor you're using, so we don't have to guess and/or give the wrong advice.

Reading the voltage divider (e.g. two 10k resistors) with an analogue pin could be a solution.

if(analogRead(A0) > 768) someVariable = HIGH; else someVariable = LOW;

Leo..

Run it thru a 2:1 voltage divider (I'd go with two 5Ks), for 2.5V and 5V, then read it with analogRead(), for reliable results. Reading of ~512 = 5V, ~1023 = 10V.

Thanks for all the replies! The sensor is a contact sensor (and motion sensor that reports 5V with no motion and 10V with motion) for a security system. There are 7 total sensors I'm trying to monitor. They're powered by the security system, and unfortunately I can't disconnect them from it. So I'm going to connect in parallel at the circuit board for the security system.

It might be better to have some galvanic isolation for a security system.

You could use opto couplers with a zener diode and current limiting resistor in series for the opto LED. Say a 5.6volt zener and a 1k resistor. Then connect the opto transistor to a digital pin with pull up enabled in pinMode. Leo..

ingenium13: Thanks for all the replies! The sensor is a contact sensor (and motion sensor that reports 5V with no motion and 10V with motion) for a security system. There are 7 total sensors I'm trying to monitor. They're powered by the security system, and unfortunately I can't disconnect them from it. So I'm going to connect in parallel at the circuit board for the security system.

Sounds like it has a security loop, anyone cutting the wire, no 5V or 10V, ALARM.. ALARM..

+1 Didn't think of that. Leo..

Wawa: It might be better to have some galvanic isolation for a security system.

You could use opto couplers with a zener diode and current limiting resistor in series for the opto LED. Say a 5.6volt zener and a 1k resistor. Then connect the opto transistor to a digital pin with pull up enabled in pinMode. Leo..

It's a security system. Too high current - alarm! (I recall a similar issue in a recent thread).

Probably need to add a buffer as well, to not put any extra load on the wires.

Use an analog comparator. (Same solution as in that other thread vwmarle remembers).

Ah, yes, I remember. That was the solution. I think it actually worked for that project.

Do you by any chance have a link to that thread? I can’t seem to find it.

This might be a silly question, but would it be possible to use a logic level converter? Such as https://www.sparkfun.com/products/12009

Possibly tricking it into somehow thinking 5V is ground and 10V is 5V relative to "ground"? Thus allowing 5V to be LOW and 10V to be HIGH.

Why? Is the 1mA load I suggested in reply #3 too much? Use larger value resistors to draw less current.

It shouldn’t be too much, it would just be easier for the project I’m working on for it to be a digital input instead of analog input. The library currently uses interrupt triggering digital inputs, so I’d need to work around that.

As I’m thinking about this more, assuming the security system panel has 10V, 5V, and ground screws, could I use the above board and connect 10V to HV, then connect 5V to GND, and GND to a ground with a resistor in between. Like:

10V <----> HV
5V <----> GND <----> resistor <----> ground

That way the logic level converter would see a 10V input on HV1 as 5V relative to ground (ie HIGH), and a 5V input as 0V relative to ground (ie LOW).

Wouldn’t this work? Or am I missing something?

So you're back to a comparator then. Look at how the LM358 is used in the power selection of an Uno.

A comparator is simple.

Voltage divider (say 15k + 10k on the input for a 2V/4V signal to the + input of an OpAmp, then voltage divider from your 5V Vcc (10k + 15k) for a 3V reference, and you have a high out if the sensor voltage is 10V, a low if the voltage is 5V.

At 10V this voltage divider will draw 0.4 mA, which hopefully is low enough for the security system to ignore - if not try 100k + 150k for a 40 uA current leak.

Dividers are wired as: input voltage - first number - (out) - second number - GND.

Interesting, I had never heard of an op amp before, they weren't mentioned in my EE class.

This seems like it would work. It looks like the LM358 has a greater than 1V drop from the supply, so I'd need a rail to rail op amp. Would the LM6134 work? Or is there something better suited?