How to write and read 4 Digit Sensor vaule in EEPROM

Hello Friends,

I am new learner and not good in coding too.But aim is to learn .Basically my project is to measure temperature uptp 1200 DegC.
for that purpose I googled many examples, tried to modify according to my need using Max6675.

Code is working perfectly & displaying Temp on serial Monitor,even simulator is used to read Temp upto 1140 Deg C with slightly difference
+-6 DegC, for the moment accuracy is not so important.

The issue is which I have been facing from last 2 Weeks,eeprom store only value upto 250 DegC perfectly but beyond it doesnt store correctly.
In my case I have to store value upto 1200 DegC.

Could you please help me with code modification to store 4 Digit Value into eeprom?

Your help would be greatly appriciated.

Thanks,

Rezox

Look at the EEPROM library's put and get functions

Here is my code:

#include <EEPROM.h>
#include "max6675.h"
 
#define SAMPLE_TIME 2000  //The time between each EEPROM write function call in ms
 
int printPin = 2;     //the print button pin
int erasePin = 4;    //the erase button pin

int thermoDO = 5;
int thermoCS = 4;
int thermoCLK = 6;

MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
 
int address = 0;      //EEPROM address counter
int counter = 0;
 
unsigned long timer;
unsigned long int milli_time; 

void printTemp();
void clearEEPROM();
void writeTemp();
 
void setup(){
  Serial.begin(115200);     //start the serial connection as always

  pinMode(printPin, INPUT_PULLUP);
  pinMode(erasePin, INPUT_PULLUP);
  
  timer = millis();         //millis() returns the time since program start in ms
}
 
void loop(){
  if(millis()-timer > SAMPLE_TIME)  //check if it's time to do a temp sensor sample
  {
    writeTemp();
    timer = millis();
  }
 
  if(!digitalRead(printPin))  //check if print button is pressed
  {
    printTemp();
    delay(500);
  }
 
  if(!digitalRead(erasePin)) //check if erase button is pressed
  {
    clearEEPROM();
    delay(500);
  }
   
  delay(1);
}
 
void printTemp()
{
  for (int i = 0 ; i < EEPROM.length() ; i++) {
    byte value = EEPROM.read(i);                //read EEPROM data at address i
    if(value != 0)                              //skip "empty" addresses
    {
      sumTemp = sumTemp + thermocouple.readCelsius();
       
      Serial.println(sumTemp);
    }
  }
}
 
void clearEEPROM()
{
  for (int i = 0 ; i < EEPROM.length() ; i++) {
    if(EEPROM.read(i) != 0)                     //skip already "empty" addresses
    {
      EEPROM.write(i, 0);                       //write 0 to address i
    }
  }
  Serial.println("EEPROM erased");
  address = 0;                                  //reset address counter
}
 
void writeTemp()
{
  
       milli_time = millis();

    sumTemp = sumTemp + thermocouple.readCelsius();            // basic readout test, just print the current temp
    counter++;

    if (counter == 10 ) {           
      counter = 0;
      delay(500);
      
  EEPROM.write(address, (sumTemp / 10));         //write value to current address counter address
 
  Serial.print("Sensor value stored at address ");
  Serial.println(address);
   
  
  if(address == EEPROM.length())  //check if address counter has reached the end of EEPROM
  {
    address = 0;              //if yes: reset address counter
    sumTemp = 0;
   }
  }
 }

Thanks,Please have a look on codes .Kindly help me to modify this code...

Please take a look at the reference page for the EEPROM library, and the put and get functions

1 Like

You write only one byte to the EEPROM.

1 Like

Please help what all changes to be done in code...

1 Like

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