I have 7 float variables.

float temperature, differential, calibration,hta,lta,hha,lha;

I want to store them all on the EEPROM memory, how do I calculate the addresses given that there type is float.



create a struct and store the struct

#include <EEPROM.h>

const int DATA_ADDR = 0;

struct MyData {
  float temperature, differential, calibration,hta,lta,hha,lha;

MyData data;

void setup() {
  data.temperature = 1.2;

  EEPROM.put(DATA_ADDR, data);

  EEPROM.get(DATA_ADDR, data);

void loop() {

| improve this answer | |

With the sizeof function:

int nrOfBytesOfTemperature = sizeof(temperature);

You can also use directly a type:

int nrOfBytesOfFloat = sizeof(float);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.