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

AnalogKid

Joined Aug 1, 2013
10,986
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
10,153
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
5,377
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
34
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.
 

AnalogKid

Joined Aug 1, 2013
10,986
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
 

sghioto

Joined Dec 31, 2017
5,377
requiring a much larger cap for the same holdup time.
Not really. I tested the circuit on 120vac (which would be worst case for the TS) using a 4.7uf cap with 47K resistors and a LED to simulate the opto.
The DC across the the LED had very little ripple, well below affecting the relay circuit.
 

Thread Starter

Bhante

Joined Dec 15, 2009
64
So what about putting in both capacitors, one 4.7uF after the bridge, and one 2.2uF after the opto? Would that be advantageous?
 

Thread Starter

Bhante

Joined Dec 15, 2009
64
I want to turn the circuit around the other way, and cut off the heater from the coffee machine, so that I can run the entire coffee machine - minus heater - from the inverter.

The heater (R5) is already modulated by an SSR, 240D25-17 made by Opto-22. Originally I had a PWM signal coming from an Atmega328, though that was zapped by bad power at some point; however I have more of those I can put in. I would need some kind of gate between the opto and the SSR. Maybe the best way is just to put the collector of the BC338 directly on the IO pin of the MCU with the PWM signal, would that work?

The SSR needs at least 3V input (max 32V), and requires only 2mA (actually 4mA at 5V unless an external resistor is added). It can be driven directly from the MCU IO pin without any problem, but I still need switching from Opt1. See datasheet P10. Obviously the terminals labelled "Inverter AC 1 and 2" are the internal connections in the coffee machine where the heater would otherwise be connected. The PWM signal is an additional level of temperature control separate from the built-in control, intended for PID. Changes necessary to R3 and C1?

Before I was using the 12V relay, so those 12V supply connectors I want to bring down to the 5V of the MCU, using the same power supply (module shown below, generating fixed 5V supply from mains AC.

PS - Actually the neon should more logically go across the heater terminals rather than the inverter input.
 

Attachments

AnalogKid

Joined Aug 1, 2013
10,986
Based on the SSR datasheet, you can eliminate Q1 and D1, and drive the SSR directly with the optocoupler output transistor.

At 130 Vac input, the current through the opto LED is less than 2 mA. The datasheet states that the minimum CTR is 50%, which means less than 1 mA through the output transistor. I recommend decreasing R1 and R2 to increase this current. If you want to drive the SSR directly, the minimum opto output current should be 5 mA.

I also recommend returning C1 to the secondary side of the optocoupler.

ak
 
Last edited:
Top