Power relay and pwm output?

When I played with LED dimming with the arduino, I could output analog values that would cause a dimming and flashing effect. How can this be done with a power relay? Is it even possible? Or does the relay just switch the LED or whatever device on and off?


Relays and PWM often are a bad combination, the mechanics of a relay are too slow to keep up with the PWM-signal. You can… PWM a (DC-only !) solid state relay, but it’s probably easier/cheaper to use a transistor to handle higher voltages/currents.
By the way, keep in mind that max current for an arduino-pin is about 40 mA, most mechanical relays will draw more current as that. Even in an on/off (non-pwm) configuration it’s there for wise to use a transistor to control a relay.

Relays are on/off devices (an electrically controlled switch).

PWM is on/off too, but it's faster than a mechanical relay can respond (and faster than your eye can detect).

How can this be done with a power relay?

Are you trying to dim/control AC power?

If you are switching DC, a solid state relay is usually fast enough for PWM. (You'd have to check the specs.) But if you are switching 50/60Hz AC power, there are special considerations and PWM will NOT work! Some AC relays won't turn-on except at the AC zero-crossing, and most will only turn-off at the zero-crossing.

If you are dimming AC power, you typically use something like PWM, but it's synchronized to the AC line frequency.

I'm trying to dim DC power- so i understand a mechanical relay will not work but is there any advantages of using a solid state relay over a transistor or vice versa?


Transistor is much cheaper, but it can be more work to find out which one and which extra components to use. Standard It doesn't insulate arduino electrically from the load, it is possible, but you'll need a small circuit using opto-couplers.

Solid state relays are expensive, they're often (!) electrically insulated though which should prevent your arduino to blow up in case of an error/overload. It may also be easier to buy one by simply checking what voltage your project uses, how many amps will flow and buying an SSR that's at least capable of handling twice as much power. (running a project at 100% of it's max capacity is never a good idea)

Which one is better is hard to tell, because of their price I... prefer transistors over SSR.

Use a logic level n-Channel Mosfet power transistor. ‘Logic Level’ means that the transistor can be directly controlled from an arduino pin. I have controlled 8v/7A pwm in this manner with no problem with IRLU024NPBF from Digikey.
Because of the extemely low on-resistance of Mosfet’s, a heat sink may not be necessary.

Hi voltage is the only reason for using a solid-state relay. The optoisolator can keep a dangerous voltage from smoking the Arduino.