# Temp measurement and display

hi all, just messing around and getting used to the arduino.

I’ve hooked up a 10k thermistor and got it working using a tutorial to feedback data over serial. I have added too the code to display on my lcd screen. It works but when the temp goes below 10 degrees the display moves the digit over so for example 9 degrees reads 90. It does not display like this on the serial monitor however, but I used the same code to get the data over the display?
Hope that makes sense!

``````#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#include <math.h>

double Temp;
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;            // Convert Kelvin to Celcius

return Temp;
}

void setup() {
lcd.begin(16, 2);
delay(100);
Serial.begin(115200);
}

void loop() {

lcd.setCursor(0,0);

lcd.setCursor(2,0);
lcd.print((char)223);

lcd.setCursor(3,0);
lcd.print ("c");

delay(1000);
}
``````

right, if i reset the board when the temp is below 10 degrees the lcd displays fine, so I guess when it goes below 10 I need to clear the display or something?

dtokez: right, if i reset the board when the temp is below 10 degrees the lcd displays fine, so I guess when it goes below 10 I need to clear the display or something?

You need to clear out, write spaces, where your temperature goes before you write a new value.

hey, thanks that works great. I’m still really new to the arduino but learning little bits here and there especially thanks to people like yourself

would it be complicated to have the degrees c symbol move to the left by one space when the temperature reading is in single figures?

Edit…

tried putting in if/else statements. It does compile and run but when the temp is <10 i get two degrees symbols for example 2°°C?

is it ignoring the if/else and just running both?

``````#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

#include <math.h>

double Temp;
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;            // Convert Kelvin to Celcius

return Temp;
}

void setup() {
lcd.begin(16, 2);
delay(100);
Serial.begin(115200);
pinMode(13, OUTPUT);
}

void loop() {
lcd.clear();

lcd.setCursor(0,0);

{
lcd.setCursor(1,0);
lcd.print((char)223);

lcd.setCursor(2,0);
lcd.print ("c");  // action A
}
{
lcd.setCursor(2,0);
lcd.print((char)223);

lcd.setCursor(3,0);
lcd.print ("c");  // action B
}

lcd.setCursor(2,0);
lcd.print((char)223);

lcd.setCursor(3,0);
lcd.print ("c");

digitalWrite(13, HIGH);   // set the LED on
delay(2);              // wait for a second
digitalWrite(13, LOW);    // set the LED off
delay(10000);              // wait for a second

}
``````

Instead of explicitly moving the cursor to the third column you could just print the degrees symbol and "c" immediately after the temperature. If you don't explicitly move it, it prints in the next available space.

``````void loop() {

lcd.setCursor(0,0);

// lcd.setCursor(2,0);
lcd.print((char)223);

//    lcd.setCursor(3,0);
lcd.print ("c");
``````

Thanks 8) I thought you had to tell the characters exactly where to be placed. so that's much better now.

I edited the post while you where replying DOH :blush:

out if interest, what was I doing wrong with the if/else statements?

anyone know?

thanks

This question pops up on a regular basis. Simple solutions I always provide (assume temperature is integer):

``````lcd.setCursor(what,ever);
if (temp<10) lcd.write('0');
lcd.print(temp);
``````

Don’t use lcd.clear. It makes your screen flash and dim.

If you need to assure 100 degree, just add “if (temp<100) lcd.write(‘0’);” before the other if.

Or if you prefer spaces iso leading zero’s
(based upon code above)

``````lcd.setCursor(right, position);
if (temp<10) lcd.write(' ');  // space
lcd.print(temp);
``````

Or trailing space, ... :D