# 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

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:

#### anniel747

Joined Oct 18, 2020
612
An almost 2:1 range of the AC input voltage:

ak
That is still way within the range of most must operate voltage range.

#### anniel747

Joined Oct 18, 2020
612
You do know that a SSR would take care of all this, right?

#### sghioto

Joined Dec 31, 2017
2,335
You do know that a SSR would take care of all this, right?
At what price?

#### anniel747

Joined Oct 18, 2020
612

Joined Jul 18, 2013
22,866
SSR are cheap and more reliable.
The circuit in #23 IS a SSR !, just remove the relay and replace the Q1 with a high power Mosfet.
Max.

#### sghioto

Joined Dec 31, 2017
2,335
OK post a link to one you think will work.

#### 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.

Joined Jul 18, 2013
22,866
I realized after I posted it was switching AC, so why not take a leaf out of the Fairchild AN-3006 AN-3003 and just use a MOC316x and a Triac? (SSR).
Max.

#### 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.

#### anniel747

Joined Oct 18, 2020
612
I realized after I posted it was switching AC, so why not take a leaf out of the Fairchild AN-3006 AN-3003 and just use a MOC316x and a Triac? (SSR).
Max.
Because everyone here wants to be innovative and reinvent the wheel.

#### sghioto

Joined Dec 31, 2017
2,335
Because everyone here wants to be innovative and reinvent the wheel.
No. The TS wanted a solution using parts on hand mostly.
Read paragraph 5 on post #1.

#### anniel747

Joined Oct 18, 2020
612
No. The TS wanted a solution using parts on hand mostly.
Read paragraph 5 on post #1.
He doesn't give an exhaustive list of the parts he has on hand. He clearly is in a communist country but even there copies of MOC and TRIAC are available.

#### sghioto

Joined Dec 31, 2017
2,335
He posted enough to get the job done.

#### sghioto

Joined Dec 31, 2017
2,335
What if you ran your entire espresso machine off a battery/inverter combination
The issue there is the 1400 watt heater element which the TS mentioned works OK on the voltage variations.
The pump is only 48 watts.

#### anniel747

Joined Oct 18, 2020
612
He posted enough to get the job done.
Good, then move on, nothing more to see.

#### sghioto

Joined Dec 31, 2017
2,335
Good, then move on, nothing more to see.
We did until you joined in.

#### 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