Arnov Sharma
Published © CC BY-ND

Relay Module Basics

Learn how to control a relay module LIKE A BOSS to do a little home automation.

BeginnerShowcase (no instructions)15 minutes1,781
Relay Module Basics

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Relay Module (Generic)
×1
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
everything above can be found here for a low price
×1

Story

Read more

Schematics

c2_uWV0iESf7p.PNG

Code

Untitled file

C/C++
#define relayA 2    //attaches the relay to pin 2
#define relayB 3

void setup()
{
  pinMode(relayA, OUTPUT);    //sets the relay as an output
  pinMode(relayB, OUTPUT);
}
void loop()
{
  digitalWrite(relayA, HIGH);    //relay open
  digitalWrite(relayB, LOW);
  delay(2000);                  //wait 2 seconds
  digitalWrite(relayA, LOW);     //relay closed
  digitalWrite(relayB, HIGH);
  delay(2000);                  //wait 2 seconds
}

Credits

Arnov Sharma
313 projects • 313 followers
Just your average MAKER

Comments