Writing Values bigger than 255 on EEPROM?

In my project I need to store big 10 digit passwords that have only numbers. I dont understand eeprom in depth but I have been messing around with only 3 basic commands, write(), update(), and read().

Here is my main project code:

#include <Keypad.h>
#include <LiquidCrystal.h>

int currentRow = 1;  // Start with the second row
const int LED = 2;
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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] = { 8, 7, 6, 5 };
byte colPins[COLS] = { 12, 11, 10, 9 };

Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

String DEFAULT_PASSCODE = "1501";
String passcode = "";
String confirmPasscode = "";  // Variable to store the confirmed passcode
String Newpasscode = "";

enum State {
  ENTER_PASSCODE,
  PRESS_A_TO_START,
  PASSCODE_CHANGE,
  ENTER_NEW_PASSCODE,
  CONFIRM_NEW_PASSCODE
};

State currentState = ENTER_PASSCODE;
bool passcodeChangeRequested = false;
int passcodeLength = 0;  // Variable to keep track of the number of characters entered during passcode reset

void setup() {
  pinMode(LED, OUTPUT);
  lcd.begin(16, 2);
  lcd.print("Enter Passcode:");
}

void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    switch (currentState) {
      case ENTER_PASSCODE:
        handlePasscodeInput(key);
        break;

      case PRESS_A_TO_START:
        if (key == 'A') {
          lcd.clear();
          lcd.print("Press B to Stop");
          digitalWrite(LED, HIGH);  // Turn on the LED
        } else if (key == 'B') {
          currentState = ENTER_PASSCODE;
          lcd.clear();
          lcd.print("Enter Passcode:");
          passcode = "";
          digitalWrite(LED, LOW);  // Turn on the LED
        } else if (key == '*') {
          passcodeChangeRequested = true;
          currentState = ENTER_NEW_PASSCODE;
          lcd.clear();
          lcd.print("Enter New Pass:");
          Newpasscode = "";
        }
        break;

      case ENTER_NEW_PASSCODE:
        handleNewPasscodeInput(key);  // Call handleNewPasscodeInput function
        if (key == '#') {
          currentState = CONFIRM_NEW_PASSCODE;
          lcd.clear();
          lcd.print("Confirm Pass:");
        } else if (key == 'B') {
          currentState = ENTER_PASSCODE;
          passcode = "";
          passcodeChangeRequested = false;
          passcodeLength = 0;  // Reset the passcode length
          lcd.clear();
          lcd.print("Enter Passcode:");
        }
        break;

      case CONFIRM_NEW_PASSCODE:
        handleConfirmPasscodeInput(key);            // Call handleConfirmPasscodeInput function
        break;
    }
  }
}

void handlePasscodeInput(char key) {
  if (key != NO_KEY) {
    if (passcode.length() < DEFAULT_PASSCODE.length()) {
      passcode += key;
      lcd.setCursor(passcode.length() - 1, 1);
      lcd.print("*");  // Display an asterisk for each character entered
    }

    if (passcode.length() == DEFAULT_PASSCODE.length()) {
      if (passcode.equals(DEFAULT_PASSCODE)) {
        currentState = PRESS_A_TO_START;
        lcd.clear();
        lcd.print("Press A to start");
      } else {
        lcd.clear();
        lcd.print("Incorrect Password");
        lcd.setCursor(0, 1);
        lcd.print("Please Try again");
        delay(2000);
        lcd.clear();
        lcd.print("Enter Passcode:");
        lcd.setCursor(0, 1);
        passcode = "";
      }
    }
  }
}

void handleNewPasscodeInput(char key) {
  if (key == '#') {  // Change state when '=' key is pressed
    currentState = CONFIRM_NEW_PASSCODE;
    lcd.clear();
    lcd.print("Confirm Pass:");
  } else if (key == 'B') {  // Reset passcode when 'B' key is pressed
    currentState = ENTER_PASSCODE;
    lcd.clear();
    lcd.print("Enter Passcode:");
    lcd.setCursor(0, 1);
    passcode = "";
  } else if (key != NO_KEY) {
    Newpasscode += key;
    lcd.setCursor(Newpasscode.length() - 1, 1);
    lcd.print("*");
  }
}

