I have designed and implemented an HVAC monitoring solution using an Arduino Mega, a W5100 Ethernet Shield, and a bunch of 24vac relays ... and it's working well.
I'm now designing ver.2 of this, with the hopes of significantly shrinking the project. So moving to a Teensy LC instead of the Arduino Mega, an ESP8266 WIFI module instead of the Ethernet shield, and hoping to use PC817 opticouplers in place of the 24v relays.
My question is around the circuit for the opticouplers. My code is designed to use Digital input pis with the internal pull-up enabled. Right now, my design is setup so when a 24vac HVAC signal wire goes hot, it triggers a 24vac relay which connects the Arduino GND to the digital input pin (with pull-up enabled).
In keeping with this approach, I think I can use a simple component design and connect the GND from the Teensy (or from the Arduino) to pin 4 of the PC817, and simply connect pin 5 of the PC817 directly to the digital input pin of the Teensy (or Arduino) with the internal pull enabled.
I'm looking for confirmation my thinking on this is correct though, as this is new territory for me. My assumption is when the opticoupler's input has no signal, the input pin will be pulled HIGH through the internal pull-up. When the opticoupler's input receives a signal, it should connect to ground and send the input pin to LOW.
So question 1 is .... Do I have the above right?
Question 2 relates to what value resistors to use for the 24vac input to the Opticoupler (R1 and R3 in the attached diagram). I have the PC817 chips here, and did some preliminary testing with 5vdc. a 220ohm resistor drops the voltage to 1.2vdc when the opticoupler's input is connected, and produces a good result on the Opticoupler's output.
So the mA draw looks to be right around 22mA.
If I use 22mA as a load value, and do the math on dropping 24v to 1.2v, I'm getting around a 1036 ohm result. If I change that to 1 kOhm, I get 24mA.
Considering the PC817 seems to be good for up to 30mA (if I'm reading the datasheet correctly), it looks like 1kOhm total resistance is what I want here. So two 500 Ohm resistors in series, just fr added protection.
Question 2 is ... Do I have this calculation right?
Thanks for any input