# eeprom counter

hi , i want to make relay operated by counter

i have to save some numbers on external eeprom.( like 16005, 160050,17263) and if counter increase to any numbers of eeprom matched relay on for 1 secons. how can i compare multiple numbers.

chetan chetan98250@gmail.com

The integers you want to store in eeprom need to be broken down into bytes to store them then when called from eeprom, recombined to make integers from them. Unless you are using a Due then integers are 4 bytes.
You can avoid the confusion and make it near seamless for the Due included by int16_t which makes your integers unsigned 16 bit integers.range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1) or us uint16_t which give you a range of 0 to 65,535 (2^16) - 1).

My code, alc is a 48 ellement array of 16 bit integers I am writing to EEprom for a preloader for an application
```
*int16_t alc[48];
int16_t alcck[48];
//…  more code

for (int i = 0; i < 48; i++)
{
Serial.print(" **  Channel # “);
Serial.print(i);
Serial.print(”\t");
byte balc1 = (alc[i] & 0xFF);
byte balc2 = ((alc[i] >> 8) & 0xFF);

//Write the 2 bytes into the eeprom memory.
Serial.print(alc[i]);
Serial.print(i * 8);
Serial.print(”\t");
EEPROM.write(i * 8, balc2);
EEPROM.write(i * 8 + 1, balc1);
////…  more code
}*
`* *Then to read the code from EEprom I do the following to check that the numbers were written.* *`
*  for (int i = 0; i < 48; i++)
{
Serial.print("\n **  Channel # “);
Serial.print(i);
Serial.print(”\t");
//Read the 2 bytes from the eeprom memory low calibration data.
int16_t i16alc1 = EEPROM.read((i * 8));
int16_t i16alc2 = EEPROM.read((i * 8) + 1);
alcck[i] = ((i16alc2<<0)&0xFF)+((i16alc1<<8)&0xFFFF);
if (alcck[i] == alc[i])
{
Serial.print(" OK  “);
}
else
{
chkflag = 1;
}
… more code
}*
```
I don’t know if I’m doing it right but I get expected results. This instance is running on a Nano.
My *8 or times 8 for my address is because I am writing and reading 4 16 byte integers on the same loop. It display the address and (i * 8 + 2) for memory location of my next array element and (i * 8 +4) for the next and (i * 8 +6) for the last. I running all this in the setup so it doesn’t loop. You have about 10,000 Writes to EEprom before it’s toast.

``````if (x >=xs || y >=ys || z >= xs 0) {
// ...
}
``````

Nasa: The integers you want to store in eeprom need to be broken down into bytes to store them then when called from eeprom, recombined to make integers from them.

Incorrect, using the EEPROM.put() and EEPROM.get() functions(available in the EEPROM library included with Arduino IDE 1.6.2 and later) allows any type or object to be written to and read from EEPROM.

Nasa: You have about 10,000 Writes to EEprom before it's toast.

No, it's 100,000. See the first page of the ATmega328 datasheet

Edit: didn't notice OP said external EEPROM, so that would depend on the chip used.

need more details

chetan98250: need more details

You have to give a lot more details.

An understandable detailed description of what you want to do and what does not work as expected, sourcecode (in code tags please) , schematics (if any), ...

Wish-wash like "save some numbers on external eeprom" is not constructive.