void handleConfirmPasscodeInput(char key) {
  if (key == '#') {  // Change state when '=' key is pressed
    if (Newpasscode == confirmPasscode) {  // Check if the passcodes match
      DEFAULT_PASSCODE = confirmPasscode;  // Update the default passcode
      currentState = ENTER_PASSCODE;
      lcd.clear();
      lcd.print("Passcode set");
      delay(2000);
      lcd.clear();
      lcd.print("Enter Passcode:");
      lcd.setCursor(0, 1);
      passcode = "";
      passcodeLength = 0;  // Reset the passcode length
    } else {
      lcd.clear();
      lcd.print("Passcodes don't");
      lcd.setCursor(0, 1);
      lcd.print("match. Try again.");
      delay(2000);
      lcd.clear();
      lcd.print("Enter New Pass:");
      lcd.setCursor(0, 1);
      Newpasscode = "";
      confirmPasscode = "";
      passcodeLength = 0;  // Reset the passcode length
      currentState = ENTER_NEW_PASSCODE;  // Return to the new passcode entry state
    }
  } else if (key == 'B') {  // Reset passcode when 'B' key is pressed
    currentState = ENTER_PASSCODE;
    lcd.clear();
    lcd.print("Enter Passcode:");
    lcd.setCursor(0, 1);
    passcode = "";
    passcodeLength = 0;  // Reset the passcode length
  } else if (key != NO_KEY) {
    confirmPasscode += key;
    lcd.setCursor(confirmPasscode.length() - 1, 1);
    lcd.print("*");  // Display the entered digit
    passcodeLength++;  // Increment the passcode length
  }
}

Where it says DEFAULT_PASSCODE = confirmPasscode; // Update the default passcode is exactly what I need to update into the EEPROM. DEFAULT_PASSCODE always needs to be on cell 0 just incase I forget my passcode and I cant get in and so all updated passcodes needs to be on cell 1 I say cell but its really address.

Here is the layout/my understanding code:

//Basicly Dont Touch (valueDT) is the default passcode we dont touch 
//and Touch (valueT) is the passcode we update / touch
//If changepasscode is enabled than update valueT with the new password
//------------------------------------------------------------------------
//The main issue is that the passcode max character limit is 10 digits and
//the arduino can only allow values up to 255

#include <EEPROM.h>

int DT_DEFAULT_PASSCODE = 0; //address 1 DontTouch_DEFAULT_PASSCODE
int DEFAULT_PASSCODE = 1; //address 2 Updated DEFAULT_PASSCODE
int valueDT;//DontTouch default passcode
int valueT;//Touch default passcode
int changePasscode = 1;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  EEPROM.write(DT_DEFAULT_PASSCODE, 245); // writing address 1 DontTouch_DEFAULT_PASSCODE
  EEPROM.write(DEFAULT_PASSCODE, 123); // writing at address DEFAULT_PASSCODE, 123

  valueDT = EEPROM.read(DT_DEFAULT_PASSCODE); //reading adress
  valueT = EEPROM.read(DEFAULT_PASSCODE); //reading adress

 if(changePasscode == 1){ //if I run change passcode
EEPROM.update(valueT, 456); //updating address to 150
changePasscode = 0;
 }
  delay(500);
  Serial.println(valueT);//printing the new passcode

}

You would do well to review the documentation for the eeprom library and consider using .put() and .get().

https://docs.arduino.cc/learn/built-in-libraries/eeprom

I'm not certain if you are trying to store any of the String objects in eeprom but you can not do that. You can only store the underlying character arrays, or else the numerical values as integers.

tring DEFAULT_PASSCODE = "1501";
String passcode = "";
String confirmPasscode = "";  // Variable to store the confirmed passcode
String Newpasscode = "";

