Bluetooth Home Automation Cheat sheet

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.

Step 1: coloured wires are new; grey wires were added earlier.
Step 1: coloured wires are new; grey wires were added earlier. Open full size

Wire it

Why LOW means ON: this relay module is active-LOW. The Arduino sends LOW (0 volts) to switch a relay ON and HIGH (5 volts) to switch it OFF. That is why the final code sets every pin HIGH at the start: everything starts OFF.

Upload the code

  1. Close the Serial Monitor if it is open.
  2. Download the sketch below and open it in Arduino IDE (File → Open). If the IDE asks to put it in a folder, click OK.
  3. Plug the USB cable back in. Check Tools → Board says Arduino UNO and Tools → Port shows your COM port.
  4. 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

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.