This is my first post here and I'm hoping there are some arduino hobbyists here that can help me out.

Does anyone here know how to save a float variable directly to the eeprom? If so could you please have a look at the program I wrote here and hopefully you can show me how I can modify my code here to work with the other 2 variables I'm saving to the eeprom. The program I wrote displays a voltmeter to the LCD. It has an adjustable alarm set point as to when to sound an alarm when the voltage drops below a user set alarm set point.

I want to be able to declare the alarm set point as a float variable and save it directly to the eeprom. I can't seem to find any programs that I could use as an example to try and figure out how to do that. Even though I wrote this program here I have very little experience or understanding of what’s involved in setting up a float var to be saved. I've been reading a lot of posts on the official arduino forum but there aren't too many posts there that are actually resolved and even when they are resolved the complete working code is very seldom posted. I get most of my coding experience by taking apart other peoples code in a working program to combine with my programs. That’s the nice thing about open source is that a lot of it is out there but unfortunately I can’t seem to find any working programs that are saving a float var to the eeprom at least none that I can understand what's going on.

I did manage to get my program working to save my Volt_Alarm_Set_Point by declaring it as an int var and then comparing it to my Volt_Set_Point (declared as a float var) to 165 if statements to save the right Volt_Alarm_Set_Point value. And it works perfectly but it uses up 4956 bytes of program space. Way too much...

That's ok if I'm using an Arduino Mega but I'd like to be able to have some of my programs run on an Arduino Nano which could cause problems with some bigger programs. If anyone here could show me how to do this or has a link to a program that I can use as a guide it would be greatly appreciated and I would be in your dept. Here is my code below.

And as far as saving your float, if the resolution of one decimal point is sufficient, multiply each reading by ten and store the integer.
As far as I know, you cannot save an actual float value to the EEPROM.

Thanks for getting me to looking on the right track. I tried using your equation "Volt_Set_Point = Volt_Alarm_Set_Point / 10;" but I couldn't seem to get it to work in my program. Your equation definitely makes sense mathematically when you look at all the if statements but I just couldn't get it to display properly to the float variable and as a consequence the alarm wouldn't sound when using "if (vin <= Volt_Set_Point){digitalWrite(Relay_3, Is_Turned_On);}". I did something wrong?

Eventually I did manage to get it working by using "Volt_Set_Point = Volt_Alarm_Set_Point * 0.1;" and it works good to displaying the Volt_Set_Point float variable while incrementing and decrementing the Volt_Alarm_Set_Point integer variable and it also does the comparison well to sound the alarm. I'm posting my new code below for you (and others) to see and maybe if you get the time possibly you could suggest how I could get your equation to work with-in the confines of the program code I wrote.

Thank you also jremington but I have no idea on how to use that library that you suggested unless I could see it being used in a relatively easy program that is within my comprehension to understand (a practicable example). As I stated in my original post here: I get most of my coding experience by taking apart other peoples code in a working program to combine with my programs.

Thanks
jessey

As far as what I've read and understand about arduino is not only for professionals and students but also for hobbyists who don't have too much comprehension of the inner workings of arduino of which I am definitely one. So please excuse me if I'm ignorant of arduino as I am looking to understand.

I suggested that division without examining the details.
Your variable declaration of Volt_Alarm_Set_Point as an integer could be changed to a float.
The C programming language takes integer math literally in this case and returns an integer since both the operands are integer.
Volt_Alarm_Set_Point / 10 returns an integer (they are both integers).
Multiplying by 0.1 (a literal float data type) will produce a float result.

Thanks for the encouragement jremington. I managed to get it working and it seems to be functioning good. Unless you can see any gotchas.
So this is a good thread for anyone that is googling how to save a float variable and is easy to follow. I posted the new revised code below...

Thanks
jessey

As far as what I've read and understand about arduino is it's not only for professionals and students but
also for hobbyists who don't have too much comprehension of the inner workings of arduino of which I
am definitely one. So please excuse me if I'm ignorant of arduino as I am looking to understand.

First off - Happy New Year. And secondly if you have the time I'd really like to know if you see any gotchas in this code I wrote (the code in my last post above) to save a float variable to the eeprom? Have I missed anything? I would definitely value any comments you may have, negative or otherwise.

Thanks
jessey

As far as what I've read and understand about arduino is it's not only for professionals and students but
also for hobbyists who don't have any or not too much comprehension of the inner workings of arduino of which I
am definitely one. So please excuse me if I'm ignorant of arduino as I'm looking to understand.

I'm still looking for assurances that my use of read and wright to save my float variable is done right or is appropriate. If anyone that is in the know is reading this and can comment then I would certainly appreciate it.

Thanks
jessey

As far as what I've read and understand about arduino is it's not only for professionals and students but
also for hobbyists who don't have any or not too much comprehension of the inner workings of arduino of which I
am definitely one. So please excuse me if I'm ignorant of arduino as I'm looking to understand.

Your program is too long and complicated for me to easily see whether you break that rule.

If you had even taken just a couple of minutes of your time to look at my code instead of just throwing your arms in the air and rushing to that judgment you would have clearly seen that my code is NOT writing to the eeprom every pass through loop(). The integer variables a & b are only saved once upon releasing the push buttons in the void loop(). And the float variable is also only saved once with a button press.

I would have expected better from someone with over 2000 posts in this forum.

Possibly when I get the time sometime I'll write a simpler program as an example that won't require more than a flighting view to realistically comment on.

Thanks
jessey

As far as what I've read and understand about arduino is it's not only for professionals and students but
also for hobbyists who don't have any or not too much comprehension of the inner workings of arduino of which I
am definitely one. So please excuse me if I'm ignorant of arduino as I'm looking to understand.