Arduino Bluetooth LED Controller

Introduction

Controling lights from your smartphone is the first step toward building a Smart Home. In this tutorial, we will build a Bluetooth LED Controller using an Arduino Uno and an HC-05 Bluetooth Module. This project allows you to turn an LED (or a relay-controlled lamp) ON and OFF wirelessly using an Android app.



How It Works

The system works through Serial Communication. When you press a button on your smartphone app, it sends a specific text character (like '1' or '0') via Bluetooth. The HC-05 module receives this signal and passes it to the Arduino’s Serial pins. The Arduino then reads the character and decides whether to turn the LED on or off.



Required Components

  • Arduino Uno (or Nano)
  • HC-05 Or HC-06 Bluetooth Module
  • RGB LED
  • Jumper Wires & Breadboard
  • Smartphone (Android)



Circuit Wiring Diagram

Connecting the HC-05 is simple, but there is one crucial rule: Always disconnect the Bluetooth module's RX/TX wires when uploading code to the Arduino to avoid conflicts.

Bluetooth Connections:

  • VCC: Connect to Arduino 5V
  • GND: Connect to Arduino GND
  • TXD: Connect to Arduino Pin 0 (RX)
  • RXD: Connect to Arduino Pin 1 (TX)

LED Connection:

  • Long Leg (+): Connect to Arduino Pin 13 (optional via 220-ohm resistor).
  • Short Leg (-): Connect to Arduino GND.



The Arduino Code

Copy and paste the code below into your Arduino IDE.


CODE

char t;

void setup() {
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()){
    t=Serial.read();
    Serial.println(t);
 }
 if(t=='R'){
  digitalWrite(13,HIGH);
  digitalWrite(12,LOW);
  digitalWrite(11,LOW);
 }
 else if(t=='G'){
  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  digitalWrite(11,LOW);
 }
 else if(t=='B'){
  digitalWrite(13,LOW);
  digitalWrite(12,LOW);
  digitalWrite(11,HIGH);
 }
 else if(t=='W'){
  digitalWrite(13,HIGH);
  digitalWrite(12,HIGH);
  digitalWrite(11,HIGH);
 }
 else if(t=='O'){
  digitalWrite(13,LOW);
  digitalWrite(12,LOW);
  digitalWrite(11,LOW);
 }
}



Smartphone App Setup

To control the LED, you can use the custom app we built in our [MIT App Inventor Tutorial] or download a "Bluetooth Terminal" app from the Play Store.

  1. Pairing: Go to your phone's Bluetooth settings and pair with HC-05 (Default PIN is usually 1234 or 0000).

  2. Connecting: Open your app and select the HC-05 module.

  3. Commanding: Send the number 1 to turn the light ON and 0 to turn it OFF.




⚠️Troubleshooting Common Errors


1. Code Won't Upload

Solution: You MUST unplug the TX and RX wires from the Arduino while clicking "Upload." The Arduino uses the same serial lines for the USB cable and the Bluetooth module.

2. LED Stays Off

  • Polarity: Check if the LED is plugged in backward. The longer leg must be connected to the signal pin.
  • Baud Rate: Ensure Serial.begin(9600) is used, as most HC-05 modules are set to 9600 by default.

3. HC-05 is Blinking Fast

A fast-blinking red light on the HC-05 means it is "Searching for a connection." Once it is connected to your phone, the blinking pattern will change to a slow pulse or double-blink.



Conclusion

Building a Bluetooth LED controller is a gateway into the Internet of Things (IoT). You can easily replace the LED with a Relay Module (check our [DIY Relay Tutorial]) to control high-voltage lights, fans, or even electric gates.

Post a Comment

Post a Comment (0)

Previous Post Next Post