Hey guys, I am trying to use a wemos d1 mini to monitor an existing door sensor on my home alarm system. When the door is open, the positive wire from the sensor is at 10.5v, and when it's shut it reads 4.5v
The D1 mini only has 1 analog pin and I have 3 doors I'd like to monitor, so my thought was that I could use voltage dividers to get the 4.5v "closed" voltage to 1v or less, which would allow me to use the digital pins. Is this feasible, or do I need to do some totally other... thing? Help please!
Can the sensor supply some current for an opto-coupler ?
That is the safest solution.
A voltage divider should work as well, but I would prefer to lower the lowest voltage to 0V. Perhaps with a transistor with three resistors that turns on at 7V, and the collector to an digital input. The signal would be inverted, but that can be solved in software.
Ok let's see if I've done my googling correctly. A pc817 photocoupler has a forward voltage of 1.2-1.4 volts and a 50ma max forward current. So according to the led calculator I found, I plugged in 9v source current, 1.3v forward voltage and 30ma forward current and it says the resistor value should be 256 ohms and the power is .23W
So.. if someone could fact check that and help me with how to wire it up? That's a 275 ohm 1/4 watt resistor on the positive leg of the PC's input side?
All of the zones have a screw terminal for high and low, and it says on the schematic to put a 200ohm resistor across the high/low terminals for all zones.. so I assumed that's what causes the 4.5 volts, but I'm not very knowledgeable about this stuff so it could be for some other reason. I don't think they're matrixed but I don't really have any way of knowing, I do know that the 3 doors that I'm wanting to monitor are on their own sets of terminals.
My current problem is that I don't know what components to use or how to hook them up, so do you have an example of how I'd use a 10k opto led cl resistor? And a part number of such a device?
The 10.5 and 4.5V are too close to each other. The 10.5V is only 2.33 times the 4.5V. When a voltage divider is used, that is perhaps not reliable for a digital pin and not reliable for the opto-isolator.
For the PC817:
A forward current of 1 or 2mA will still work as Wawa already mentioned.
It can be done with a voltage divider to change the 10.5 and 4.5V into 1.8 and 0.8V and make use of the forward voltage of about 1V, but that is too close. A trick could be to use the 3.3V, but I don't want to push current into the 3.3V.
I think that you should use a zenerdiode. You can use the opto-isolator for safety or a digital pin without opto-isolator. In both cases use a zener diode.
With a opto-isolator: a zenerdiode of 6.2V and a resistor of 2k2 ohm for an If of about 1.5mA. On the WeMos side for example a pullup resistor of 4k7.
With a digital pin, first a zenerdiode of 6.2 V followed by a voltage divider for example with R1 = 1k and R2 = 3k3.
As an alternative you can use a voltage divider (two resistors) and the analog input without zenerdiode. For example R1 = 4k7 and R2 = 2k2, that will lower the 10.5 V to 3.3 V. Even a multiplexer is possible to read many analog signals.
Any opto will do. You mentioned a pc817.
Emitter of the opto transistor to Wemos ground, collector to Wemos digital pin with PULLUP enabled in pinMode.
Opto LED is just like a normal LED. Anode to positive alarm voltage, cathode to negative voltage or ground, with a (10k) current limiting resistor either in the positive or the negative line of the LED.
When the opto LED is lit, the opto transistor pulls the Wemos pin to ground.
Otherwise the digital pin is internally pulled high.
Maybe wise to try first if you can get a reliable on/off indicator with a common 3mm red LED + 10k resistor.
Leo..
bkcberry:
All of the zones have a screw terminal for high and low, and it says on the schematic to put a 200ohm resistor across the high/low terminals for all zones.
This resistor is likely to be fitted as part of an anti-tamper system. The control panel may check that the resistance does not go outside certain limits.
The loading effect of any additional circuit might adversely affect its operation.
You might have to use relatively high resistor values to minimise the loading, or change the 220Ω resistor value to maintain the correct voltage.
Just warning you of this in advance, in case it becomes an issue.
Analog comparators. These are like op-amps, with two inputs ("+" and "-") and one output. They come in chips with 2, 4, 6 etc on a single chip. Each comparator compares its two inputs. If input "+" is higher than "-", the output is high, otherwise low. Power the comparator chip at 3.3V and the outputs can connect directly to Wemos digital inputs. Use a voltage divider to get the 10V down to 3.3V and connect that to the "+" comparator input. Connect a trim pot to the "-" input.
Wawa:
Any opto will do. You mentioned a pc817.
Emitter of the opto transistor to Wemos ground, collector to Wemos digital pin with PULLUP enabled in pinMode.
Opto LED is just like a normal LED. Anode to positive alarm voltage, cathode to negative voltage or ground, with a (10k) current limiting resistor either in the positive or the negative line of the LED.
When the opto LED is lit, the opto transistor pulls the Wemos pin to ground.
Otherwise the digital pin is internally pulled high.
Maybe wise to try first if you can get a reliable on/off indicator with a common 3mm red LED + 10k resistor.
Leo..
Thanks! I think this is what i am going to try to do
the positive wire from the sensor is at 10.5v, and when it's shut it reads 4.5v
Start here, why you have 10.5V and 4,5V not a 0V and 6V, post the circuit for that.
ted:
Start here, why you have 10.5V and 4,5V not a 0V and 6V, post the circuit for that.
That 4.5V is of course to see whether the sensor is connected and working. Same reason you see the 4-20 mA signal (and not 0-16mA).
Knowing a sensor is present and working is a very important thing in many applications. Getting a zero signal can mean a switch is open, it can also mean the switch is disconnected entirely.
A comparator sounds like the way to go. You could even add a second comparator to also detect the presence of the low signal.
Hey guys, I got some time to work on this tonight and the circuit that Wawa described worked perfectly, but unfortunately as someone else said the alarm noticed my hackery and threw a fault while the Arduino was hooked up. So, as Ted said, I will try a comparator next. Amazon sells TI LM393 in a 10 pack for $4, and each one is actually 2 comparators, so I figure I'll give those a shot.
I've read some about these and pretty sure I know how to hook it up, but just wanted to ask you guys bc I haven't done a lot of this stuff. Will I do-
VCC - +5v from Wemos
GND - wemos
Pin 1- output 1 - wemos digital input pin
Pin 2 - in 1 (-) -- +4.5v reference
Pin 3 - in 1 (+) -- +12v door sensor
The alarm has a 12v backup battery, so my thinking was that I could run the wemos off of that with a car usb charger, and the wemos would share a common ground with the alarm thru that.
Electronics seem to need resistors like nuts and bolts need washers.. do I need some here somewhere? Maybe a resistor on the door sensor pin so that when it's resting at 4.5v closed state it reads lower than the reference pin?
It seems to me that the way this works is that while pin 3 is below the voltage of pin 2, the output pin 1 will be pulled to ground. And when pin 3's voltage rises above pin 2's, then outpit pin 1 will go high. Is that correct?
Thanks guys, I really appreciate all the help thus far
bkcberry:
but unfortunately as someone else said the alarm noticed my hackery and threw a fault while the Arduino was hooked up.
+1 for a well designed alarm! I guess it detects a current drawn from the +10.5V level, when no current should be there.
VCC - +5v from Wemos
GND - wemos
Pin 1- output 1 - wemos digital input pin
Pin 2 - in 1 (-) -- +4.5v reference
Pin 3 - in 1 (+) -- +12v door sensor
Won't work like this. Comparators usually can not handle voltages on their inputs higher than Vcc +0.5V and lower than GND -0.5V. Your inputs are +10.5V or +4.5V, so you have to do it a little different.
You mentioned you have a 12V power supply available. Use that to power the comparator. A voltage divider between the +12V and the negative input, set this to something in between, 7.5V or thereabout. GND - 33k - 22k - 12V gives you 7.2V reference which is great. If the 0.2 mA current that flows through this divider is too much for you, increase the values, but the comparator may become unstable if they're too great (a small cap, 100 nF or so, between reference and GND can help in that case).
So now you have a comparator that produces +12V or 0V. The easiest way to interface with your NodeMCU is a diode between NodeMCU and comparator output pointing towards the comparator, and then enable the internal pull-up. This way any voltage >3.3V will be blocked by the diode (and you read a high signal), while the comparator can pull the pin low.
For additional safety you may add a resistor (1k-10k is fine) between the diode and the pin. This as if you accidentally set your pin to OUTPUT, HIGH while the comparator is low, you create a short. The resistor makes sure nothing gets damaged.