Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Bluetooth-Controlled LED Lighting System with Arduino Mega and 4-Channel Relay

View and Edit Project In Cirkit DesignerImage of Bluetooth-Controlled LED Lighting System with Arduino Mega and 4-Channel Relay

Circuit Documentation

Summary

This circuit is designed to control four AC-powered LED bulbs using a 4-channel relay module. The relays are actuated by an Arduino Mega 2560 microcontroller, which receives commands via a Bluetooth module. The circuit allows for individual control of each LED bulb, enabling them to be switched on or off remotely. The AC wall plug point provides the main power source for the LED bulbs, while the Arduino and Bluetooth module are powered by a 5V supply.

Component List

LED Bulb AC / Bombillo AC

Relay 4 Channel 5v

Arduino Mega 2560

Bluetooth Module

AC Wall Plug Point

Wiring Details

LED Bulb AC / Bombillo AC

Relay 4 Channel 5v

Arduino Mega 2560

Bluetooth Module

AC Wall Plug Point

Documented Code

/*
 * This Arduino sketch controls a 4-channel relay module to switch on and off
 * four LED bulbs. The relays are controlled via PWM pins on the Arduino Mega
 * 2560. A Bluetooth module is used for communication to receive commands for
 * controlling the relays.
 */

// Pin definitions
const int relay1 = 8;  // Relay 1 connected to D8
const int relay2 = 9;  // Relay 2 connected to D9
const int relay3 = 10; // Relay 3 connected to D10
const int relay4 = 11; // Relay 4 connected to D11

void setup() {
  // Initialize serial communication for Bluetooth
  Serial2.begin(9600);
  
  // Initialize relay pins as outputs
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  
  // Turn off all relays initially
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, LOW);
  digitalWrite(relay4, LOW);
}

void loop() {
  // Check if data is available from Bluetooth
  if (Serial2.available()) {
    char command = Serial2.read();
    
    // Control relays based on received command
    switch (command) {
      case '1':
        digitalWrite(relay1, HIGH); // Turn on Relay 1
        break;
      case '2':
        digitalWrite(relay1, LOW);  // Turn off Relay 1
        break;
      case '3':
        digitalWrite(relay2, HIGH); // Turn on Relay 2
        break;
      case '4':
        digitalWrite(relay2, LOW);  // Turn off Relay 2
        break;
      case '5':
        digitalWrite(relay3, HIGH); // Turn on Relay 3
        break;
      case '6':
        digitalWrite(relay3, LOW);  // Turn off Relay 3
        break;
      case '7':
        digitalWrite(relay4, HIGH); // Turn on Relay 4
        break;
      case '8':
        digitalWrite(relay4, LOW);  // Turn off Relay 4
        break;
      default:
        // Do nothing for unrecognized commands
        break;
    }
  }
}

This code is responsible for initializing the Arduino Mega 2560's pins connected to the relay module and setting up serial communication with the Bluetooth module. The loop function listens for commands from the Bluetooth module and controls the state of the relays accordingly. Each relay corresponds to one LED bulb, allowing individual control of each bulb's power state.