Go Down

Topic: Voltage Comparator Operation with 12V input to 3.3V logic LM339/LM393 (Read 209 times) previous topic - next topic

tomb098123


Hi,

I'm trying to implement something similar to the following instructable to measure the voltage from the PIRs connected to my house alarm system. https://www.instructables.com/id/Alarm-PIR-Movement-to-Home-Automation/

The instructable states to use an LM339, the LM339 output is connected directly to the Digital Input on an Wemos D1, as INPUT_PULLUP. With Vcc connected to the +12V source.


The Power source I have is 13.7V DC.

PIR will general voltages 4.6V - IDLE, 6.4V - triggered or 12.8V disconnected. Latter two are both alarm states.
Reference voltage I then need to set to 5.5V (half way between 4.6 and 6.4), for which a I use a voltage divider, 3.3K and 2.2K to give 5.48V.

As I understand the voltage comparator, if the +Vin is less than or greater that the -Vin, it will either connected(synced) the output to Vcc or Gnd.

If I set this up on a breadboard I observe that the output is synced to 13.7V or Ground. If I connect this output to one of the Wemos D1 digital inputs (3.3V logic) with a 10K pull-up to 3.3V - isn't the 13.7V going to fry the D1?

If that is true:
Changing the Vcc to 3.3V doesn't seem an option as the LM339 spec states  the Vcc must be 1.5V above the input voltages. Should I add an optocoupler between the LM339 and Wemos?



JCA34F

Would something like this work for you? Adjust trimmer to trip point (5.5V?).

6v6gt

Quote
The instructable states to use an LM339, the LM339 output is connected directly to the Digital Input on an Wemos D1, as INPUT_PULLUP. With Vcc connected to the +12V source.
That is not as bad as you appear to think. Vcc for the comparator is NOT Vcc for the Wemos device.
The LM339 is an open collector device so the output voltage is not related to the voltage supplied to it.
The output is effectively an NPN transistor with the emitter connected to ground, and the collector pin exposed as the output pin. It is either strongly pulled to ground or floating, depending on the state of the 2 inputs. That is why on the Wemos you have to use INPUT_PULLUP so it does not float.

If you attempt to measure the voltage at the output pin of the LM339 (meter connected between ground and the output pin with nothing else connected to the output pin), you will see zero volts regardless of the state of the inputs.

Paul__B

Would something like this work for you? Adjust trimmer to trip point (5.5V?).

Given that the opto-coupler is mounted close to the Arduino, the 10k pull-up resistor is unnecessary.  You use INPUT_PULLUP on the Arduino pin.

aarg

You don't need an optocoupler. There is no problem with connecting the 339 output directly to the Arduino input with the input pull up enabled, as you have described. As long as your PIR 12V and Arduino supply can share a common ground connection, you're fine.
  ... with a transistor and a large sum of money to spend ...
Please don't PM me with technical questions. Post them in the forum.

Go Up