Step 1 of 6 ⏱ about 4 min
Relay module only
What you're adding
The relay module. A relay is a switch that the Arduino can flip. Each relay clicks when it switches. Leave the screw terminals on the relays empty for now.
The 5V and GND wires are shared, so we use the breadboard's power rails: the long red (+) and blue (−) lines of holes.
Wire it
✔ All ticked. Now upload the code.
Upload the code
- Close the Serial Monitor if it is open.
- Download the sketch below and open it in Arduino IDE (File → Open). If the IDE asks to put it in a folder, click OK.
- Plug the USB cable back in. Check Tools → Board says Arduino UNO and Tools → Port shows your COM port.
- Click Upload (the round → arrow button). Wait for Done uploading.
Show the code
// Step 1: test the relay module.
// Turns relay 1, 2, 3, 4 ON one at a time (1 second each), then all OFF.
// Wiring: IN1 = pin 8, IN2 = pin 9, IN3 = pin 10, IN4 = pin 11.
// This relay module is "active-LOW": LOW turns a relay ON, HIGH turns it OFF.
const int RELAY_PINS[4] = {8, 9, 10, 11};
const int RELAY_ON = LOW;
const int RELAY_OFF = HIGH;
void allOff()
{
for (int i = 0; i < 4; i++) {
digitalWrite(RELAY_PINS[i], RELAY_OFF);
}
}
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 4; i++) {
pinMode(RELAY_PINS[i], OUTPUT);
}
allOff();
Serial.println("Relay test starting");
}
void loop()
{
for (int i = 0; i < 4; i++) {
allOff();
digitalWrite(RELAY_PINS[i], RELAY_ON);
Serial.print("Relay ");
Serial.print(i + 1);
Serial.println(" ON");
delay(1000);
}
allOff();
Serial.println("All OFF");
delay(1000);
}
You should see
- Each relay clicks and its little light on the module turns on, in order 1, 2, 3, 4.
- Then all are off for a second, and it repeats.
- Serial Monitor (9600 baud) shows Relay 1 ON, Relay 2 ON … All OFF.
If it doesn't work
No lights on the relay module at all
Relay VCC and GND are not getting power. Check Arduino 5V → red rail, Arduino GND → blue rail, and that the relay wires are in the same rails. Some breadboards have a break in the middle of each rail: keep all the wires on the same half.
Relays click in the wrong order
The IN wires are swapped. Check IN1 → pin 8, IN2 → pin 9, IN3 → pin 10, IN4 → pin 11.
One relay never clicks
That relay's IN wire is loose or in the wrong hole. Push it in firmly.
Lights come on but there is no click
The USB port may not give enough power. Try another USB socket on the PC.