you can certainly store multiple byte values in EEPROM at specific addresses, including strings. if the max length is know, the addresses would start at integer multiples of that length and unused value set to zero

i prefer to store value in EEPROM using type-length-values, (TLV) which allow the eeprom to be searched for a specific ID (type) and skip over entries using the length field.

here's code i used to write strings after the last TLV identified with a type value of 0xFF

void
eepromWrite (
    byte        type,
    const char *text )
{
    printf ("%s: %d %s\n", __func__, type, text);

    int addr = eepromAddr (ID_END);
    if (ID_NOT_FOUND == addr)  {
        printf (" %s: not found - eeprom full\n", __func__);
        return;
    }

    printf (" %s: addr 0x%02x\n", __func__, addr);

    EEPROM.write (addr++, type);

    byte len = strlen (text) + 1;
    EEPROM.write (addr++, len);

    for (unsigned n = 0; n < len; n++)
        EEPROM.write (addr++, text [n]);

    EEPROM.write (addr++, ID_END);
    EEPROM.commit ();
}
int
eepromAddr (
    byte   type)
{
    for (int addr = 0; addr < EEPROM_SIZE; )  {
        byte id = EEPROM.read (addr);
 //     printf (" %s: 0x%02x\n", __func__, id);

        if (id == ID_END || id == type)
            return addr;

        addr += EEPROM.read (++addr)+1;
    }
    return ID_NOT_FOUND;
}

think about it

So how can I store my password into the eeprom if it cant be a string?

Sorry, I am beyond lost here. I am just a noob and I have no Idea how to implement this into my code. Thanks for the reply!

Is the password the only thing you want to store?
Do you have just one password?

Yes the password is the only thing I want to store but the password will change over time so no it wont be just one passcode.

which arduino are you using?

I am currently working on a Arduino Uno and when I am finished with this whole eeprom stuff I will upload the same code to my Arduino Pro Mini.

untested.
check on your own.
hint: in setup there is a one time line to write a password in the EEPROM to address 100.
upload it once.
then comment that line and upload it again.

I was not sure where to put the put (better way of write), i did it down in line 162.

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <EEPROM.h>

int currentRow = 1;  // Start with the second row
const int LED = 2;
const int rs = A0, en = A1, d4 = A2, d5 = A3, d6 = A4, d7 = A5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

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] = { 8, 7, 6, 5 };
byte colPins[COLS] = { 12, 11, 10, 9 };

Keypad keypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

String DEFAULT_PASSCODE = "1501";  // will be overwritten in setup
String passcode = "";
String confirmPasscode = "";  // Variable to store the confirmed passcode
String Newpasscode = "";

const uint16_t addrPasscode = 100;


enum State {
  ENTER_PASSCODE,
  PRESS_A_TO_START,
  PASSCODE_CHANGE,
  ENTER_NEW_PASSCODE,
  CONFIRM_NEW_PASSCODE
};

State currentState = ENTER_PASSCODE;
bool passcodeChangeRequested = false;
int passcodeLength = 0;  // Variable to keep track of the number of characters entered during passcode reset

void setup() {
  pinMode(LED, OUTPUT);

  // use this line to write once a known password into EEPROM
  // compile and upload the sketch. Then comment out the line and immidiately upload the sketch a second time!
  EEPROM.put(addrPasscode, DEFAULT_PASSCODE);
  //

  // read the passCode from the EEPROM - thats needed after each power cycle
  EEPROM.get(addrPasscode, DEFAULT_PASSCODE); 

  lcd.begin(16, 2);
  lcd.print("Enter Passcode:");
}

