-2

I have made a home automation project.

Description: Light on, off through HC-05 Bluetooth module and my Android app. The problem is when the power is gone, the system stops, that's OK. After that, when the power comes back, the system remains off, as because of no storage of the value.

Please any one help me, that how to store Bluetooth data on EEPROM on Arduino. My simple code looks like...

#include <EEPROM.h>
#define ledPin 7
int state = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.begin(9600); // Default communication rate of the Bluetooth module
}

void loop() {

  if(Serial.available() > 0){ // Checks whether data is comming from the serial port
    state = Serial.read(); // Reads the data from the serial port
  }

  if (state == '0') {
    digitalWrite(ledPin, LOW); // Turn LED OFF
    Serial.println("LED: OFF"); // Send back, to the phone, the String "LED: ON"
    state = 0;
  }
  else if (state == '1') {
    digitalWrite(ledPin, HIGH);
    Serial.println("LED: ON");;
    state = 0;
  } 
}
  • Don't shout next time! Also format the code correctly. – chrisl Jun 28 '18 at 11:46
  • Have you tried to use the EEPROM examples from the Arduino IDE? There is a library for using the EEPROM. Do you have any specific problem with it? – chrisl Jun 28 '18 at 12:23
0

Sir you didn't used EEPROM functions, you just initialized them. For example

if you use these function then your issue will be solved out..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.