Header Ads Widget

Arduino Home Automation with Bluetooth, Manual switches and EEPROM

Home automation has become a popular trend in recent years. It allows you to control and automate various devices and appliances in your home, making your life easier and more convenient. In this article, we will discuss how to create an Arduino-based home automation system that uses Bluetooth, manual switches, and EEPROM to control various devices in your home.




COMPONENTS LINKS :

QUARTAZ COMPONENTS LINKS :

Arduino board (UNO or Nano)  :  BUYNOW

IR receiver module    :  BUYNOW

IR remote control   :  BUYNOW

Breadboard     :  BUYNOW

Jumper wires    :  BUYNOW

relay  : BUYNOW

AMAZON LINKS :

Arduino board (UNO or Nano)  :  BUYNOW

IR receiver module    :  BUYNOW

IR remote control   :  BUYNOW

Breadboard     :  BUYNOW

Jumper wires    :  BUYNOW

relay  : BUYNOW

What is Arduino Home Automation?

Arduino home automation refers to the process of automating your home using an Arduino microcontroller board. Arduino is an open-source electronics platform that is easy to use and provides endless possibilities for creating various projects, including home automation.


Arduino home automation uses various sensors, actuators, and other components to control and automate devices in your home, such as lights, fans, air conditioners, and more. It provides a convenient and cost-effective way to make your home smarter and more energy-efficient.


Using Bluetooth in Arduino Home Automation:

Bluetooth is a wireless technology that allows devices to communicate with each other over short distances. It is widely used in home automation to remotely control devices using a smartphone or Bluetooth-enabled device.


In Arduino home automation, you can use a Bluetooth module, such as the HC-05, to connect your Arduino board to a smartphone. You can then use a mobile app to control various devices in your home, such as turning lights on and off, adjusting the temperature of an air conditioner, and more.


Using Manual Switches in Arduino Home Automation:

While Bluetooth provides a convenient way to control devices remotely, manual switches are still an important part of home automation. Manual switches allow you to control devices directly without the need for a smartphone or other remote control.


In Arduino home automation, you can use manual switches, such as push buttons, to control devices in your home. You can connect these switches to your Arduino board and program it to respond to specific switch presses, such as turning on a light when a switch is pressed.

Using EEPROM in Arduino Home Automation:

EEPROM stands for Electrically Erasable Programmable Read-Only Memory. It is a type of non-volatile memory that allows you to store data even when the power is turned off. In Arduino home automation, you can use EEPROM to store various settings and configurations for your devices.


For example, you can use EEPROM to store the last state of a device, such as whether a light was on or off, and restore that state when the power is turned back on. This can be useful when there is a power outage, and you don't want to manually turn all your devices back on.

Arduino Home Automation with Bluetooth, Manual switches, and EEPROM circuit:




Arduino Home Automation with Bluetooth, Manual switches, and EEPROM code:

#include <EEPROM.h>


#define relay1 4  
#define relay2 5  
#define relay3 6  
#define relay4 7  

#define switch1 10  
#define switch2 11 
#define switch3 12  
#define switch4 13  


// Switch State
bool state_1 = LOW;
bool state_2 = LOW;
bool state_3 = LOW;
bool state_4 = LOW;

char bluetooth_data; // variable for storing bluetooth data

void relayOnOff(int relay){
 switch(relay){
      case 1:
            digitalWrite(relay1, !digitalRead(relay1)); // change state for relay-1
            EEPROM.update(0,digitalRead(relay1));
            delay(100);
      break;
      case 2:
            digitalWrite(relay2, !digitalRead(relay2)); // change state for relay-2
            EEPROM.update(1,digitalRead(relay2));
            delay(100);
      break;
      case 3:
            digitalWrite(relay3, !digitalRead(relay3)); // change state for relay-3
            EEPROM.update(2,digitalRead(relay3));
            delay(100);
      break;
      case 4:
            digitalWrite(relay4, !digitalRead(relay4)); // change state for relay-4
            EEPROM.update(3,digitalRead(relay4));
            delay(100);
      break;
      default : break;      
      }  
}

void eepromState()
{
  digitalWrite(relay1, EEPROM.read(0)); delay(200);
  digitalWrite(relay2, EEPROM.read(1)); delay(200);
  digitalWrite(relay3, EEPROM.read(2)); delay(200);
  digitalWrite(relay4, EEPROM.read(3)); delay(200);
}  

