how to save float value EEPROM

Hi

This is Eabul.

i want to save data to eeprom from press button .

when TemperatureUp button press. increase float data like as 0.01> 0.02--------30.10> 30.61
and this value save to eeprom.

and when TemperatureDown button press . decrease float data like as 30.60>30.59-----29.10
and update minus value eeprom

and increase and decrease valud view lcd display .

but when press button save int number not float. and show me lcd display int value.
please help how to write and read float value from eeprom. press button.

hear my code.

//For Display
#include <LiquidCrystal595.h> // 3wire display
LiquidCrystal595 lcd(4, 3, 2); // DS, ST_CP, SH_CP

//For time
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 RTC;

//for humidity
#include “DHT.h”
DHT dht;

//for stor tempereratur and humidity
#include <EEPROM.h>
int SetHumidity;
int HumidityUp = 10; // switch up is at pin 10
int HumidityDown = 11; // switch down is at pin 11

float fix = 0.01;

float settemp; // make a variable called temp
float TemperatureUp = 12; // switch up is at pin 12
float TemperatureDown = 13; // switch down is at pin 13

//result view
int led = 0; // led is at pin 0

void setup() {
//For timer
Wire.begin();
RTC.begin();

//For welcome screen
lcd.begin(16,4);
lcd.setCursor(0,0);
lcd.print(“Welcome Elab”);
delay(2000);
lcd.clear();

//for dht-11 pin setup
dht.setup(A1); // data pin 2

}

void loop() {

//For tempererature up / down
float temp[3];
getTemp(temp);
float tempererature = temp[1];

settemp = EEPROM.read(1); // read the settemp on the eeprom
if(digitalRead(TemperatureUp) == 1 )
{
settemp+=fix;

settemp++;
EEPROM.write (1, settemp); /* write the most recent settemp in eeprom data stoage*/

}
else {}

if(digitalRead (TemperatureDown) == 1)
{
settemp -= fix;

settemp–;
EEPROM.write (1, settemp); /* write the most recent settemp in eeprom data stoage*/

}

if (tempererature >= settemp) { digitalWrite (led, 1); }
else { digitalWrite (led, 0);}
//else { };

lcd.setCursor(0,0);
lcd.print(“T:”);
lcd.print(tempererature);
lcd.setCursor(8,0);
lcd.print (“ST”);
lcd.print (settemp);

lcd.print((char)223);

//End tempererature controll

//For humidity up / down

SetHumidity = EEPROM.read(2);
int humidity = dht.getHumidity();
if(digitalRead(HumidityUp ) == 0 )
{SetHumidity++ ; } // add one to the settemp
else {}

if(digitalRead (HumidityDown) == 0)
{ SetHumidity–; } // Reduse settemp
else { };

lcd.setCursor (0, 1);
lcd.print (“CH:”);
lcd.print (humidity);
lcd.print ("%");

lcd.setCursor (8, 1);
lcd.print (“SH:”);
lcd.print (SetHumidity);
lcd.print ("%");
delay (1); // wait 100 milliseconds
EEPROM.write (2, SetHumidity); /* write the most recent settemp in eeprom data stoage*/
//End tempererature controll controll
}

//analog temperature
void getTemp(float * t)
{
const int analogPin = 0; // replace 0 with analog pin
const float invBeta = 1.00 / 3380.00; // replace “Beta” with beta of thermistor

const float adcMax = 1023.00;
const float invT0 = 1.00 / 298.15; // room temp in Kelvin

int adcVal, i, numSamples = 5;
float K, C, F;

adcVal = 0;
for (i = 0; i < numSamples; i++)
{
adcVal = adcVal + analogRead(analogPin);
delay(100);
}
adcVal = adcVal/5;
K = 1.00 / (invT0 + invBeta*(log ( adcMax / (float) adcVal - 1.00)));
C = K - 273.15; // convert to Celsius
F = ((9.0*C)/5.00) + 32.00; // convert to Fahrenheit
t[0] = K; t[1] = C; t[2] = F;
return;
}

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:

[code]

[color=blue]// your code is here[/color]

[/code]

Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you’re using the Arduino Web Editor you will not have access to this useful tool but it’s still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we’re trying to read your code. Do not post double spaced code.

It’s quite easy to write float values to EEPROM using EEPROM.put(). See:
https://www.arduino.cc/en/Reference/EEPROMPut
Just remember that a float will use up 4 bytes of EEPROM, starting from the address you pass to EEPROM.put().

Hi

This is Eabul.

i want to save data to eeprom from press button . 

