How to use a signal from mains to control a DC relay?

AnalogKid

Joined Aug 1, 2013
9,188
Work backwards. The relay takes 30 mA. The transistor gain is around 100, but for firm saturation you want to overdrive it. The rule of thumb is 10:1; for 30 mA collector current you want 3 mA base current, but that rule is from the 1950's. Your relay will operate just fine with a base current of 1 mA, so let's use 1.5 mA (20:1). This is the current through the HCPL817 output transistor.

The ratio of the 817's input LED current to its output transistor current is called the CTR (Current Transfer Ratio). To get 1.5 mA of output current, the input current must be 1.5 mA at 100%, 3.0 mA at 50%, 7.5 mA at 20%, etc. The 817 has a range of CTR values depending on the operating conditions, from 50% to 600%. Looking at the datasheet chart, it has a typical CTR of 100% at 2 mA. 2 mA in, 2 mA out, we need only 1.5 mA, sounds good. ... But wait.

To charge up C1 and drive Q1 with base current takes more than the 1.5 mA. A rough calc puts it at around 5 mA for a 4.7 uF cap. A look at the chart indicates that at 4 mA input current the CTR is around 130%, for an output current of 5.2 mA. Reducing C1 to 2.2 uF cuts this in half. Charging up the cap completely in the first half-cycle prevents the relay contacts from chattering if the cap is charged up incrementally over a number of cycles. This is important only at turn-on because the capacitor is not completely discharged every half-cycle.

For now I'd go with a 2.2 uF cap and 2 mA input current. I'll chew on this more later today.

ak
 

DickCappels

Joined Aug 21, 2008
7,288
A, almost 2:1 range of the AC input voltage:

ak
Choosing the right relay would probably solve that problem, or adding a little bit of rectification and a capacitor to increase the average voltage is another way to go, but not nearly as much fun as developing the circuit under discussion.
 

sghioto

Joined Dec 31, 2017
2,335
1613408297343.png
1613410085221.png
Using ak's circuit it would more feasible to move C1 to the output of the bridge. Then you don't have to deal with the charging current through the opto.
I can tell you from testing the Q1 circuit that the base current is much less then .5 ma.
From the chart you can see a Ic current of .5 ma with a Forward current of 1.25 ma the voltage drop is less then .5 volt
Therefore you can increase R1,R2 to 47K each at 1/2 watt.
I have some bridge rectifiers
Looks like a B250 bridge, rated 250 RMS and .9 amp, should be fine.
 
Last edited:

Jon Hoover

Joined Oct 10, 2019
33
Just thinking outside the box. What if you ran your entire espresso machine off a battery/inverter combination and then connected a full time charger to your battery to keep it charged between cups of coffee? The charger should be able to use whatever voltage comes into it and would output 12 volts to the battery to charge it. Not sure if you thought about this scenario or not. It seems like it would work and it would be all "off the shelf" parts that should be easily sourced no matter where you are located.
 

anniel747

Joined Oct 18, 2020
612
Just thinking outside the box. What if you ran your entire espresso machine off a battery/inverter combination and then connected a full time charger to your battery to keep it charged between cups of coffee? The charger should be able to use whatever voltage comes into it and would output 12 volts to the battery to charge it. Not sure if you thought about this scenario or not. It seems like it would work and it would be all "off the shelf" parts that should be easily sourced no matter where you are located.
That's called a UPS.
 

AnalogKid

Joined Aug 1, 2013
9,188
Using ak's circuit it would more feasible to move C1 to the output of the bridge.
Disagree. Placing the holdup cap across the LED has the same problem as placing it across the Q1 base-emitter junction - the operating voltage range of the cap is very small, requiring a much larger cap for the same holdup time.

The 817 typical forward voltage is 1.2 V. A datasheet plot indicates that at room temperature, the diode cuts out at approx 1.1 V, so we'll round this down to 1.0 V for margin. Worst case, the cap has to hold up the circuit for one half-cycle, or 10 ms, supplying 2 mA, while the cap voltage decreases by only 0.2 V. With the cap located in my schematic and the same conditions, the cap can discharge from 11.9 V to 0.7 V, a swing of 11.2 V. Yes, the actual discharge current is not constant, and yes, the power line is supplying some current for most of a half-cycle. But the energy storage issue is the same.

One could argue that the "right" way is to drive Q1 with a constant-current source circuit powered by the holdup cap; this would allow the smallest cap value for any given holdup time. But that's pretty complex for this level of problem.

ak
 
Top