void bluetooth_control()
{
  if(Serial.available()) {
    bluetooth_data = Serial.read();
    Serial.println(bluetooth_data);
    switch(bluetooth_data)
        {
          case 'A': digitalWrite(relay1, LOW);  EEPROM.update(0,LOW); break; // if 'A' received Turn on Relay1
          case 'a': digitalWrite(relay1, HIGH); EEPROM.update(0,HIGH); break; // if 'a' received Turn off Relay1
          case 'B': digitalWrite(relay2, LOW);  EEPROM.update(1,LOW); break; // if 'B' received Turn on Relay2
          case 'b': digitalWrite(relay2, HIGH); EEPROM.update(1,HIGH); break; // if 'b' received Turn off Relay2
          case 'C': digitalWrite(relay3, LOW);  EEPROM.update(2,LOW); break; // if 'C' received Turn on Relay3
          case 'c': digitalWrite(relay3, HIGH); EEPROM.update(2,HIGH); break; // if 'c' received Turn off Relay3
          case 'D': digitalWrite(relay4, LOW);  EEPROM.update(3,LOW); break; // if 'D' received Turn on Relay4
          case 'd': digitalWrite(relay4, HIGH); EEPROM.update(3,HIGH); break; // if 'd' received Turn off Relay4
          case 'Z': all_Switch_ON(); break;  // if 'Z' received Turn on all Relays
          case 'z': all_Switch_OFF(); break; // if 'z' received Turn off all Relays
          default : break;
        }
        delay(20);
  }
}

void all_Switch_ON(){
  digitalWrite(relay1, LOW); EEPROM.update(0,LOW); delay(100);
  digitalWrite(relay2, LOW); EEPROM.update(1,LOW); delay(100);
  digitalWrite(relay3, LOW); EEPROM.update(2,LOW); delay(100);
  digitalWrite(relay4, LOW); EEPROM.update(3,LOW); delay(100);
}

void all_Switch_OFF(){
  digitalWrite(relay1, HIGH); EEPROM.update(0,HIGH); delay(100);
  digitalWrite(relay2, HIGH); EEPROM.update(1,HIGH); delay(100);
  digitalWrite(relay3, HIGH); EEPROM.update(2,HIGH); delay(100);
  digitalWrite(relay4, HIGH); EEPROM.update(3,HIGH); delay(100);
}

void manual_control()
{
  if (digitalRead(switch1) == LOW && state_1 == LOW) {
    digitalWrite(relay1, LOW);
    EEPROM.update(0,LOW);
    state_1 = HIGH;
  }
  if (digitalRead(switch1) == HIGH && state_1 == HIGH) {
    digitalWrite(relay1, HIGH);
    EEPROM.update(0,HIGH);
    state_1 = LOW;
  }
  if (digitalRead(switch2) == LOW && state_2 == LOW) {
    digitalWrite(relay2, LOW);
    EEPROM.update(1,LOW);
    state_2 = HIGH;
    Serial.println("Switch-2 on");
  }
  if (digitalRead(switch2) == HIGH && state_2 == HIGH) {
    digitalWrite(relay2, HIGH);
    EEPROM.update(1,HIGH);
    state_2 = LOW;
    Serial.println("Switch-2 off");
  }
  if (digitalRead(switch3) == LOW && state_3 == LOW) {
    digitalWrite(relay3, LOW);
    EEPROM.update(2,LOW);
    state_3 = HIGH;
    Serial.println("Switch-3 on");
  }
  if (digitalRead(switch3) == HIGH && state_3 == HIGH) {
    digitalWrite(relay3, HIGH);
    EEPROM.update(2,HIGH);
    state_3 = LOW;
    Serial.println("Switch-3 off");
  }
  if (digitalRead(switch4) == LOW && state_4 == LOW) {
    digitalWrite(relay4, LOW);
    EEPROM.update(3,LOW);
    state_4 = HIGH;
    Serial.println("Switch-4 on");
  }
  if (digitalRead(switch4) == HIGH && state_4 == HIGH) {
    digitalWrite(relay4, HIGH);
    EEPROM.update(3,HIGH);
    state_4 = LOW;
    Serial.println("Switch-4 off");
  }
}  

void setup() {
  Serial.begin(9600);


  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);

  pinMode(switch1, INPUT_PULLUP);
  pinMode(switch2, INPUT_PULLUP);
  pinMode(switch3, INPUT_PULLUP);
  pinMode(switch4, INPUT_PULLUP);

  //During Starting all Relays should TURN OFF
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
  
  delay(500);
  eepromState();
}

void loop() {
  bluetooth_control();
  manual_control();
}


Conclusion:

Arduino home automation provides a convenient and cost-effective way to control and automate devices in your home. By using Bluetooth, manual switches, and EEPROM, you can create a home automation system that is easy to use and provides endless possibilities for customization.

Whether you want to turn your lights on and off remotely, adjust the temperature of your air conditioner from your smartphone, or use manual switches to control your devices directly, Arduino home automation can help you achieve your goals. With the right components and a little programming knowledge, you can create a home automation system that is tailored to your specific needs and preferences.

Post a Comment

0 Comments