Smart Home Automation Project Using Arduino and Bluetooth Module

Smart Home Automation Project Using Arduino and Bluetooth Module

Introduction:

This document outlines the development of a smart home automation system using an Arduino microcontroller and a Bluetooth (BT) module. The system allows users to control home appliances wirelessly through a smartphone or tablet. This project aims to enhance convenience and improve energy efficiency in a modern household.

Components Required:

    1. Arduino Uno: The microcontroller used to control the system.
    2. Bluetooth Module (HC-05 or HC-06): For wireless communication between the Arduino and a smartphone.
    3. Relay Modules: To control high voltage appliances.
    4. Smartphone: To send commands to the Arduino via a Bluetooth application.
    5. Breadboard and Jumper Wires: For prototyping and connections.
    6. Power Supply: To power the Arduino and the relay modules.
    7. Home Appliances: Such as lights, fans, or any other appliances to be controlled.

System Architecture:

The system consists of three main components:

    1. Arduino Uno: Acts as the brain of the system, receiving commands from the Bluetooth module and controlling the relays.
    2. Bluetooth Module: Facilitates wireless communication between the smartphone and Arduino.
    3. Relay Modules: Connected to the Arduino, these relays control the power supply to the home appliances.

Circuit Diagram:


 

 Arduino Code:

 #include <EEPROM.h> // Include the EEPROM library


const int Relay1 = 8;
const int Button1 = 2;
const int Relay2 = 9;
const int Button2 = 3;
const int Relay3 = 10;
const int Button3 = 4;
const int Relay4 = 11;
const int Button4 = 5;
const int Relay5 = 12;
const int Button5 = 6;
const int Relay6 = 13; // Define the pin for Relay6
const int Button6 = 7; // Define the pin for Button6

int lastRelayPosition = 0; // Variable to store the last relay position
void setup() {
  Serial.begin(9600);
  delay(5000); // Delay for 5 seconds at the start
 
  // Initialize relays and buttons
  pinMode(Relay1, OUTPUT);
  digitalWrite(Relay1, HIGH); // Initially turn on the first relay
  pinMode(Button1, INPUT_PULLUP); // Set the first button pin as input with internal pull-up resistor

  pinMode(Relay2, OUTPUT);
  digitalWrite(Relay2, HIGH); // Initially turn on the second relay
  pinMode(Button2, INPUT_PULLUP); // Set the second button pin as input with internal pull-up resistor

  pinMode(Relay3, OUTPUT);
  digitalWrite(Relay3, HIGH); // Initially turn on the third relay
  pinMode(Button3, INPUT_PULLUP); // Set the third button pin as input with internal pull-up resistor

  pinMode(Relay4, OUTPUT);
  digitalWrite(Relay4, HIGH); // Initially turn on the fourth relay
  pinMode(Button4, INPUT_PULLUP); // Set the fourth button pin as input with internal pull-up resistor

  pinMode(Relay5, OUTPUT);
  digitalWrite(Relay5, HIGH); // Initially turn on the fifth relay
  pinMode(Button5, INPUT_PULLUP); // Set the fifth button pin as input with internal pull-up resistor

  pinMode(Relay6, OUTPUT);
  digitalWrite(Relay6, HIGH); // Initially turn on the sixth relay
  pinMode(Button6, INPUT_PULLUP); // Set the sixth button pin as input with internal pull-up resistor

  // Read the last relay position from EEPROM
  lastRelayPosition = EEPROM.read(0); // Assuming the last relay position is stored in the first byte of EEPROM

  // Set the initial relay positions
  digitalWrite(Relay1, bitRead(lastRelayPosition, 0) ? HIGH : LOW);
  digitalWrite(Relay2, bitRead(lastRelayPosition, 1) ? HIGH : LOW);
  digitalWrite(Relay3, bitRead(lastRelayPosition, 2) ? HIGH : LOW);
  digitalWrite(Relay4, bitRead(lastRelayPosition, 3) ? HIGH : LOW);
  digitalWrite(Relay5, bitRead(lastRelayPosition, 4) ? HIGH : LOW);
  digitalWrite(Relay6, bitRead(lastRelayPosition, 5) ? HIGH : LOW);
}

