# Convert digital 12V/7V inputs to 3V3 levels

I'd like to read the digital inputs of my alarm sensor into a microcontroller (mainly PIR and Reed switches). The alarm system and the sensors operate at 12V (actually a tad higher) and the MCU uses 3.3V. I also noticed that the PIRs provide an idle signal of ~7V (no motion) and an alarm signal of ~13V.

My question is, how would I go about safely reading the sensor values into the microcontroller. I found a few voltage divider examples, but they don't take into account the idle voltage (i.e. they scale 12V/0V to 3.3V/0V). The idle signal can also vary between PIRs, so I might need an adjustable (potentiometer?) solution. Any help would be appreciated.

• The answer depends a little bit on your project. Is it for a home project or an industrial application? I'm asking, because for a home / hobby project you can expect much less noise etc. then in an industrial application. – KarlKarlsom Jan 9 at 3:01
• It’s a hobby project – orange Jan 9 at 21:14

Here is an example of a robust design I have used in industrial product designs that allows interface of sensor inputs that range over a wide voltage swing to safely interface to 3.3V microcontrollers. In this example the reference threshold voltage is set for about 2.4V so that the inputs can accept signals with swings from 0->3.3V up to 0->15V.

Whilst this design does provide a good bit of noise isolation for the MCU from the input signals it is still necessary for the highest level of robustness to provide for higher level ESD filtering before the inputs to this circuit.

For your inputs that swing from 7V to 12V you may want to check to see if adding a pulldown resistor of a few K ohms would lower that 7V idle level to closer to GND. If not then you could replace the input 2.2K resistors with a pair as a divider that brings that 7V level down way below the 5V clamping action and then possibly raise the REF_IO voltage a little.

Simple answer: use a comparator with a voltage-divider reference.

A comparator is a device that outputs a HIGH voltage if the input is above the reference and a LOW voltage (i.e. zero) if the input is below the reference. You can use a voltage divider to set the reference equal to, say, 10V. That way, 12V will be above the reference (HIGH) and 7V will be below the reference (LOW).

Here's a picture from the Electronics-Notes.com tutorial on comparators:

You can either buy a comparator that outputs a 3.3V/0V signal, or you can buy a comparator that outputs at XV/0V signal, and then use techniques that you already know to convert XV down to 3.3V.

Hope this helps!

EDIT: If you need an adjustable reference, just replace R1 or R2 with a potentiometer. :)

• Note: Michael Karas's answer is also fundamentally based on the same principle (comparators), but I'm guessing that you don't need all of that extra circuitry for your application. – Adam Q Jan 9 at 3:46
• Note that this circuit requires the comparator to be powered from a voltage higher than the input signal, probably 15V in this case. – Mattman944 Jan 9 at 8:59
• Unfortunately, the max power supply voltage is the same as the signal voltage. Anything I can do? – orange Jan 9 at 12:16
• Several options: (1) If you use a "rail-to-rail" op amp like ti.com/product/OPA2743 for your comparator, then you CAN power it from a voltage equal to the max signal level. (2) Alternatively, just divide your 12V/7V down to a 6V/3.5V before inputting to your comparator. – Adam Q Jan 9 at 13:44

A simple clamp may be all you need. Low voltage zeners have a soft knee so you want enough current to get past the horizontal part of the I-V curve (don't make R1 too large).

Changing the voltage level may not be your only concern. Long wires may pick up noise from house wiring or large transient voltages from lightning. If you live in an area with a lot of lightning strikes, you may need additional protection.

Edit: added 2nd option for case when idle is not zero.

simulate this circuit – Schematic created using CircuitLab

• Would that switch 12/7V to 3.3/0V (high/low)? – orange Jan 9 at 12:08
• No, this circuit will convert both 12V and 7V to the same voltage, approximately 3.3V :/ – Adam Q Jan 9 at 13:47
• Sorry, didn't read the question carefully enough, added second option. – Mattman944 Jan 9 at 14:24

Voltage divider with input Hi-impedance amplifier (op-amp) would work. the previous suggestion of using AM26LV32 is OK solution. be aware the device is only 5V tolerant, and MAX input (absolute MAX) is 8V according to datasheet. you don't want exceed that spec.