SSR relay code

Hi to all…

I am working on a new project where I need to have a relay turn on/off two lights… I am using an arduino MEGA and I bought this relay from SainSmart http://www.sainsmart.com/sainsmart-2-channel-5v-solid-state-relay-module-board-omron-ssr-avr-dsp-arduino.html. I have based my code on http://arduino-info.wikispaces.com/ArduinoPower#4-8 where it discusses Solid state relays and I have come up with this:

///2-Solid State Relay testing code

//Include libraries here
#include<Wire.h>

#define RELAY_ON  1
#define RELAY_OFF 0

#define Relay_1   2    // arduino digital I/0 pin number might need to change
#define Relay_2   3    //


int waittime;    //Delay between changes

void setup()
{
	waitime = 1000;
	digitalWrite(Relay_1, RELAY_OFF);
	pinMode(Relay_1,OUTPUT);
	digitalWrite(Relay_2, RELAY_OFF);
	pinMode(Relay_2,OUTPUT);
	delay(4000);    //Check that all relays are inactive at reset

}

void loop()
{
	//turning all (2) relays ON in sequence
	digitalWrite(Relay_1,RELAY_ON);     //set the relay ON
	delay(waittime);		    // wait for a second
	digitalWrite(Relay_2,RELAY_ON);	
	delay(waittime);

	//turning all (2) relays OFF in sequence
	digitalWrite(Relay_1, RELAY_OFF);	//turn the relay OFF
	delay(waittime);
	digitalWrite(Relay_2, RELAY_OFF);	//turn the relay OFF
	delay(waittime);
	
}  //end of program

Anyone have any experience with this type of relay that can tell me if the code looks ok? I want to test it by having two small LED’s connected to each output of the relay to turn on or off… I am just not sure how I could connect the LED’s. Should I connect them on both sides to the wires coming out of the outputs of the relay?

Thanks,
Yesenia

    digitalWrite(Relay_1, RELAY_OFF);

Why are you needing to turn off the pull-up resistor? Before making the pin an OUTPUT, it defaults to INPUT, so digitalWrite() affects the pullup resistor, not the state of the pin.

I want to test it by having two small LED's connected to each output of the relay to turn on or off... I am just not sure how I could connect the LED's. Should I connect them on both sides to the wires coming out of the outputs of the relay?

A relay is a switch. It turns power on or off. What is your power source for the LED? One side of the power supply connects to one of the relay pins on the controlled side. The other relay pin on the controlled side connects to the LED (or whatever load you have). The other side of the load connects to the other side of the power supply.

Just looked at the spec sheet... the switching of this thing is triac based. Which usually means you control AC power on/off not DC.

Anyone have any experience with this type of relay that can tell me if the code looks ok? I want to test it by having two small LED's connected to each output of the relay to turn on or off

You can test your code and the Arduino by connecting LEDs (along with current limiting resistors) directly to the Arduino outputs, without the relay.

If your lights are DC, you have the wrong relay... A mechanical relay's contacts are simply contacts, and they will work with AC or DC, but SSRs are different.*

If your lights are 120VAC or 240VAC, I wouldn't bother low-voltage testing your solid state relays. SSRs are generally very reliable (f you connect them properly and if you don't overload them).

Testing a SSR with with an LED might not work. Besides the fact that it's an AC relay, the LED may not draw enough current to turn-on the relay. (There is a minimum current 0.1A for your relay). Or, it might "leak" enough current to keep the LED lit when the relay is switched off. Your SSR also has a minimum output voltage of 75V, so it really is designed to work with "AC power".

If you find it necessary to test the relays, disconect the Arduino and connect 5V across the relay inputs to turn it on (with the AC-output side wired-up and powered-up).

  • A TRIAC (in an AC relay) can be turned-on, but it won't turn-off till power is removed. With AC power, the voltage crosses-through zero twice every cycle (100 or 120 times per second), so this isn't a problem.

Unlike a transistor of MOSFET, a TRIAC can pass current in both directions, so it's ideal for AC power.

Just acquired this very SaintSmart 8Channel SSR. It's meant for AC power. Attempt to connect DC will NOT work.