Introduction
In this experiment, we will use Bluetooth communication to control a relay. This setup can be used to remotely turn on or off electrical devices.

Components Needed
- Bluetooth Module (e.g., HC-05)
- Relay Module
- Arduino (e.g., Uno, Nano)
- Jumper wires
Circuit Setup
- Connect the VCC and GND pins of the Bluetooth module to the 5V and GND pins of the Arduino.
- Connect the TX pin of the Bluetooth to RX on Arduino and RX pin of the Bluetooth to TX on Arduino.
- Connect the relay module's VCC and GND to the Arduino 5V and GND.
- Connect the IN pin of the relay to pin 7 on the Arduino.
Ensure that the relay and Bluetooth module are connected as shown.

Code for Relay Control with Bluetooth
Upload the following code to your Arduino to control the relay using Bluetooth:
char command;
const int relayPin = 7; // Pin connected to relay
void setup() {
pinMode(relayPin, OUTPUT);
Serial.begin(9600); // Start serial communication
}
void loop() {
if (Serial.available() > 0) {
command = Serial.read(); // Read the incoming command
if (command == '1') {
digitalWrite(relayPin, HIGH); // Turn on relay
} else if (command == '0') {
digitalWrite(relayPin, LOW); // Turn off relay
}
}
}
Explanation
This setup uses Bluetooth to send commands to the Arduino, which then controls the relay. Sending a '1' through Bluetooth turns the relay on, while sending a '0' turns it off.
Troubleshooting
- If the relay does not respond, check the Bluetooth connection and ensure it is paired with the device sending the commands.
- Ensure the relay is correctly wired and that the relay module is functioning properly.