Making A Solid-state Relay With I2C Interface

As [Mic] often got requests to make high-power switching boards, he recently finally gave in and designed the one shown above based around a solid-state relay. Some of our readers that already play with mains power know that switching should normally occur when the voltage crosses zero volts. The ‘TRIAC BLOC’ is able to do so, which also allows mains frequency measurement. [Mic] then tuned to the internal oscillator of his ATtiny microcontroller with this 50Hz by adjusting its OSCCAL register value, so the switching command can be sent at the ideal moment. Zero crossing detection is implemented by feeding the mains into an AC optocoupler. [Mic] discovered that the optocoupler diodes are not identical, so he had to adjust his firmware to account for the time differences.

All the resources are available on github, we would be interested to hear your detailed analysis of the circuit implemented with the passives R3/C1/L1/R8/C3.

34 thoughts on “Making A Solid-state Relay With I2C Interface

  1. Nice rigor on all the math!

    Shouldn’t you expect the off time to be the same as the twice-previous zero crossing? Or when you said “the same length as the previous one” that’s what you meant? (same length as the previous one in the same direction)

    At some point in the past I’d sat down and characterized a specific incandescent bulb to get a mapping of “% duty” to “perceived brightness”; human photopic response and resistance-as-a-function-of-temperature.

    1. Yes, exactly, each pulse was similar with the one two ago. In other words, pulses for the same leds are similar in length. But it depends on pullup value used. For a bigger pullup I don’t get two distinct peaks in hystogram, so they are appearently close enough to each other.

      Regarding perceived brightness – i’ve checked on the stuff recently – interestingly enough it goes back to greece and perceived star brightness. I should put my power values thru another function get a perceived linear dimming. I dont’ remember exactly now, it has something to do with 2.5^x.

    1. Connecting with bolts and ring terminals is not that uncommon in product design and the solution works well providing you use the right hardware. The ring on the board, the ring terminal & the bolt size need to match, plus you need a good star type lock washer under the nut.

      But it’s just as important to use the right crimper on the terminal & to make sure the crimp is tight. The easiest way to do this is to use a ratcheting type crimper that forces you to do a full crimp then to grab the ring terminal in one hand & pull the wire back & fourth. Any movement in the free end of the wire is a failure & the terminal needs to be cut off & re-crimped.

    1. You mean with a coil and switches? That’s not what a solid-state relay is, the clue’s in the name! An SSR is really just a triac + zero-crossing sensor + whatever support components.

    2. Who would have thought that you’re so important that the 30 seconds needed to read this article would be significant, but not so important that the next 30 seconds needed to post your reply wouldn’t be significant.

      1. I’d make my own relays, if I had any valid excuse at all to do it. And the tools and skill to make all the little fiddly lever bits.

        One day I might save up for a decommissioned crane electromagnet, and make myself a relay out of girders and bits of car. I’d use it to switch power stations.

  2. You can avoid the huge resistors for the optocoupler by using a series capacitor to limit the current. Also, I would just use an optocoupler with a single LED, and put an anti-parallel diode on the outside (to avoid reverse voltage breakdown of the LED). The CPU can measure the mains frequency, and calculate zero crossings with a timer.

          1. I have used this method with a series capacitor in a couple of products, and never had any trouble with distortion. Of course, you can’t count on the mains frequency to be a clean sine wave anyway. There could be distortion from heavy or non-linear loads on the same circuit, as well as big transients, so a suitable low pass filter is recommended.

  3. The oscillator calibration trick is cool, but I’m not sure what it buys you. Assuming that you are running on the internal RC oscillator at ~8 MHz and your mains frequency is 50 Hz, each mains half cycle is ~100k clocks. Your worst-case misalignment without calibration (1 clock) is ~3e-5 radians. Assuming 240V RMS, you are, at worst, 10 mV off the zero crossing. What about the application makes scrubbing out that 10 mV worth the effort?

    I really like the work you did on sussing out the errors with the zero-crossing detection.

    1. If he’s trying to trigger at zero-crossing, but there’s still voltage detected, then wouldn’t his timing be off? Correcting for the voltage error would allow him to properly detect when the voltage would be zero just before it occurs. This would help prevent any wasted power dissipation.

      1. You will never switch perfectly at 0V, since nothing is perfect. The proper engineering question to ask is how close to 0V is good enough? Now, if the uC clock really is the limiting factor on your precision, you can figure out how much the mains voltage changes in 1 clock… and it happens to be 10 mV. That’s out of a 240V RMS/340V peak. It hardly seems worth the effort, so I was asking why.

        If you want to be achingly precise about correctly estimating the exact instant of zero crossing, the right approach is likely a single LED optocoupler (so you only get half the waveform) combined with a PLL to synthesize the zero crossings.
        -p

  4. If I understand this circuit correctly, it can also be used to switch american two phase 220v loads, with L1 on phase and L2 on Neutral. Something I have not been able to do with regular SSRs.

      1. For North American 220, both legs are hot. When a regular SSR tries to switch the load, it fails to find the zero crossing. One leg of the SSR is direct to hot, the other hot via the load. It tends to work ok for a resistive load, but when you try to switch a motor, nothing happens. Something is messing with the SSR’s ability to find the zero crossing point. With this circuit, it switches one leg, but sees both sides direct without intervening load. Place the second power leg on the neutral post.

        1. It has nothing to do with the North American 220V. It’s only a matter of reference if a leg is hot or not. As long as the neutral (or ground) isn’t connected the SSR had no way of telling it’s connected hot or not. The problem then is in the fact it’s an Inductive load. The TRIAC stops conducting when no current is flowing. With a inductive load that’s not at the zero crossing of the voltage…

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.