Can you PWM a relay?

I got this 4 channel relay board: http://www.miniinthebox.com/4-channel-relay-module-with-optocoupler-5v_p903429.html?currency=USD&litb_from=paid_adwords_shopping&gclid=CjwKEAiA-5-kBRDylPG5096R8mASJABqEdm4QiMyKa_3AVUJklufrBZuEIS4uQ-Ih_Eo_gTGkrcCDxoChDrw_wcB

One question I have is, can you safely PWM the opening and closing of the relays with an Arduino? I plan on this to flicker some Christmas lights. I got to work already, but I don't know how fast the switching time could be without damaging the internals of the relays.

Not a good idea.
All mechanical contacts bounce. PWM of arduino analogWrite is about 500 Hz. I can’t find the info on bounce time on neither of two pages of the datasheet, but judging by the quality of those relays (and here I judge quality by the price) this could be a problem. The bounce time could take a significant portion of the duty cycle.

Troubles don’t end here, however.
What the limited datasheet does say, is this:
LifeExpectancy
Mechanically 107 operations
Electrically 105 operations

At 500 Hz, you get through 100 000 operations in about 3 and a half minutes.

Thanks for the quick reply. So the mechanical relays wouldn't last every long if I were to PWM them. How else could I control fast flickering of the AC lights? Or what could I use if I were to switch all of the lights to DC LED's?

For AC you I'd go with a solid state or a triac. It's a bit more complicated than DC, so make sure you do your homework before you start messing with mains.
http://playground.arduino.cc/Code/ACPWM
http://playground.arduino.cc/Main/ACPhaseControl

For DC a MOSFET is enough.

No you can't PWM a relay - that makes no sense, the relay is either on or off. Rapid
switching of a relay will use up its limited life (they are normally rated for a certain
number of switching cycles).

Are these lights mains or DC?

As stated, a solid state relay would work fine. It might look like:

or you can make one. This is a: thyristor-based, zero-crossing, unit. If the lights are incandescent based, there will be amperage inrush, so over size the solid state relay. If the lights are DC LEDs, then you need a mosfet-based product instead. For AC applications, the minimum ON-Time is 1 or 2 sine waves, so you can create any high speed flickering effects without concerns about wear and tear. The only wear and tear with solid state relays comes from heat. The more amps switched = the more important to use a proper size heat sink.

Your eyes cannot detect flickering at the frequencies used by the Arduino for PWM.

Not an issue, as you would change the PWM at a much lower rate to get the appearance of a candle flicker. I am guessing that is what the OP is going for.

In any case, you can't PWM a solid state relay, either. A zerocrossing solid state relay will just stay on as it keeps receiving an intermittent ON signal.

You don't want to use PWM for this. Just turn the solid state relay on intermittently at a low rate, semirandomly.

polymorph:
In any case, you can't PWM a solid state relay, either. A zerocrossing solid state relay will just stay on as it keeps receiving an intermittent ON signal.

Sure you can. With a on+off time of several cycles. It wouldn't provide a dimming effect. More of a flicker... :smiley: But you wouldn't use the PWM function, you would write your own.

PWM on the order of 5-10 seconds total cycle time for resistance heating has been used for decades.

I wasn't specific enough. You cannot use the Arduino's default PWM with a relay.

No you can't PWM a relay - that makes no sense, the relay is either on or off. Rapid
switching of a relay will use up its limited life (they are normally rated for a certain
number of switching cycles).

I'm going to have to go with this opinion, because the purpose of using PWM to control the intensity of
lights, it to use the duty cycle to limit the amount of current to the lights. When you PWM a relay, you
are applying the power to the lights with the PWM waveform on the input of the relay , but the lights are
seeing a delay caused by the slow response time of the relay, and beyond a circuit speed, the contacts are just bouncing. It makes no sense to PWM a relay. The proper approach is a TRIAC circuit , as already
mentioned, but it won't work with a solid state relay

In any case, you can't PWM a solid state relay, either. A zerocrossing solid state relay will just stay on as it keeps receiving an intermittent ON signal.

You need a TRIAC phase control circuit:
AC PHASE CONTROL

The only problem with a solid state relay as suggested here is that there is a leakage current associated with them in the order of a few tens of mA. In practice this makes controlling light loads ( that is not heavy ) tricky. You might have to end up putting some sort of ballast on as well in parallel like a heater.

I think I have seen that but didn't understand it. Are you saying there is a "minimum" effective load you can have with an SSR and if you try to use it with something that doesn't draw enough current (doesn't load it down enough) it won't work right ?

Yes, that's correct.
From OMRON:
https://www.ia.omron.com/support/faq/answer/18/faq02109/index.html

Useful link
+1

Some of my sound activated lighting effects sort-of "flicker". I've used solid state relays DC relays, and I've built my own zero-crossing and non-zero-crossing solid state AC relays with opto-isolators and TRIACs. With incandescent lights at 60Hz, I don't notice any difference with zero-crossing or non-zero crossing versions. (I just assume the zero-crossing version is less-likely to introduce noise into the AC line.)

You can "flash" an incandescent light at about 10 times per second. That's probably a good starting point.

An incandescent bulb won't go completely off in 1/10 of second. If an incandescent light is off and you hit it with a 1/10th second (100mS) on-pulse, you'll see it flash to full-brightness. If you do the opposite and take a light that's on, and pulse it off for 1/10th of second, you'll see the flicker but it's not nearly as noticeable as flashing it on.

Of course LEDs turn on & off almost instantly, but your eye doesn't respond instantly. And, LED Christmas lights have a power supply so how they will respond to pulsing AC power is unpredictable.

If you want a random flickering effect, try modifying the Blink sketch with a random on & off times between 10mS and 100mS, choosing a new [u]random()[/u] time every time the LED is to turn on or or off. 10mS to 100mS is probably too wide of a range, but you can narrow it down from there to see how it goes.

To test-out your solid-state relay, you can use the standard Blink sketch.