void loop() {
  char key = keypad.getKey();

  if (key != NO_KEY) {
    switch (currentState) {
      case ENTER_PASSCODE:
        handlePasscodeInput(key);
        break;

      case PRESS_A_TO_START:
        if (key == 'A') {
          lcd.clear();
          lcd.print("Press B to Stop");
          digitalWrite(LED, HIGH);  // Turn on the LED
        } else if (key == 'B') {
          currentState = ENTER_PASSCODE;
          lcd.clear();
          lcd.print("Enter Passcode:");
          passcode = "";
          digitalWrite(LED, LOW);  // Turn on the LED
        } else if (key == '*') {
          passcodeChangeRequested = true;
          currentState = ENTER_NEW_PASSCODE;
          lcd.clear();
          lcd.print("Enter New Pass:");
          Newpasscode = "";
        }
        break;

      case ENTER_NEW_PASSCODE:
        handleNewPasscodeInput(key);  // Call handleNewPasscodeInput function
        if (key == '#') {
          currentState = CONFIRM_NEW_PASSCODE;
          lcd.clear();
          lcd.print("Confirm Pass:");
        } else if (key == 'B') {
          currentState = ENTER_PASSCODE;
          passcode = "";
          passcodeChangeRequested = false;
          passcodeLength = 0;  // Reset the passcode length
          lcd.clear();
          lcd.print("Enter Passcode:");
        }
        break;

      case CONFIRM_NEW_PASSCODE:
        handleConfirmPasscodeInput(key);            // Call handleConfirmPasscodeInput function
        break;
    }
  }
}

void handlePasscodeInput(char key) {
  if (key != NO_KEY) {
    if (passcode.length() < DEFAULT_PASSCODE.length()) {
      passcode += key;
      lcd.setCursor(passcode.length() - 1, 1);
      lcd.print("*");  // Display an asterisk for each character entered
    }

    if (passcode.length() == DEFAULT_PASSCODE.length()) {
      if (passcode.equals(DEFAULT_PASSCODE)) {
        currentState = PRESS_A_TO_START;
        lcd.clear();
        lcd.print("Press A to start");
      } else {
        lcd.clear();
        lcd.print("Incorrect Password");
        lcd.setCursor(0, 1);
        lcd.print("Please Try again");
        delay(2000);
        lcd.clear();
        lcd.print("Enter Passcode:");
        lcd.setCursor(0, 1);
        passcode = "";
      }
    }
  }
}

void handleNewPasscodeInput(char key) {
  if (key == '#') {  // Change state when '=' key is pressed
    currentState = CONFIRM_NEW_PASSCODE;
    lcd.clear();
    lcd.print("Confirm Pass:");
  } else if (key == 'B') {  // Reset passcode when 'B' key is pressed
    currentState = ENTER_PASSCODE;
    lcd.clear();
    lcd.print("Enter Passcode:");
    lcd.setCursor(0, 1);
    passcode = "";
  } else if (key != NO_KEY) {
    Newpasscode += key;
    lcd.setCursor(Newpasscode.length() - 1, 1);
    lcd.print("*");
  }
}

void handleConfirmPasscodeInput(char key) {
  if (key == '#') {  // Change state when '=' key is pressed
    if (Newpasscode == confirmPasscode) {  // Check if the passcodes match
      DEFAULT_PASSCODE = confirmPasscode;  // Update the default passcode


      // persist to EEPROM
      EEPROM.put(addrPasscode, DEFAULT_PASSCODE);


      
      currentState = ENTER_PASSCODE;
      lcd.clear();
      lcd.print("Passcode set");
      delay(2000);
      lcd.clear();
      lcd.print("Enter Passcode:");
      lcd.setCursor(0, 1);
      passcode = "";
      passcodeLength = 0;  // Reset the passcode length
    } else {
      lcd.clear();
      lcd.print("Passcodes don't");
      lcd.setCursor(0, 1);
      lcd.print("match. Try again.");
      delay(2000);
      lcd.clear();
      lcd.print("Enter New Pass:");
      lcd.setCursor(0, 1);
      Newpasscode = "";
      confirmPasscode = "";
      passcodeLength = 0;  // Reset the passcode length
      currentState = ENTER_NEW_PASSCODE;  // Return to the new passcode entry state
    }
  } else if (key == 'B') {  // Reset passcode when 'B' key is pressed
    currentState = ENTER_PASSCODE;
    lcd.clear();
    lcd.print("Enter Passcode:");
    lcd.setCursor(0, 1);
    passcode = "";
    passcodeLength = 0;  // Reset the passcode length
  } else if (key != NO_KEY) {
    confirmPasscode += key;
    lcd.setCursor(confirmPasscode.length() - 1, 1);
    lcd.print("*");  // Display the entered digit
    passcodeLength++;  // Increment the passcode length
  }
}

