how can i read 2 different address in eeprom

hi can please help with i have 2 different address of eeprom the problem was when i try to print in the serial monitor my second eeprom address my first address has been printed by serial monitor this is my code

#include <Servo.h>
#include <Keypad.h>
#include<EEPROM.h>
Servo Sm;
char password[4];
char pass[4],pass1[4];
int i=0;
int position = 0;
char targetamount[4]={0,0,0,0};
char customKey=0;
const byte ROWS = 4; 
const byte COLS = 4; 
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {3,4,5,6}; //connection ng row pin sa arduino
byte colPins[COLS] = {7,8,9,10}; //connection ng colum pin sa arduino
//initialize ng intance sa keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 
void setup()
{
  
   Sm.attach(10);
   Serial.begin(9600);
   Serial.println("welcome to zion coin bank");
   Serial.println("Enter Passcode");
   //lcd.print("Welcome to zion coin bank");
  //lcd.print("Enter Ur Passkey:");
  //lcd.setCursor(0,1);
  //char customPad = customKeypad.getKey();  
  //if (customPad == '*')
  //{
   //for(int j=0;j<4;j++)
   //EEPROM.write(j, j+49);
   //for(int j=0;j<4;j++)
   //pass[j]=EEPROM.read(j);
  
  }
  
void loop()
{
  
  
  
  customKey = customKeypad.getKey();

if (customKey == 'B')
{
      for(int c = 0; c < 4; c++)
    {
     Serial.println(targetamount[c] = EEPROM.read(c));
    }
}
if (customKey == '*')
{
  target();
}
  
  if (customKey == 'C')
  {
    reset();
  }
  if(customKey == '#')
  change();
  
  if (customKey)
  {
     password[i++]=customKey;
     
      Serial.print(customKey);     
     
     
  }
  if(i==4)
  {
    //delay(200);
    for(int j=0;j<4;j++)
    pass[j]=EEPROM.read(j);
    if(!(strncmp(password, pass,4)))
    {
     
      Serial.println("Passcode Accepted");
      Sm.write(5);// servo at 90
      i=0;
     
    }
    
    else
    {
     
      Serial.println("Passcode Denied");
      Serial.println("Enter Correct Passcode");
      i=0;
     
    }
  }
}
void change()
{
  int j=0;
  Serial.println("Enter your Current Passcode");
 
  while(j<4)
  {
    char key=customKeypad.getKey();
    if(key)
    {
      pass1[j++]=key;
      Serial.print(key);
       
    }
    key=0;
  }
  
  if((strncmp(pass1, pass, 4)))
  {
    Serial.println("Wrong Passcode");
   
    Serial.println("Please Input Your passcode");
  }
  else
  {
    j=0;
    
  //lcd.clear();
  Serial.println("Enter New Passcode");
 
  while(j<4)
  {
    char key=customKeypad.getKey();
    if(key)
    {
      pass[j]=key;
      Serial.print(key);
      //lcd.print(key);
      EEPROM.write(j,key);
      j++;
      //beep();
    }
  }
  Serial.println("PassCode Has been Change");
  Serial.println("Enter your passcode");
  
  }
  customKey=0;
}
void reset()
{
  for(int j=0;j<4;j++)
   EEPROM.write(j, j+49);
   for(int j=0;j<4;j++)
   pass[j]=EEPROM.read(j);
   Serial.println("Passcode has been Resset");
   
   Serial.println("Please Enter Passcode");
   
   customKey=0;
    
  }
    
void target()
{
  int r = 0;
  int c = 4;
   Serial.println("Enter the amount you want to saved");
  while (r<4)
  {
    char key=customKeypad.getKey();
    if (key)
    {
     targetamount[r] = key;
     Serial.print(key);
     EEPROM.write(c,key);
     r++;
     c++;
    } 
  }
  
  Serial.print("taget amount saved");
  customKey = 0;
}

Please provide a clearer description of your problem. A description of what your program is supposed to be doing would also help.

Weedpharma

Nowhere do you use 2 different addresses in EEPROM for different purposes. Actually you always use the first four.

Serial.println(targetamount

 = EEPROM.read(c));

  try:

  targetamount[c] = EEPROM.read(c);
  Serial.println(targetamount[c]);

sir larry it’s has same result it show my first address

weedpharma sir i have 2 defferent address on eeprom one is passcode ang the other one is the target amount my problem was when i try to print in the serial monitor my target amount it wont show instead the passcode was printed on the serial monitor

aarg sir can you give a sample on what to do how can i code that?

