Bluetooth Home Automation Light Bulb Switch Using An HC-05, A Relay, and Arduino

I used an HC-05 Bluetooth module, a relay switch, a light bulb switch, and an Arduino Uno to create a wireless home automation light switch. The goal was to establish a wireless protocol for switching a light bulb on and off using a simple app on a smartphone. The relay switch controls the power to the light bulb, the HC-05 handles the Bluetooth, and the Uno reads the Bluetooth module to control the relay. The tools implemented can be extrapolated to other projects such as automated blinds, temperature controlled fans, motion sensors, security cameras, smoke detectors, etc. 


 

PARTS LIST:

  • Light bulb socket (here)

  • Relay switch (here)

  • Bluetooth HC-05 (here)

  • Arduino Uno

IMG_2728.JPG

IMG_2738.jpg
socket_whole.jpg
relay_zoom.jpg
IMG_2739.jpg

Wiring

wiring_diagram.png

Android App

I used a simple Andoid app that connects to the HC-05 and transmits strings. Using the app, on the Arduino side we can decode the signal to create a protocol that turns the light switch on or off. It can be as simple as 1s and 0s, or as complex as you want. I used a 1 for on, and a 0 for off, and this method is used in the Arduino code below. To change the protocol, just change the code section in the 'if' statement, and make sure to send the desired protocol through the Android app.


Arduino Code

#include <SoftwareSerial.h>
int relay = 2; // Set pin for relay control

SoftwareSerial bleserial(8,9);

// setup the relay output and the bluetooth serial, and the serial monitor (if you want to print the outputs)
void setup() {                
  // set relay pin as output.
  pinMode(relay, OUTPUT); 
  // start bluetooth and serial monitor  
  bleserial.begin(9600);
  Serial.begin(9600);
 
}

void loop() {
  
  if(bleserial.available()){

    char char1 = bleserial.read();
    Serial.println(char1);
    // Set protocol that you want to turn on the light bulb, I chose 1 and 0 as on and off, respectively

    if(char1=='1'){
      Serial.println("ON");
      digitalWrite(relay,LOW);
    } else if (char1=='0'){
      digitalWrite(relay,HIGH);
    }
  }
  
}

CONCLUSION

This project is straightforward, so I did not feel the need to make many comments throughout. The important thing to remember about using a relay module is that it involves switching AC current, also called mains power. This is a dangerous process. So please use caution when disassembling the light bulb socket. This project is a great introduction to using relays and switching, while also utilizing wireless technology and Arduino. The Bluetooth protocol process is useful for wireless sensing and control, and I hope the educational nature of this project opens up avenues in home automation, remote sensing, wireless control, and electronics in general. 

 

See more in Electronics:

Related Products: