saving relay current status during power outage (Noob here, help needed)

my code suppose to control a set of relays with blynk and to save the status of the relays after power outage.
I connected analog pins to the matrix that connect between the arduino and the set of relays and I checked the status of the relay and turned it into a variable, I have 8 relays and I want there status to preserved after a power outage please help me.

this is my code:

#include <EEPROM.h>
     
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V3);
WidgetLED led4(V4);
WidgetLED led5(V5);
WidgetLED led6(V6);
WidgetLED led7(V7);
WidgetLED led8(V8);

int sec = 0;
int mint = 0;


int val = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;

int salt =0;
int salt1 =0;
int salt2 =0;
int salt3 =0;
int salt4 =0;
int salt5 =0;
int salt6 =0;
int salt7 =0;


 int BLYNK_PRINT;

uint8_t EEPROMadress = 130;
uint8_t EEPROMadress1 = 135;
uint8_t EEPROMadress2 = 140;
uint8_t EEPROMadress3 = 145;
uint8_t EEPROMadress4 = 150;
uint8_t EEPROMadress5 = 155;
uint8_t EEPROMadress6 = 160;
uint8_t EEPROMadress7 = 165;
char auth[] = "cdcfeb90aa8f43c1a22684dcb52f05b9";

void setup()
{ 
  
 
  
  
  
  
  
  Serial.begin(9600);
  Blynk.begin(auth);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);

 
  
 
  if (1000< EEPROM.read (EEPROMadress)>1050) 
  {
   digitalWrite (3 ,HIGH);
   
    
   }
   

  if (700<EEPROM.read (EEPROMadress1)>750); 
  {
   digitalWrite (6 ,HIGH);
   
    
    }
    
     
     if (800<EEPROM.read (EEPROMadress2)>850); 
  {
   digitalWrite (5 ,HIGH);
   
    
    }
     if (400<EEPROM.read (EEPROMadress3)>450); 
  {
   digitalWrite (4 ,HIGH);
   
    
    }
     if (600<EEPROM.read (EEPROMadress4)>650); 
  {
   digitalWrite (7 ,HIGH);
   
    
    }
     if (900<EEPROM.read (EEPROMadress5)>950); 
  {
   digitalWrite (9 ,HIGH);
   
    
    }
      if (500<EEPROM.read (EEPROMadress6)>550); 
  {
   digitalWrite (8 ,HIGH);
   
    
    }
       if (300<EEPROM.read (EEPROMadress7)>350); 
  {
   digitalWrite (2 ,HIGH);
   
    
    }  
     
 
  
}
 int periodStartMillis = millis();
void loop()
{
  val = analogRead(1);
  val1 = analogRead(2);
  val2 = analogRead(3);
  val3 = analogRead(4);
  val4 = analogRead(5);
  val5 = analogRead(7);
  val6 = analogRead(8);
  val7 = analogRead(0);
 
 salt=val;
 salt1=val1-100;
 salt2=val2-200;
 salt3=val3-300;
 salt4=val4-400;
 salt5=val5-500;
 salt6=val6-600;
 salt7=val7-700;
Serial.println("salt=");  
Serial.println(salt);
Serial.println("salt1="); 
Serial.println(salt1);
Serial.println("salt2="); 
Serial.println(salt2);
Serial.println("salt3="); 
Serial.println(salt3);
Serial.println("salt4=");
Serial.println(salt4);
Serial.println("salt5="); 
Serial.println(salt5);
Serial.println("salt6="); 
Serial.println(salt6);
Serial.println("salt7="); 
Serial.println(salt7);

if (periodStartMillis == 1000) {
  sec+1;
  periodStartMillis = 0; 
}

if (sec == 60){
  mint+1;
  sec =0;
}


if (mint ==5 )
{
  EEPROM.write (EEPROMadress,salt);
  EEPROM.write (EEPROMadress1,salt1);
  EEPROM.write (EEPROMadress2,salt2);
  EEPROM.write (EEPROMadress3,salt3);
  EEPROM.write (EEPROMadress4,salt4);
  EEPROM.write (EEPROMadress5,salt5);
  EEPROM.write (EEPROMadress6,salt6);
  EEPROM.write (EEPROMadress7,salt7);

mint = 0;
}

 

  
  Serial.println(periodStartMillis);
Serial.println(sec);
Serial.println(mint);
  Blynk.run();



}

What is the problem? What is wanted and what happends?