const byte PASS1 = 0;
const byte PASS2 = 4;
//...
  for(int j=0;j<4;j++)
{
   pass[j]=EEPROM.read(j+PASS2);
//...

sir aarg it has the same result

I’m sorry, I can only make suggestions. I can’t teach you how to program. I can’t really experiment with your code because I don’t have your hardware. The general approach that I suggested above WILL work, if you use it correctly.

If you post the program again, with the changes you made, perhaps someone will advise you on what you did wrong.

amc12: sir larry it's has same result

So it's Sir Larry now, is it? ;)

sir aarg it has the same result

Sir aarg

So it's Sir Larry now, is it? ;)

Sir? hell I am a enlisted man, Saint Nick.

my prob with this is when i try to print in the serial monitor the targetamount value it wont display instead it display the value of my passwor

#include <Servo.h>
#include <Keypad.h>
#include<EEPROM.h>
Servo Sm;
char password[4];
char pass[4],pass1[4];
int i=0;
int position = 0;
char targetamount[4]={0,0,0,0};
char customKey=0;
const byte ROWS = 4; 
const byte COLS = 4; 
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {3,4,5,6}; //connection ng row pin sa arduino
byte colPins[COLS] = {7,8,9,10}; //connection ng colum pin sa arduino
//initialize ng intance sa keypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 
void setup()
{
  
   Sm.attach(10);
   Serial.begin(9600);
   Serial.println("welcome to zion coin bank");
   Serial.println("Enter Passcode");
  
 
  
  
  }
  
void loop()
{
  
  
  
  customKey = customKeypad.getKey();

if (customKey == 'B')
{
      for(int n = 0; n < 4; n++)
    {
     targetamount[n] = EEPROM.read(n);
     Serial.println(targetamount[n]);
    }
}
if (customKey == '*')
{
  target();
}
  
  if (customKey == 'D')
  {
    reset();
  }
  if(customKey == '#')
  change();
  
  if (customKey)
  {
     password[i++]=customKey;
     
      Serial.print(customKey);     
     
     
  }
  if(i==4)
  {
    //delay(200);
    for(int j=0;j<4;j++)
    pass[j]=EEPROM.read(j);
    if(!(strncmp(password, pass,4)))
    {
     
      Serial.println("Passcode Accepted");
      Sm.write(5);// servo at 90
      i=0;
     
    }
    
    else
    {
     
      Serial.println("Passcode Denied");
      Serial.println("Enter Correct Passcode");
      i=0;
     
    }
  }
}
void change()
{
  int j=0;
  Serial.println("Enter your Current Passcode");
 
  while(j<4)
  {
    char key=customKeypad.getKey();
    if(key)
    {
      pass1[j++]=key;
      Serial.print(key);
       
    }
    key=0;
  }
  
  if((strncmp(pass1, pass, 4)))
  {
    Serial.println("Wrong Passcode");
   
    Serial.println("Please Input Your passcode");
  }
  else
  {
    j=0;
    
  //lcd.clear();
  Serial.println("Enter New Passcode");
 
  while(j<4)
  {
    char key=customKeypad.getKey();
    if(key)
    {
      pass[j]=key;
      Serial.print(key);
      //lcd.print(key);
      EEPROM.write(j,key);
      j++;
      //beep();
    }
  }
  Serial.println("PassCode Has been Change");
  Serial.println("Enter your passcode");
  
  }
  customKey=0;
}
void reset()
{
  for(int j=0;j<4;j++)
   EEPROM.write(j, j+49);
   for(int j=0;j<4;j++)
   pass[j]=EEPROM.read(j);
   Serial.println("Passcode has been Resset");
   
   Serial.println("Please Enter Passcode");
   
   customKey=0;
    
  }
    
void target()
{
  int r = 0;
  int c = 4;
  Serial.print("Input target amount");
  while (r<4)
  {
    char key=customKeypad.getKey();
    if (key)
    {
     targetamount[r] = key;
     Serial.print(key);
     EEPROM.write(c,key);
     r++;
     c++;
    } 
  }
  
  Serial.print("taget amount saved");
  customKey = 0;
}

I find your code difficult to follow, but the below code reads the first 4 bytes from eeprom

  if (customKey == 'B')
  {
    for (int n = 0; n < 4; n++)
    {
      targetamount[n] = EEPROM.read(n);
      Serial.println(targetamount[n]);
    }
  }

As far as I can figure it out, those contain the password and not the target amount. The target amount is (I think) stored in the next 4 locations.

So if you change the for loop to read the second 4 instead of the first 4 you should be OK.

  if (customKey == 'B')
  {
    for (int n = 4; n < 8; n++)
    {
      targetamount[n] = EEPROM.read(n);
      Serial.println(targetamount[n]);
    }
  }

Suggestion: never ever use single character variable names at a global level. You have e.g. an global int i.

Looking further for that variable, it’s initialized with 0 and never changed. Hence your if (i == 4) will never be true.

Why can you use punctuation in your code but is it impossible to use it here?

And watch your code formatting. Press ctrl+t and see how much more readable the code becomes.

And to answer the question, of course. You try to store everything in the same EEPROM. The password and the amount, you always use 0 to 3 as the address.

Look at it as lockers in which you can store one number per locker. But the only lockers you use are 0 to 1.
Here for the password

    while (j < 4)
    {
      char key = customKeypad.getKey();
      if (key)
      {
        pass[j] = key;
        Serial.print(key);
        //lcd.print(key);
        EEPROM.write(j, key);
        j++;
        //beep();
      }
    }

Here for the amount

    for (int n = 0; n < 4; n++)
    {
      targetamount[n] = EEPROM.read(n);
      Serial.println(targetamount[n]);
    }

You can fix that by planning the locations in EEPROM. Let’s say to use 0 to 3 for the password and 4 to 7 for the amount. So starting at 0 and 4.

const byte EepromPassword = 0;
const byte EepromAmount = 4

The above code becomes now

    for (int n = 0; n < 4; n++)
    {
      targetamount[n] = EEPROM.read(EepromAmount + n);
      Serial.println(targetamount[n]);
    }

You have to do this on all locations where you read write to EEPROM. This way you give every variable a starting place.