← Back to notes

Dual relay module simulator

A relay is an electrically operated switch. A small signal from the Arduino energises a coil, which pulls the COM contact from NC (normally closed) across to NO (normally open). This lets a 5 V microcontroller switch a separate, higher-power circuit.

Arduino outputs

Pin 13 → IN1
Pin 12 → IN2

On the common blue 2-channel modules, writing LOW to IN turns the relay ON (the opto-isolator LED is wired from VCC to IN). That is why the course's switch-over code writes LOW to the relay it wants to use. Check yours by listening for the click.

Relay contacts

Example 3b sketch

int R1pin = 12;
int R2pin = 13;
int dt1 = 500;
int dt2 = 1000;

void setup() {
  Serial.begin(9600);
  pinMode(R1pin, OUTPUT);
  pinMode(R2pin, OUTPUT);
}

void loop() {
  digitalWrite(R1pin, HIGH);
  digitalWrite(R2pin, LOW);
  delay(dt1);
  digitalWrite(R2pin, HIGH);
  digitalWrite(R1pin, LOW);
  delay(dt2);
}