Problems with my temp (DS18B20) + Analog Read (potentiometer) and LCD project

Hi all.

Here is a thing that has been bugging me for the last few days.
What I am making is an arduino NANO/ATMega328 project that I have put on an experiment board.
Project is a "shake-meter" for beer that works like this.

  1. Put beer in a small vessel/can (like ml) - fill it gently to avoid foaming.
  2. When full close all valves and shake it until pressure on manometer doesn't increase anymore.
  3. on an analogue manometer read the pressure (my meter is in bar).
  4. use a potentiometer to let the arduino know the pressure that you read on the manometer (0.2 bar to 2.0 bar) the LCD shows the value that you enter.
  5. I convert bar to PSI and a DS18B20 sensor that is in a probe inside the can gets the temp in celsius that is converted to fahrenheit Depending on the temp in F (30-50) I know what array (Temp30....Temp50 arrays) and the pressure in PSI (-1) i use as the Index to get the VolCO2% values that I have collected from a chart. http://www.backfire.se/images/stories/tutorial/kolsyresttning.png
    (So 34F and 5 PSI would get the record in Temp34[4] = "2.06")

On the LCD I display the data that I am after.

Now to the problem.
When I only used the temp 30-40F it worked fine, but then I decided to change to 30-50F. After that I got weird chars on the LCD and on Serial.print.
So I have tried to clean the code and simplify it. I even changed the float fahrenheit to an int instead (since I only am after F in integer).

In the code section:

// 
// DEBUG 
//fahrenheit = fahrenheit - 40;
fahrenheit = 44.2; // as fahrenheit now is an integer this means it will be 44
// END DEBUG

Then it works and presents correctly on the LCD display
and the function:

void presentonLCD (float tempCin, float tempFin, float prePSIin, float preBARin, float coLevel)

writes the following on the serial print (Note that I in debug purposes have provided the 44 F manually)

ROM = 28 D2 C2 CD 4 0 0 2F
Chip = DS18B20
Data = 1 6F 1 4B 46 7F FF 1 10 67 CRC=67
Temperature = 22.94 Celsius, 73 Fahrenheit

44.00F
22.94C
25.91PSI
1.78bar
3.41CO2%
No more addresses.

If I comment out the following ie. tries to get fahrenheit from the DS18B20 it will not work and I will not get anything on display or serial print.

// 
// DEBUG 
//fahrenheit = fahrenheit - 40;
//fahrenheit = 44.2; // as fahrenheit now is an integer this means it will be 44
// END DEBUG

Will post the full code in the next post

I have attached the full code.

newCO2.ino (12.5 KB)

21 arrays, with 30 elements per array is 630 elements. Each element is 4 bytes, for a total of 2,520 bytes, of the 2000 that you have (assuming a 328-based machine).

I'm sure PaulS has nailed it.

You could use PROGMEM to avoid those large lookup tables taking up RAM, or try to replace them with a formula to calculate the resulting values. Excel is a good way to fit curves to data sets.

Thank you for your quick replies.

Will try to see how I could calculate it (using some form of Henry's law) instead of doing lookups in the matrix table.
Also need to do some studying regarding PROGMEM as suggested.