void loop() {
  // Check for incoming serial data
  if (Serial.available() > 0) {
    char m = Serial.read();

    if (m == 'A') {
      delay(1000);
      digitalWrite(Relay1, HIGH);
    } else if (m == 'a') {
      digitalWrite(Relay1, LOW);
    } else if (m == 'B') {
      delay(1000);
      digitalWrite(Relay2, HIGH);
    } else if (m == 'b') {
      digitalWrite(Relay2, LOW);
    } else if (m == 'C') {
      delay(1000);
      digitalWrite(Relay3, HIGH);
    } else if (m == 'c') {
      digitalWrite(Relay3, LOW);
    } else if (m == 'D') {
      delay(1000);
      digitalWrite(Relay4, HIGH);
    } else if (m == 'd') {
      digitalWrite(Relay4, LOW);
    } else if (m == 'E') {
      delay(1000);
      digitalWrite(Relay5, HIGH);
    } else if (m == 'e') {
      digitalWrite(Relay5, LOW);
    } else if (m == 'F') {
      delay(1000);
      digitalWrite(Relay6, HIGH);
    }  else if (m == 'f') {
      digitalWrite(Relay6, LOW);
    }
  }

  // Check if the first button is pressed
  if (digitalRead(Button1) == LOW) {
    digitalWrite(Relay1, HIGH);
    Serial.write('A');
    if (digitalRead(Button1) == HIGH) {
      digitalWrite(Relay1, LOW);
      Serial.write('a');
    }
  }

  // Check if the second button is pressed
  if (digitalRead(Button2) == LOW) {
    digitalWrite(Relay2, HIGH);
    Serial.write('B');
    if (digitalRead(Button2) == HIGH) {
      digitalWrite(Relay2, LOW);
      Serial.write('b');
    }
  }

  // Check if the third button is pressed
  if (digitalRead(Button3) == LOW) {
    digitalWrite(Relay3, HIGH);
    Serial.write('C');
    if (digitalRead(Button3) == HIGH) {
      digitalWrite(Relay3, LOW);
      Serial.write('c');
    }
  }

  // Check if the fourth button is pressed
  if (digitalRead(Button4) == LOW) {
    digitalWrite(Relay4, HIGH);
    Serial.write('D');
    if (digitalRead(Button4) == HIGH) {
      digitalWrite(Relay4, LOW);
      Serial.write('d');
    }
  }

  // Check if the fifth button is pressed
  if (digitalRead(Button5) == LOW) {
    digitalWrite(Relay5, HIGH);
    Serial.write('E');
    if (digitalRead(Button5) == HIGH) {
      digitalWrite(Relay5, LOW);
      Serial.write('e');
    }
  }

  // Check if the sixth button is pressed
  if (digitalRead(Button6) == LOW) {
    digitalWrite(Relay6, HIGH);
    Serial.write('F');
    if (digitalRead(Button6) == HIGH) {
      digitalWrite(Relay6, LOW);
      Serial.write('f');
    }
  }

  // Update last relay position and store it in EEPROM before resetting
  int newRelayPosition = 0;
  newRelayPosition |= digitalRead(Relay1) << 0;
  newRelayPosition |= digitalRead(Relay2) << 1;
  newRelayPosition |= digitalRead(Relay3) << 2;
  newRelayPosition |= digitalRead(Relay4) << 3;
  newRelayPosition |= digitalRead(Relay5) << 4;
  newRelayPosition |= digitalRead(Relay6) << 5;

  if (newRelayPosition != lastRelayPosition) {
    lastRelayPosition = newRelayPosition;
    EEPROM.write(0, lastRelayPosition); // Store the last relay position in the first byte of EEPROM
    //EEPROM.commit(); // Commit changes to EEPROM
  }
}

 

Bluetooth Application:

To control the home automation system, you can use any Bluetooth terminal app available on Google Play Store or Apple App Store. Pair your smartphone with the HC-05 Bluetooth module and send the following commands to control the appliances:

    • Send '1' to turn on Relay 1 (Appliance 1).
    • Send '2' to turn off Relay 1 (Appliance 1).
    • Send '3' to turn on Relay 2 (Appliance 2).
    • Send '4' to turn off Relay 2 (Appliance 2).

Testing and Troubleshooting:

  • Testing:

    • Connect the Bluetooth module to the Arduino.
    • Upload the code to the Arduino.
    • Pair the Bluetooth module with your smartphone.
    • Use the Bluetooth terminal app to send commands and observe if the appliances respond correctly.
  • Troubleshooting:

    • Ensure the Bluetooth module is properly paired with the smartphone.
    • Check all connections between the Arduino, Bluetooth module, and relay modules.
    • Verify the relay modules are connected to the correct digital pins on the Arduino.
    • Ensure the power supply is adequate for the relay modules and connected appliances.

Conclusion:

This smart home automation project using Arduino and a Bluetooth module provides a simple yet effective way to control home appliances wirelessly. The system can be expanded by adding more relays and modifying the code to accommodate additional appliances. This project not only enhances convenience but also contributes to energy efficiency by allowing users to control their home environment remotely. 

Comments

Popular posts from this blog

Smart water heater using Arduino DIY Project

Simple Automatic Night Light using LDR and BC547 Transistor