# How to mange EEPROM storage

**URL:** <https://community.particle.io/t/how-to-mange-eeprom-storage/62771>\
**Category:** Firmware\
**Created:** [June 19, 2022, 9:37am UTC](https://community.particle.io/t/how-to-mange-eeprom-storage/62771 "2022-06-19T09:37:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![coconut](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@coconut](https://community.particle.io/u/coconut)\
**Post date:** [June 19, 2022, 9:37am UTC](https://community.particle.io/t/how-to-mange-eeprom-storage/62771/1 "2022-06-19T09:37:45Z")

</div>

Hello  
Sorry for the basic question but I was unable to figure it out myself.  
I am trying to figure out how to use EEPROM in case of power outage.  
I manged to successfully use EEPROM.get and EEPROM.put (using [docs](https://docs.particle.io/reference/device-os/api/eeprom/eeprom/)

```cpp
int temp;
int s1max1;
int s1min1;

void setup() {
  Particle.function("s1",s1 ); 
  Particle.variable("s1max1",s1max1); 
  Particle.variable("s1min1",s1min1); 
  pinMode(D0, OUTPUT);
  pinMode(D0, OUTPUT);
  EEPROM.get(0, s1max1);
  EEPROM.get(5, s1min1);
  Serial.begin(9600);
}

void loop() {  
  //temp=airSensor.getTemperature();
  size_t length = EEPROM.length();
  Serial.print("The size of byte is "); Serial.print((length)); 
  Serial.println(".");
  delay(2000);

  if(temp <= s1max1){
   digitalWrite(D0, HIGH); 
  }

  if(temp <= s1min1){
    digitalWrite(D0, LOW); 
    delay(2000);
  }
}

int s1 (String value) {
  s1min1 = value.substring(0,2).toFloat();
  s1max1= value.substring(2,4).toFloat();
  EEPROM.put(0, s1max1);
  EEPROM.put(5, s1min1);
  
  return 0; 
}

```

Although it works OK I did not understand how addresses work and how much storage each variable takes.  
In this code attached I used address 0 for the first variable and address 5 for the second and printing the size of the eeprom to see if it changes.

My question is : How much of storage each INT with 1 digit (for example 6), with 2 digit (for example 26)/ 3 digit etc…  
I tried reading [this](https://docs.particle.io/reference/device-os/libraries/e/EEPROM-Storage/) but I did not understand it.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [June 19, 2022, 3:26pm UTC](https://community.particle.io/t/how-to-mange-eeprom-storage/62771/2 "2022-06-19T15:26:40Z")

</div>

> [@coconut](#):
>
> Although it works OK I did not understand how addresses work and how much storage each variable takes.

That depends on the datatypes you use, but `sizeof(yourVariable)` will give you the byte count your variable occupies in memory.  
For `int` (better to use `int32_t` for clarity) it'd be _four_ bytes.

An `int32_t` _ **always** _ occupies 32 bits, no matter which number it holds (providing within its range -2,147,483,648 .. +2,147,483,647).  
If you know your respective data will never exceed a certain range you can always opt for shorter datatypes (e.g. `int8_t` for -128..+127 - which will require _one_ byte in memory).

---

<div class="post-metadata">

**Author:** ![coconut](https://avatars.discourse-cdn.com/v4/letter/c/f9ae1b/32.png) [@coconut](https://community.particle.io/u/coconut)\
**Post date:** [June 20, 2022, 7:44am UTC](https://community.particle.io/t/how-to-mange-eeprom-storage/62771/3 "2022-06-20T07:44:11Z")

</div>

Thank you [ScruffR](https://community.particle.io/u/ScruffR)  
I think I understand now.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/6/4/64635adccc35238caa19e9b553ec3e98b163d026.png) [@system](https://community.particle.io/u/system)\
**Post date:** [July 20, 2022, 5:44pm UTC](https://community.particle.io/t/how-to-mange-eeprom-storage/62771/4 "2022-07-20T17:44:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
