Subscribe to Arduino Academy and start learning today for FREE!

Working with the SainSmart 5v Relay Board

Today we are working with our SainSmart 5v Relay Board. This is a simple and inexpensive 4 port SPDT relay board (there are boards with more or less relays)  that takes a digital signal (LOW) from the Arduino, through an optoisolator, which triggers a transistor, pulling in the relay. The relay contacts are rated for 10 amps at 120/240vac, and 10 amps at 30vdc or less.
IMPORTANT!

Become the Maker you were born to be. Try Arduino Academy for FREE!

The contact pins are not numbered, and are reversed if you go by what the schematic appears to be saying. Facing the screw terminals, with the board face up (solder side down), the screw terminals are as follows (from left to right):
K4
1 – Normally Open
2 – Common
3 – Normally Closed
K3
1 – Normally Open
2 – Common
3 – Normally Closed
K2
1 – Normally Open
2 – Common
3 – Normally Closed
K1
1 – Normally Open
2 – Common
3 – Normally Closed
When you send a logic low, that turns on the LED, and energizes the coil. However, a disconnected input will drop out the LED and the coil, as will a logic HIGH. We will send a logic HIGH in setup to ensure the relays are disabled on boot.

There is a 6 pin male header, so you will need a cable or female pins to slide over the header to connect it to your Arduino. Pin 1 connects to Arduino GND, Pins 2-5 to Digital output pins, and Pin 6 to Arduino 5v. A red LED for each relay lights when active (LOW).

int relayPin1 = 7;                 // IN1 connected to digital pin 7
int relayPin2 = 8;                 // IN2 connected to digital pin 8
int relayPin3 = 9;                 // IN3 connected to digital pin 9
int relayPin4 = 10;                // IN4 connected to digital pin 10

void setup()
{
pinMode(relayPin1, OUTPUT);      // sets the digital pin as output
pinMode(relayPin2, OUTPUT);      // sets the digital pin as output
pinMode(relayPin3, OUTPUT);      // sets the digital pin as output
pinMode(relayPin4, OUTPUT);      // sets the digital pin as output
digitalWrite(relayPin1, HIGH);        // Prevents relays from starting up engaged
digitalWrite(relayPin2, HIGH);        // Prevents relays from starting up engaged
digitalWrite(relayPin3, HIGH);        // Prevents relays from starting up engaged
digitalWrite(relayPin4, HIGH);        // Prevents relays from starting up engaged
}

void loop()
{
digitalWrite(relayPin1, LOW);   // energizes the relay and lights the LED
digitalWrite(relayPin2, LOW);   // energizes the relay and lights the LED
digitalWrite(relayPin3, LOW);   // energizes the relay and lights the LED
digitalWrite(relayPin4, LOW);   // energizes the relay and lights the LED
delay(1000);                  // waits for a second
digitalWrite(relayPin1, HIGH);    // de-energizes the relay and LED is off
digitalWrite(relayPin2, HIGH);    // de-energizes the relay and LED is off
digitalWrite(relayPin3, HIGH);    // de-energizes the relay and LED is off
digitalWrite(relayPin4, HIGH);    // de-energizes the relay and LED is off
delay(1000);                  // waits for a second
}

Become the Maker you were born to be. Try Arduino Academy for FREE!

Subscribe
Notify of
guest
1 Comment
Inline Feedbacks
View all comments
Unknown
6 years ago

Hi,
may I know what are the values of Resistors and Transistor number.
waiting for a quick reply
Thanks

Archives

1
0
Would love your thoughts, please comment.x
()
x