0
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ – KarlKarlsom Jan 9 at 3:01
  • \$\begingroup\$ It’s a hobby project \$\endgroup\$ – orange Jan 9 at 21:14
2
\$\begingroup\$

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.

enter image description here

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.

\$\endgroup\$
1
\$\begingroup\$

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:

enter image description here https://www.electronics-notes.com/articles/analogue_circuits/operational-amplifier-op-amp/comparator.php

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. :)

\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$ – Adam Q Jan 9 at 3:46
  • \$\begingroup\$ Note that this circuit requires the comparator to be powered from a voltage higher than the input signal, probably 15V in this case. \$\endgroup\$ – Mattman944 Jan 9 at 8:59
  • \$\begingroup\$ Unfortunately, the max power supply voltage is the same as the signal voltage. Anything I can do? \$\endgroup\$ – orange Jan 9 at 12:16
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Adam Q Jan 9 at 13:44
0
\$\begingroup\$

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.

schematic

simulate this circuit – Schematic created using CircuitLab

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

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.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.