Bluetooth Home Automation Cheat sheet

Step 2 of 6 ⏱ about 4 min

First light

What you're adding

The battery and LED 1. Each relay has three screws:

The battery side is a separate circuit. Battery − never connects to the Arduino.

⚠ Never let the battery + and − wires touch each other.

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

Wire it

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 2: first light.
// Switches relay 1 (pin 8) ON for 2 seconds, then OFF for 2 seconds.
// LED 1 should light up while relay 1 is ON.
// Remember: LOW = relay ON, HIGH = relay OFF.

const int RELAY1_PIN = 8;

void setup()
{
  Serial.begin(9600);
  pinMode(RELAY1_PIN, OUTPUT);
  digitalWrite(RELAY1_PIN, HIGH);   // start with relay 1 OFF
}

void loop()
{
  digitalWrite(RELAY1_PIN, LOW);    // relay 1 ON -> LED 1 on
  Serial.println("Relay 1 ON");
  delay(2000);

  digitalWrite(RELAY1_PIN, HIGH);   // relay 1 OFF -> LED 1 off
  Serial.println("Relay 1 OFF");
  delay(2000);
}

The Step 1 sketch also works: LED 1 lights when relay 1 clicks.

You should see

If it doesn't work

LED never lights

Flip the LED round (it only works one way). Check the battery is charged and in its holder the right way. Check the resistor and LED legs share a breadboard row.

LED is on when the relay is OFF, and off when it is ON

The wire is on NC instead of NO. Move it to the NO screw (the top one in the diagram).

LED is on all the time

The NO wire may be touching COM. Check the screws are tight and no bare wire touches the next screw.