# writing difrent values to eeprom

**URL:** <https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147>\
**Category:** Programming\
**Created:** [August 7, 2020, 1:27pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147 "2020-08-07T13:27:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerdal](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerdal](https://forum.arduino.cc/u/gerdal)\
**Post date:** [August 7, 2020, 1:27pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/1 "2020-08-07T13:27:59Z")

</div>

Hello, I am struggled with eeprom can someone help me ,

I have 4 difrent int in my code that I calculate in loop.

Value= 154  
valuea =785  
valueb = 5  
valuec = 200  
valued= 650

I need to write this values to eeprom

I looked in the forum they are eeprom write anything or eeprom get or eepromput but I couldt find how to use it..

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [August 7, 2020, 1:40pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/2 "2020-08-07T13:40:57Z")

</div>

Did you look [Here](https://www.arduino.cc/en/Reference/EEPROM)?

---

<div class="post-metadata">

**Author:** ![gerdal](https://avatars.discourse-cdn.com/v4/letter/g/85e7bf/32.png) [@gerdal](https://forum.arduino.cc/u/gerdal)\
**Post date:** [August 7, 2020, 1:49pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/3 "2020-08-07T13:49:26Z")

</div>

yes but I cant figured .

I wat to to write all these in eeprom and when I need I want to call just the value of the int I chose

when I tried to use EEprom.write when I Make EEpprom.Read(valueb) the values comes difrent

when try to write I use eeprom.write(valuea,785)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [August 7, 2020, 2:01pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/4 "2020-08-07T14:01:14Z")

</div>

The quick way

```cpp
int address = 0;
EEPROM.put(address, valueA);
Serial.print("valueA stored at "); Serial.println(address);
address += sizeof(valueA);
EEPROM.put(address, valueB);
Serial.print("valueB stored at "); Serial.println(address);
address += sizeof(valueB);
...
...

```

To read it back, you need to know the address where a variable was saved; e.g. valueB was saved at address 2.

```cpp
EEPROM.get(2, newVarB);
Serial.print("newVarB = "); Serial.println(newVarB);

```

You can also use

```cpp
const int addressA = 0;
const int addressB = addressA + sizeof(int);
...
...

```

And write with

```cpp
EEPROM.put(addressA, valueA);
Serial.print("valueA stored at "); Serial.println(addressA);
EEPROM.put(addressB, valueB);
Serial.print("valueB stored at "); Serial.println(addressB);
...
...

```

And to read it back

```cpp
EEPROM.get(addressB, newVarB);
Serial.print("newVarB = "); Serial.println(newVarB);

```

---

<div class="post-metadata">

**Author:** ![pcbbc](https://avatars.discourse-cdn.com/v4/letter/p/54ee81/32.png) [@pcbbc](https://forum.arduino.cc/u/pcbbc)\
**Post date:** [August 7, 2020, 2:01pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/5 "2020-08-07T14:01:44Z")

</div>

> gerdal:  
> yes but I cant figured .
> 
> I wat to to write all these in eeprom and when I need I want to call just the value of the int I chose
> 
> when I tried to use EEprom.write when I Make EEpprom.Read(valueb) the values comes difrent
> 
> when try to write I use eeprom.write(valuea,785)

Try put and get.  
Read and write on read and write single bytes (0...255).

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [August 8, 2020, 3:13pm UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/6 "2020-08-08T15:13:22Z")

</div>

```cpp
#include <EEPROM.h>

int Value = 154;
int valuea = 785;
int valueb = 5;
int valuec = 200;
int valued = 650;

const int addr_Value = 0;
const int addr_valuea = addr_Value + sizeof Value;
const int addr_valueb = addr_valuea + sizeof valuea;
const int addr_valuec = addr_valueb + sizeof valueb;
const int addr_valued = addr_valuec + sizeof valuec;

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

  // Only needed once
  EEPROM.put(addr_Value, Value);
  EEPROM.put(addr_valuea, valuea);
  EEPROM.put(addr_valueb, valueb);
  EEPROM.put(addr_valuec, valuec);
  EEPROM.put(addr_valued, valued);

  int V, va, vb, vc, vd;
  EEPROM.get(addr_Value, V);
  EEPROM.get(addr_valuea, va);
  EEPROM.get(addr_valueb, vb);
  EEPROM.get(addr_valuec, vc);
  EEPROM.get(addr_valued, vd);

  Serial.println(V);
  Serial.println(va);
  Serial.println(vb);
  Serial.println(vc);
  Serial.println(vd);
}

void loop() {}

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 12:41am UTC](https://forum.arduino.cc/t/writing-difrent-values-to-eeprom/669147/7 "2021-05-06T00:41:32Z")

</div>


