Subscribe to Arduino Academy and start learning today for FREE!

Arduino Relay Control

Previously I have blogged about using relays with an Arduino, and SainSmart relays specifically. A while back I received a 4 relay, and a 8 relay board, and both of them used negative logic, i.e. a LOW activated them, and a HIGH deactivated them. Yesterday I received a single relay module as part of a kit, and found that this module uses positive logic, i.e. a High activates it, and a LOW deactivates it.

Being a 5v relay, it’s able to be driven directly from the arduino power. If you have a lot of additional hardware, you may want to consider a separate 5v supply, and common ground.

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

We are printing the relay state to the serial monitor, but the LED on the relay board also signifies whether it’s active or not.

Only 3 pins are used, 5v (“V”), Gnd (“G”), and a data pin. We are using pin 7 in this example, and connects to the relay “S” (signal) pin.

Here is my test code:

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(7, OUTPUT); //don’t forget to declare the pin as output!
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7, HIGH);
Serial.println(“Active”);
delay(5000);
digitalWrite(7, LOW);
Serial.println(“Inactive”);
delay(5000);

}

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

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Archives

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