Pages: [1]   Go Down
Author Topic: Temp measurement and display  (Read 732 times)
0 Members and 1 Guest are viewing this topic.
South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!

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




#include <math.h>

double Thermister(int RawADC) {
 double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 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.print(int(Thermister(analogRead(0))));
 
  lcd.setCursor(2,0);
  lcd.print((char)223);
 
 
    lcd.setCursor(3,0);
    lcd.print ("c");



 Serial.println(int(Thermister(analogRead(0))));  // display Fahrenheit
 delay(1000);
}

Logged

South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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?

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




#include <math.h>

double Thermister(int RawADC) {
 double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 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.print(int(Thermister(analogRead(0))));


if (int(Thermister(analogRead(0)))  <= 10)
{
  lcd.setCursor(1,0);
  lcd.print((char)223);
 
 
    lcd.setCursor(2,0);
    lcd.print ("c");  // action A
}
else if (int(Thermister(analogRead(0)))  >= 10)
{
  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");



 Serial.println(int(Thermister(analogRead(0))));  // display Fahrenheit
 
 
   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
 
}

« Last Edit: August 14, 2011, 06:14:36 pm by dtokez » Logged

Dallas, Texas
Offline Offline
God Member
*****
Karma: 0
Posts: 861
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
void loop() {
 
      lcd.setCursor(0,0);
lcd.print(int(Thermister(analogRead(0))));
 
 // lcd.setCursor(2,0);
  lcd.print((char)223);
 
 
//    lcd.setCursor(3,0);
    lcd.print ("c");
Logged

South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks  smiley-cool 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  smiley-red

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

South UK
Offline Offline
God Member
*****
Karma: 2
Posts: 568
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

anyone know?

thanks
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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.
Logged


Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Or if you prefer spaces iso leading zero's
(based upon code above)
Code:
lcd.setCursor(right, position);
if (temp<10) lcd.write(' ');  // space
lcd.print(temp);
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 64
Posts: 6893
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Or trailing space, ...  smiley-grin
Logged


Pages: [1]   Go Up
Jump to: