EEPROM Memory,Android App and Manual Control Home Automation System.

EEPROM Memory,Android App and Manual Control Home Automation System.

EEPROM Memory,Android App and Manual Control Home Automation System.

Hello friends, In this article we are going to make Home Automation System which can be controlled with Smartphone as well as Manual Buttons.

In this project we will be storing data in the EEPROM Memory of Arduino so when there is any power cutoff and when the power is back again it will continue the last saved state.

What is EEPROM?

EEPROM (also E2PROM) stands for electrically erasable programmable read-only memory and is a type of non-volatile memory used in computers, integrated in microcontrollers for smart cards and remote keyless systems, and other electronic devices to store relatively small amounts of data by allowing individual bytes to be erased and reprogrammed.

Components Required

Designing the PCB.

To design the circuit and PCB, we used EasyEDA which is a browser based software to design PCBs.

Designing the circuit works like in any other circuit software tool, you place some components and you wire them together. Then, you assign each component to a footprint.Having the parts assigned, place each component. When you’re happy with the layout, make all the connections and route your PCB.

Save your project and export the Gerber files.

Ordering the PCBs at PCBWay

This project is sponsored by PCBWay. PCBWay is a full feature Printed Circuit Board manufacturing service.

Turn your DIY breadboard circuits into professional PCBs – get 10 boards for approximately $5 + shipping (which will vary depending on your country).

Once you have your Gerber files, you can order the PCB. Follow the next steps.

1. Download the Gerber files – click here to download the .zip file.

2. Go to PCBWay website and open the PCB Instant Quote page. 


3. PCBWay can grab all the PCB details and automatically fills them for you. Use the “Quick-order PCB (Autofill parameters)”.

4. Press the “+ Add Gerber file” button to upload the provided Gerber files.

After approximately one week using the DHL shipping method, I received the PCBs at my place.

As usual, everything comes well packed, and the PCBs are really high-quality. The letters on the silkscreen are really well-printed and easy to read. Additionally, the solder sticks easily to the pads.

PCBWay Year End Big Sale and Christmas Shopping Festival 2021.

PCBWay are now offering different sales offers and coupons at Christmas Festival 2021. I hope you will not miss the opportunity and avail of these offers as soon as possible. Since limited days are remaining. 

So let’s get started with PCBWay Year End Big Sale & Christmas Shopping Festival 2021.

The PCBWay is PCB producing company based in China and offers numerous services such as PCB with different types such as single layer PCB, double Layer PCB, multilayer PCB, etc, with that PCB prototyping services and PCBA.

Now regard Christmas they are providing different offers through using them you can get Free Christmas Coupons and Up to 52% Off for 3D Printing & CNC Machining.

Special Sales in PCBWay Store!

PCBWayhas providing special sales in their store, using them you can get Up to 50% Off on different electronic modules like ESP32, ARDUINO BOARDS , IPS touch screen display, Robotic Arm etc

Lucky Draw.

With all these offers here & Coupons, One lucky draw is also conducted. To take part in this lucky draw the last date is December 31, 2021.

                                                            Rules.

1.Each PCBWayer (who had PCBWay shopping experience before) has TWO chances to draw the lottery. And ONE extra chance will be given if you place any order during December.

2.The beans would be automatically added into your account. You can use it to redeem modules in PCBWay store.

3.If you have any questions about how to redeem modules, please contact anson@pcbway.com.

Let's Make it...!

Now grab all the components whose list is mention above, and soldered on the PCB.

After soldiering rest of components PCB look like this neat, clean and well arranged.

Connection of Switches & Bulbs.

Connect all the switches and bulb as shown schematic below.

Android Application.

Download the APK file in your your smartphone and install.

Pair your phone with HC-05 bluetooth module.

Code.

Copy the following code to your Arduino IDE and upload it to your Arduino board.

#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>
String readString;

 int relay_1 = 2;
 int relay_2 = 3;
 int relay_3 = 9;
 int relay_4 = 10;


const int mswitch_1 = 5;
const int mswitch_2 = 6;
const int mswitch_3 = 7;
const int mswitch_4 = 8;



int toggleState_1 = 0; 
int toggleState_2 = 0; 
int toggleState_3 = 0; 
int toggleState_4 = 0;