I tested it and seems to me the eeprom isn't working. The whole code works, no errors or anything but when I set the passcode and un-plug and re-plug it back in it goes back to the default passcode not the new one I set it to.

In setup(), you are setting the EEPROM back to the default password.
This happens everytime you reset the Arduino.

You should either remove this line now, or better yet, change it, so that default password is only set if the EEPROM appears blank. This will require a new piece of code.

do you mean this line: EEPROM.put(addrPasscode, DEFAULT_PASSCODE); because he already told me to comment it as soon as I upload the code but lets say I dont and I set it to when the eeprom is blank

Would this work:

bool isEEPROMBlank() {
  for (int i = 0; i < EEPROM.length(); i++) {
    if (EEPROM.read(i) != 255) {  // Check if address is not blank (255 is the default erased value)
      return false;  // EEPROM is not blank
    }
  }
  return true;  // EEPROM is blank
}

in the void setup:

void setup() {

if (isEEPROMBlank()) {
    EEPROM.put(addrPasscode, DEFAULT_PASSCODE);
  }

  // ... Existing code ...
}

replace Setup with following:

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);

  Serial.print(F("0 DEFAULT_PASSCODE="));
  Serial.print(DEFAULT_PASSCODE);
  Serial.println("|");

  // use this line to write once a known password into EEPROM
  // compile and upload the sketch. Then comment out the line and immidiately upload the sketch a second time!
  //EEPROM.put(addrPasscode, DEFAULT_PASSCODE);
  //

  // read the passCode from the EEPROM - thats needed after each power cycle
  EEPROM.get(addrPasscode, DEFAULT_PASSCODE); 
  Serial.print(F("1 DEFAULT_PASSCODE="));
  Serial.print(DEFAULT_PASSCODE);
  Serial.println("|");

  lcd.begin(16, 2);
  lcd.print("Enter Passcode:");
}

and copy paste what serial is printing.

On startup:

0 DEFAULT_PASSCODE=1501|

1 DEFAULT_PASSCODE=1501|

It's in the EEPROM. Without any doubt.
it has the same length, there a no unwanted characters.
so whats next. Check if a new passcode gets written.
Where do you write a new passcode?

Where the new passcode is confirmed and written is at void handleConfirmPasscodeInput

Whats about somtehing like this?


#include <EEPROM.h>

struct Passcode {
  bool changeable;
  char code[11];
};

struct EepAddress {
  uint16_t base;
  uint16_t offset;
};

Passcode valueDT {false,"0000000000"};
Passcode valueT  {true,"1234567890"};

EepAddress eep{5,sizeof(Passcode)};

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

  char check[4] {"SET"};
  EEPROM.get(0,check);
  if (strcmp("SET",check)) {      // If SET is NOT in EEPROM
    Serial.println("EEPROM Empty, set default value");
    EEPROM.put(0,"SET");
    EEPROM.put(eep.base, valueDT);
  }
  EEPROM.put(eep.base + eep.offset, valueT);

  EEPROM.get(eep.base, valueDT);
  EEPROM.get(eep.base + eep.offset, valueT);

  Serial.print(valueDT.code); Serial.print(" ");
  (valueDT.changeable) ? Serial.println("Value changeable") : Serial.println("Value NOT changeable");
  Serial.print(valueT.code); Serial.print(" ");
  (valueT.changeable) ? Serial.println("Value changeable") : Serial.println("NOT Value changeable");
}

void loop() {}

I mean that just looks hella complicated not to be rude or anything I am a noob

check the position where I have put the EEPROM.put.
Does it make sense for you?
Add a Serial print "passCode written" and check if it gets printed when you change and confirm the password