when TemperatureUp  button press. increase float data like as 0.01> 0.02--------30.10> 30.61
and this value save to eeprom.

and when TemperatureDown button press . decrease float data like as 30.60>30.59-----29.10
and update minus value eeprom

and increase and decrease valud view lcd display .

but when press button save int number not float. and show me lcd display int value.
please help how to write and read float value from eeprom. press button. 


hear my code.


//For Display
  #include <LiquidCrystal595.h>    // 3wire display
  LiquidCrystal595 lcd(4, 3, 2);   // DS, ST_CP, SH_CP

//For time
  #include <Wire.h>
  #include <RTClib.h>
  RTC_DS1307 RTC;

//for humidity
  #include "DHT.h"
  DHT dht;


//for stor tempereratur and humidity 
  #include <EEPROM.h>
  int SetHumidity;
  int HumidityUp = 10;  // switch up is at pin 10
  int HumidityDown = 11;   // switch down is at pin 11


   float fix = 0.01;
   
   float settemp; // make a variable called temp
   float TemperatureUp = 12;  // switch up is at pin 12
   float TemperatureDown = 13;   // switch down is at pin 13

//result view 
  int led = 0; // led is at pin 0




void setup() {
  //For timer
    Wire.begin();
    RTC.begin();

  //For welcome screen
    lcd.begin(16,4);   
    lcd.setCursor(0,0);                                                    
    lcd.print("Welcome Elab");
    delay(2000);
    lcd.clear();

  //for dht-11 pin setup 
    dht.setup(A1); // data pin 2

  }

void loop() {


//For tempererature up / down
  float temp[3];
  getTemp(temp);
  float tempererature = temp[1];

   settemp = EEPROM.read(1); // read the settemp on the eeprom
  if(digitalRead(TemperatureUp) == 1 )
  {
    settemp+=fix;
    
   settemp++;
    EEPROM.write (1, settemp); /* write the most recent settemp in eeprom data stoage*/
   
      } 
  else {} 

  if(digitalRead (TemperatureDown) == 1)
  {
    settemp -= fix;
    
    settemp--;
     EEPROM.write (1, settemp); /* write the most recent settemp in eeprom data stoage*/
   
} 


  if (tempererature >= settemp) { digitalWrite (led, 1); }
  else { digitalWrite (led, 0);}
  //else {  };

  lcd.setCursor(0,0);
  lcd.print("T:");
  lcd.print(tempererature);
  lcd.setCursor(8,0);
  lcd.print ("ST");
  lcd.print (settemp);

  lcd.print((char)223);
  
  
  //End   tempererature controll


  
//For humidity up / down

  SetHumidity = EEPROM.read(2);
  int humidity = dht.getHumidity();
  if(digitalRead(HumidityUp ) == 0 )
  {SetHumidity++ ;  } // add one to the settemp
  else {} 

  if(digitalRead (HumidityDown) == 0)
  { SetHumidity--; } // Reduse settemp
  else {  };


  lcd.setCursor (0, 1); 
  lcd.print ("CH:");  
  lcd.print (humidity);
  lcd.print ("%");  

  lcd.setCursor (8, 1); 
  lcd.print ("SH:");  
  lcd.print (SetHumidity);
  lcd.print ("%");  
  delay (1); // wait 100 milliseconds
   EEPROM.write (2, SetHumidity); /* write the most recent settemp in eeprom data stoage*/ 
 //End   tempererature controll controll
} 




//analog temperature
void getTemp(float * t)
{
  const int analogPin = 0; // replace 0 with analog pin
  const float invBeta = 1.00 / 3380.00;   // replace "Beta" with beta of thermistor

  const  float adcMax = 1023.00;
  const float invT0 = 1.00 / 298.15;   // room temp in Kelvin

  int adcVal, i, numSamples = 5;
  float  K, C, F;

  adcVal = 0;
  for (i = 0; i < numSamples; i++)
   {
     adcVal = adcVal + analogRead(analogPin);
     delay(100);
   }
  adcVal = adcVal/5;
  K = 1.00 / (invT0 + invBeta*(log ( adcMax / (float) adcVal - 1.00)));
  C = K - 273.15;                      // convert to Celsius
  F = ((9.0*C)/5.00) + 32.00;   // convert to Fahrenheit
  t[0] = K; t[1] = C; t[2] = F;
  return;
}

when i use EEPROM.update() EEPROM.get()

dosen't work button press

Post your updated code, but this time only put the code in code tags, not your whole post. Also, you forgot to do the auto format and remove the pointless blank lines.

Thanks you pert for your help. finally i got it. it work fine for me