ron_akkerman_16:
if (1000< EEPROM.read (EEPROMadress)>1050)
{
digitalWrite (3 ,HIGH);

Your comparison construction is incorrect. You need two separate compares, one for each limit (enclosed in parentheses for clarity) joined by a logical

and

or a logical

or

, as the case may be.

Props for code tags on your first post.

I want to save the current status of my relays after a power outage a used blynk to control a set of relays but after a power outage they changing their status (they are turning of) I connected analog pins on a matrix and the digital pins also (if you wont i can send a sketch) so they are checking if the relays get pulse or not and they turn it into variable I want to save this variable in the EEprome and use it to power up the relays or power down them in the setup. thank you for helping.
this is my code:

#include <EEPROM.h>
     
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
WidgetLED led1(V1);
WidgetLED led2(V2);
WidgetLED led3(V3);
WidgetLED led4(V4);
WidgetLED led5(V5);
WidgetLED led6(V6);
WidgetLED led7(V7);
WidgetLED led8(V8);

int sec = 0;
int mint = 0;


int val = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;

int salt =0;
int salt1 =0;
int salt2 =0;
int salt3 =0;
int salt4 =0;
int salt5 =0;
int salt6 =0;
int salt7 =0;


 int BLYNK_PRINT;

uint8_t EEPROMadress = 130;
uint8_t EEPROMadress1 = 135;
uint8_t EEPROMadress2 = 140;
uint8_t EEPROMadress3 = 145;
uint8_t EEPROMadress4 = 150;
uint8_t EEPROMadress5 = 155;
uint8_t EEPROMadress6 = 160;
uint8_t EEPROMadress7 = 165;
char auth[] = "cdcfeb90aa8f43c1a22684dcb52f05b9";

void setup()
{ 
  
 
  
  
  
  
  
  Serial.begin(9600);
  Blynk.begin(auth);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);

 
  
 
  if (1000< EEPROM.read (EEPROMadress)>1050) 
  {
   digitalWrite (3 ,HIGH);
   
    
   }
   

  if (700<EEPROM.read (EEPROMadress1)>750); 
  {
   digitalWrite (6 ,HIGH);
   
    
    }
    
     
     if (800<EEPROM.read (EEPROMadress2)>850); 
  {
   digitalWrite (5 ,HIGH);
   
    
    }
     if (400<EEPROM.read (EEPROMadress3)>450); 
  {
   digitalWrite (4 ,HIGH);
   
    
    }
     if (600<EEPROM.read (EEPROMadress4)>650); 
  {
   digitalWrite (7 ,HIGH);
   
    
    }
     if (900<EEPROM.read (EEPROMadress5)>950); 
  {
   digitalWrite (9 ,HIGH);
   
    
    }
      if (500<EEPROM.read (EEPROMadress6)>550); 
  {
   digitalWrite (8 ,HIGH);
   
    
    }
       if (300<EEPROM.read (EEPROMadress7)>350); 
  {
   digitalWrite (2 ,HIGH);
   
    
    }  
     
 
  
}
 int periodStartMillis = millis();
void loop()
{
  val = analogRead(1);
  val1 = analogRead(2);
  val2 = analogRead(3);
  val3 = analogRead(4);
  val4 = analogRead(5);
  val5 = analogRead(7);
  val6 = analogRead(8);
  val7 = analogRead(0);
 
 salt=val;
 salt1=val1-100;
 salt2=val2-200;
 salt3=val3-300;
 salt4=val4-400;
 salt5=val5-500;
 salt6=val6-600;
 salt7=val7-700;
Serial.println("salt=");  
Serial.println(salt);
Serial.println("salt1="); 
Serial.println(salt1);
Serial.println("salt2="); 
Serial.println(salt2);
Serial.println("salt3="); 
Serial.println(salt3);
Serial.println("salt4=");
Serial.println(salt4);
Serial.println("salt5="); 
Serial.println(salt5);
Serial.println("salt6="); 
Serial.println(salt6);
Serial.println("salt7="); 
Serial.println(salt7);

if (periodStartMillis == 1000) {
  sec+1;
  periodStartMillis = 0; 
}

if (sec == 60){
  mint+1;
  sec =0;
}


if (mint ==5 )
{
  EEPROM.write (EEPROMadress,salt);
  EEPROM.write (EEPROMadress1,salt1);
  EEPROM.write (EEPROMadress2,salt2);
  EEPROM.write (EEPROMadress3,salt3);
  EEPROM.write (EEPROMadress4,salt4);
  EEPROM.write (EEPROMadress5,salt5);
  EEPROM.write (EEPROMadress6,salt6);
  EEPROM.write (EEPROMadress7,salt7);

mint = 0;
}

 

  
  Serial.println(periodStartMillis);
Serial.println(sec);
Serial.println(mint);
  Blynk.run();



}

Many errors in that code, even before starting the EEPROM part (indeed that’s where you can store your values)

ron_akkerman_16:

  if (1000< EEPROM.read (EEPROMadress)>1050)

That’s not going to work.
EEPROM.read() returns the value of that one byte, which can be 0-255.
I actually don’t know how that statement is even evaluated. I guess the first part first (resulting in true/false or 0/1), which is always < 1050 so overall always false.

Instead do something like:

  int val;
  EEPROM.get(EEPROMadress, val);
  if (val > 1000 && val < 1050) {
   digitalWrite (3 ,HIGH);
  }
  val = analogRead(1);

val1 = analogRead(2);
  val2 = analogRead(3);
  val3 = analogRead(4);
  val4 = analogRead(5);
  val5 = analogRead(7);
  val6 = analogRead(8);
  val7 = analogRead(0);

What type of Arduino are you using?

EEPROM.write() is again for a single byte. Use EEPROM.put().

Then you write there a value of salt which is not the value which you test against (you made a deduction), but you don’t correct for that deduction after reading back the value.

Finally, don’t write values to EEPROM so often. You have only some 100,000 writes to play with - which is a few minutes of running time for your sketch. Well, in practice the EEPROM often works for 1-2 million writes, that 100k is the guaranteed number, still you’re guaranteed to wear it out within an hour, and then at least those cells of the the EEPROM are dead and unusable. Only write when you have a change in status of the relay. Indeed you better just write the actual relay state in EEPROM rather than this val value.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.

DON'T CROSS POST!!!!!!!!!!!!!!!!!!!!

I HAVE REPORTED THIS THREAD TO THE MODERATORS

Duplicate posts waste the time of the people helping you. I might spend 15 minutes writing a detailed answer on this thread, without knowing that someone already did the same in the other thread. This behavior is very disrespectful to the people you're asking for assistance. Just because we give our time freely doesn't mean it has no value.

In the future, take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, which you would already know if you had bothered reading the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

I am very sorry it does not suppose to be offensive I am a beginner and I dont now all the things I need to do
a used arduino mega 2560
and after the power outage occurs all the relays turns off