Controlling a Relay with Bluetooth

Controlling a Relay with Bluetooth

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.

Controlling Relay with Bluetooth

Components Needed

Circuit Setup

  1. Connect the VCC and GND pins of the Bluetooth module to the 5V and GND pins of the Arduino.
  2. Connect the TX pin of the Bluetooth to RX on Arduino and RX pin of the Bluetooth to TX on Arduino.
  3. Connect the relay module's VCC and GND to the Arduino 5V and GND.
  4. Connect the IN pin of the relay to pin 7 on the Arduino.

Ensure that the relay and Bluetooth module are connected as shown.

Relay Circuit Setup

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