Convert Opto detector circuit to straight voltage divider

Thread Starter

tomg7

Joined Dec 5, 2022
7
1677567427146.png

I want to detect if this latching solenoid relay has been activated. The switch is a momentary manual push button. I want presence of 24VAC to produce logic 1 and absence to produce logic 0 (or vice versa it doesn't matter I can invert in software or on PCA9555 config). My original design used a jelly bean opto and it works fine - I can handle the square wave produced in software. But I want to cram 8 of these detectors on to a small board along with the i2c expander. The 8x opto's are relatively huge compared to a couple of SMD resistor arrays. VCC is 24VAC (HVAC transformer) and feeds a 5V regulator for the logic side - shared grounds. I can't change the switch and solenoid and diode part of the circuit. That is an existing system I am tapping into to detect relay state changes into an MCU.
I am struggling with the voltage divider. It seems like when the switch is open the pin would get pulled to 24VAC so would get 34V+ on it.
If the switch was on the high side I think I could figure this out but its on the ground side. I have played with replacing R2 with a 4.6V Zener also. Another idea was to use a ULN2801 (or similar) with 8 channels on one small chip but it seems like its used mostly to go in the opposite direction of low to high and was outside my skill level to figure out.
Any ideas gratefully appreciated.
 

Sensacell

Joined Jun 19, 2012
3,432
If you can cope with the square wave signal- all you need is a single resistor for each line.
Use a 330K ohm resistor from the low end of the coil to the MCU- the input clamp diodes inside the MCU will easily handle the 100 uA current through the resistor, while clamping the voltage to the 5V supply.
When the switch closes, the voltage goes to ground.
 

Thread Starter

tomg7

Joined Dec 5, 2022
7
If you can cope with the square wave signal- all you need is a single resistor for each line.
Use a 330K ohm resistor from the low end of the coil to the MCU- the input clamp diodes inside the MCU will easily handle the 100 uA current through the resistor, while clamping the voltage to the 5V supply.
When the switch closes, the voltage goes to ground.
This is super simple! I will try tomorrow. Thank you.
 

AnalogKid

Joined Aug 1, 2013
10,986
Stefan beat me to it. Note that the solution in post #4 means there will be a small current through the coil in the "off" state. The larger the resistor values, the lower the current; but also, the larger the resistor values, the more susceptible the uC input will be to noise. Life is choice.

ak
 

Thread Starter

tomg7

Joined Dec 5, 2022
7
This is super simple! I will try tomorrow. Thank you.
I tried this and it appears to be working.
I used a 470k ohm resistor because it’s what I had to hand.
Btw I noticed that data sheets sometimes say use current limiting resistor for voltage over vcc but how do we calculate the resistor value?
E.g. data sheet says pin can sink 20mA of current So is it :
(40 - 3.3)/0.02 if we want to put up to 40v on to the pin?
Because this would result in much lower resister value than 330k ohms?
Thanks
 

Thread Starter

tomg7

Joined Dec 5, 2022
7
I would like to avoid current through the coil to be as non intrusive as possible on the original circuit.
A few uA is probably no issue but ideally it would be none.
 

Sensacell

Joined Jun 19, 2012
3,432
I tried this and it appears to be working.
I used a 470k ohm resistor because it’s what I had to hand.
Btw I noticed that data sheets sometimes say use current limiting resistor for voltage over vcc but how do we calculate the resistor value?
E.g. data sheet says pin can sink 20mA of current So is it :
(40 - 3.3)/0.02 if we want to put up to 40v on to the pin?
Because this would result in much lower resister value than 330k ohms?
Thanks
The source and sink currents are for the OUTPUT MODE, you are using the pins as inputs.
The inputs draw almost no current - except when the input protection diodes (internal) start conducting (Vin > Vcc + 0.6 V)

Buried somewhere in the data sheet it will tell you the max current these diodes can carry.
The resistor value is a compromise: too low and the diode current is exceeded, too high and you might have noise immunity problems.

EDIT - I forgot you are using an IO expander, these are WAYYY to slow to do software PWM.
You might generate a PWM on a direct MCU pin and use some gates to mix it into the signal path- a hybrid solution.
 
Last edited:

StefanZe

Joined Nov 6, 2019
191
I would like to avoid current through the coil to be as non intrusive as possible on the original circuit.
A few uA is probably no issue but ideally it would be none.
If you want less current use higher resistor values. 220k und 22k will give you a current of ~100uA at 24V
 

StefanZe

Joined Nov 6, 2019
191
The coil has no freewheeling diode, when turning of this will probably induce a high voltage into the system when turning of, that can damage your components. So you should but a freewheeling diode in parallel to the coil.
 
Top