I have made a simple thermostat for controlling a 12V heater. The temperature range can be from 0 F to around 190 F. For some reason when the displayed temperature on my LCD goes from 99 to 100 everything is fine but if it goes back down from 100 to 99 the value ends out being 990. I think this is something to do with the rounding in my Thermistor Temp calculation. Any thoughts? Code posted below.

    The circuit:
 * 5V to Arduino 5V pin
 * GND to Arduino GND pin
 * CLK to Analog #5
 * DAT to Analog #4
 * BUTTON to Analog #2
 * Thermistor to Analog #3
 * Heater to digital #7

// include the library code:
#include <Wire.h>
#include <LiquidCrystal.h>
#include "OneButton.h"
#include <EEPROM.h>

LiquidCrystal lcd(0);
int heater = 7;       // heater is connected to pin 2
OneButton button(A2, true);
float settemp;
unsigned long currentTime;
unsigned long loopTime;

void setup()
  currentTime = millis();
  loopTime = currentTime;
  EEPROM.read (1); // make the eeprom or atmega328 memory address 1
  // link the doubleclick function to be called on a doubleclick event.   
  pinMode(heater, OUTPUT);                       // Set the Heater Valve pin as output
    lcd.print("  D.W. VEGGIE");
    lcd.print(" BURNER SYSTEMS");
    lcd.print("  CENTRITHERM");
    lcd.print("     V1.0");  
    lcd.print("SET TEMP     F   ");
    lcd.print("OIL TEMP     F   ");  

double Thermister2(int RawADC) {
  double Temp2;
  Temp2 = log(((10240000/RawADC) - 10000));
  Temp2 = 1 / (0.001129148 + (0.000234125 * Temp2) + (0.0000000876741 * Temp2 * Temp2 * Temp2));
  Temp2 = Temp2 - 273.15;           // Convert Kelvin to Celcius
  Temp2 = (Temp2 * 1.8) + 32;    // Convert to F
  Temp2 = round(Temp2);
  return Temp2;

void loop()
  currentTime = millis();
  settemp = EEPROM.read(1); // read the settemp on the eeprom
  if(currentTime >= (loopTime + 500)){ 
    double Temp2 = Thermister2(analogRead(1));   // read Thermistor
    if (Temp2 < settemp) digitalWrite(heater, HIGH);      // turn heater on 
        else if (Temp2 >= settemp) digitalWrite(heater, LOW);  // turn heater off 
    loopTime = currentTime;
  EEPROM.write (1,settemp);  

// this function will be called when the button was pressed 2 times in a short timeframe.
void doubleclick() {
   settemp --  // remove one to the settemp, the settemp is the ideal temperature for you
} // doubleclick

// this function will be called when the button was pressed 1 time in a short timeframe.
void click() {
  (settemp ++);  // add one to the settemp, the settemp is the ideal temperature for you
} // click
// End

No, the problem is that you didn't erase the "0" at the end of "100". Output enough spaces after the current value to blank out the previous value.

| improve this answer | |
  • \$\begingroup\$ Thanks, All i did was add another lcd.print(" "); on the line after the set temps. Thanks \$\endgroup\$ – D.W. Nov 3 '13 at 20:44
  • \$\begingroup\$ Funny enough this happened to me as well when I first began using LCD screens so I knew immediately what you're problem was. I was so confused on why my counter would go from 0 -> 255, and then when it counted backwards that, once below 100, it would start at 990 and go down by 10s! \$\endgroup\$ – sherrellbc Jun 22 '14 at 16:56

This isn't down to rounding, but down to the way the characters are displayed on your lcd. Once you display 100 you are displaying three characters on your display then when it drops down to 99 you are only displaying 2 characters, yet the display shunts it right leaving the 0 from the 100 still displayed.

Not sure of the exact solution but try experimenting with the lcd.setCursor(9,1); and lcd.setCursor(9,0); functions.

Or call the lcd.clear(); function somewhere in your void loop();

| improve this answer | |

Also, writes to EEPROM will wear it out.

Better to use a variable on the stack, or heap.

Another tip, the only way to debug arduino is Serial.println() it's tedious however it will confirm what they said.

| 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.