void setup() {
 
  Serial.begin(9600);
  
  pinMode(relay_1, OUTPUT);
  pinMode(relay_2, OUTPUT);
  pinMode(relay_3, OUTPUT);
  pinMode(relay_4, OUTPUT);

  pinMode(mswitch_1, INPUT);
  pinMode(mswitch_2, INPUT);
  pinMode(mswitch_3, INPUT);
  pinMode(mswitch_4, INPUT);

  eepromcheckstate();
}

void relayOnOff(int relay){

switch(relay){
      case 1: 
             if(toggleState_1 == 0){
              digitalWrite(relay_1, HIGH); // turn on relay 1
              EEPROM.update(0,HIGH);
              toggleState_1 = 1;
              }
             else{
              digitalWrite(relay_1, LOW); // turn off relay 1
              EEPROM.update(0,LOW);
              toggleState_1 = 0;
              }
             delay(100);
      break;
      case 2: 
             if(toggleState_2 == 0){
              digitalWrite(relay_2, HIGH); // turn on relay 2
              EEPROM.update(1,HIGH);
              toggleState_2 = 1;
              }
             else{
              digitalWrite(relay_2, LOW); // turn off relay 2
              EEPROM.update(1,LOW);
              toggleState_2 = 0;
              }
             delay(100);
      break;
      case 3: 
             if(toggleState_3 == 0){
              digitalWrite(relay_3, HIGH); // turn on relay 3
              EEPROM.update(2,HIGH);
              toggleState_3 = 1;
              }else{
              digitalWrite(relay_3, LOW); // turn off relay 3
              EEPROM.update(2,LOW);
              toggleState_3 = 0;
              }
             delay(100);
      break;
      case 4: 
             if(toggleState_4 == 0){
              digitalWrite(relay_4, HIGH); // turn on relay 4
              EEPROM.update(3,HIGH);
              toggleState_4 = 1;
              }
             else{
              digitalWrite(relay_4, LOW); // turn off relay 4
              EEPROM.update(3,LOW);
              toggleState_4 = 0;
              }
             delay(100);
      break;
           
      default : break;      
      }
  
}

void eepromcheckstate()
{

  toggleState_1 = EEPROM.read(0);
  if(toggleState_1 == HIGH) {
    digitalWrite(relay_1, HIGH);
   }   
   if(toggleState_1 == LOW) {
    digitalWrite(relay_1, LOW);
   }   
   
  toggleState_2 = EEPROM.read(1); 
  if(toggleState_2 == HIGH) {
    digitalWrite(relay_2, HIGH);
   }   
   if(toggleState_2 == LOW) {
    digitalWrite(relay_2, LOW);
   }
     
  toggleState_3 = EEPROM.read(2);
  if(toggleState_3 == HIGH) {
    digitalWrite(relay_3, HIGH);
   }   
   if(toggleState_3 == LOW) {
    digitalWrite(relay_3, LOW);
   }

  toggleState_4 = EEPROM.read(3);
  if(toggleState_4 == HIGH) {
    digitalWrite(relay_4, HIGH);
   }   
   if(toggleState_4 == LOW) {
    digitalWrite(relay_4, LOW);
   }

}


void loop() {     
     
    if (digitalRead(mswitch_1) == LOW){
      delay(200);
      relayOnOff(1);      
    }
    else if (digitalRead(mswitch_2) == LOW){
      delay(200);
      relayOnOff(2);
    }
    else if (digitalRead(mswitch_3) == LOW){
      delay(200);
      relayOnOff(3);
    }
    else if (digitalRead(mswitch_4) == LOW){
      delay(200);
      relayOnOff(4);
    }

      while(Serial.available())    //Check if there are available bytes to read
  {
    delay(10);                 //Delay to make it stable
    char c = Serial.read();    //Conduct a serial read
    if (c == '#'){
      break;                   //Stop the loop once # is detected after a word
    }
    readString += c;                //Means readString = readString + c
  }
    if (readString.length() >0)
    {
      Serial.println(readString);
                  
      if(readString == "RELAY1"){   
        relayOnOff(1);
      }
      else if(readString == "RELAY2"){   
        relayOnOff(2);
      }
      else if(readString == "RELAY3"){   
        relayOnOff(3);
      }
      else if(readString == "RELAY4"){   
        relayOnOff(4);
      }
      readString="";
    }
  }

Copy above code and upload in your Arduino Nano Board after selecting right board & COM Port in arduino ide.

Thank you for reading!!

One thought on “EEPROM Memory,Android App and Manual Control Home Automation System.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top