temp sensor not updating

Noob here trying to fumble my way through my first project. The temp sensor will only update when i switch through all my pages (not continuous) i imagine that its not looping on its “page”. please help! and use small words too :stuck_out_tongue:

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

float tempC;
int tempPin = 1;
int switchPin = 4; // momentary switch on 8, other side connected to ground
int Display = 0;

void setup()
{
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH); // turn on pullup resistor

}

void loop()
{
if (digitalRead(switchPin) == LOW){
delay(500); // delay to debounce switch

Display = Display + 1;
if(Display > 5){
lcd.clear();
Display = 1;
}

switch (Display) {
case 1: {
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Cab Temp”);
tempC = analogRead(tempPin); //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature
lcd.setCursor(10, 0);
lcd.print(tempC,1);
lcd.print("'C");
lcd.setCursor(0,1);
lcd.print(“Out Temp”);
tempC = analogRead(tempPin);
tempC = (5.0 * tempC * 100.0)/1024.0;
lcd.setCursor(10, 1);
lcd.print(tempC,1);
lcd.print("'C");
break;
}

}

case 2: {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Fr Temp”);
lcd.setCursor(0,1);
lcd.print(“Fr Pilot”);
break;
}

case 3: {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Main”);
lcd.setCursor(0, 1);
lcd.print(“House”);

break;
}

case 4: {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“SP Volts”);
lcd.setCursor(0, 1);
lcd.print(“SP Amps”);
break;
}

case 5: {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Water Level”);
break;
}
}
}
}

noob here working on my first project. the temperature won’t loop. It will update if i scroll through all the pages

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

float tempC;
int tempPin = 1;
int switchPin = 4;   
int Display = 0;








void setup()
{
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);      // turn on pullup resistor



}
  

void loop()
{
    if (digitalRead(switchPin) == LOW){  
    delay(500);                      // delay to debounce switch

    Display = Display + 1;
    if(Display > 5){
      lcd.clear();
      Display = 1;
    }
   
    
    switch (Display) {
      case 1: {
        {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Cab Temp");
        tempC = analogRead(tempPin);                 //read the value from the sensor    
        tempC = (5.0 * tempC * 100.0)/1024.0;        //convert the analog data to temperature 
        lcd.setCursor(10, 0);
        lcd.print(tempC,1);
        lcd.print("'C");
        lcd.setCursor(0,1);
        lcd.print("Out Temp");
        tempC = analogRead(tempPin);           
        tempC = (5.0 * tempC * 100.0)/1024.0;  
        lcd.setCursor(10, 1);
        lcd.print(tempC,1);
        lcd.print("'C");
        break;
  }
         
        
        
      }
        
      case 2: {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Fr Temp");
        lcd.setCursor(0,1);
        lcd.print("Fr Pilot");
        break;
      }
        
       case 3: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("Main");
         lcd.setCursor(0, 1);
         lcd.print("House");
         
         break;
       }
      
       case 4: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("SP Volts");
         lcd.setCursor(0, 1);
         lcd.print("SP Amps");
         break;
       }
 
       case 5: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("Water Level");
         break;
       }
 }
}
}

Case 1 is the only case that has any code that has anything to do with any sensor. The rest just print stuff out.

If you want that temp data updated every time through loop, then take it out of the switch case.

I've taken it out, but no matter where i put it nothing nothing happens

I’ve taken it out, but no matter where i put it nothing nothing happens

Please post your revised code.

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

float tempC;
int tempPin = 1;
int switchPin = 4;   // momentary switch on 8, other side connected to ground
int Display = 0;









void setup()
{
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);      // turn on pullup resistor
  

}
  

void loop()
{      
        
    if (digitalRead(switchPin) == LOW){  
    delay(500);                      // delay to debounce switch

    Display = Display + 1;
    if(Display > 5){
      lcd.clear();
      Display = 1;
    }
     {tempC = analogRead(tempPin);           
        tempC = (5.0 * tempC * 100.0)/1024.0;} 
    
    switch (Display) {
      case 1: {
        {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Cab Temp");
        
        lcd.setCursor(10, 0);
        lcd.print(tempC,1);
        lcd.print("'C");
        lcd.setCursor(0,1);
        lcd.print("Out Temp");
        
        lcd.setCursor(10, 1);
        lcd.print(tempC,1);
        lcd.print("'C");
        break;
  }
         
      
      }
        
      case 2: {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Fr Temp");
        lcd.setCursor(0,1);
        lcd.print("Fr Pilot");
        break;
      }
        
       case 3: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("Main");
         lcd.setCursor(0, 1);
         lcd.print("House");
         
         break;
       }
      
       case 4: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("SP Volts");
         lcd.setCursor(0, 1);
         lcd.print("SP Amps");
         break;
       }
 
       case 5: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("Water Level");
         break;
       }
 }
}
}

Are you wanting the sensor to be read or are you also wanting the screen to update. Right now the switch case with all the display code in it is inside the if (digitalRead(switchPin) == LOW) block. So the display only updates when you press the button.

What's the matter? You don't like the answers you are getting in your other thread with the same name?

i am wanting the screen to update with the real time temp.

i figured out how to post the code properly. so i was trying to be polite

Well I would get the code out of that if block then. Cause now it only updates when you press the button. All you need in that if block is to increment your Display variable.

thanks that worked. one more question, the temp is now displaying on every page and i’m looking to designate it to case 1

UKHeliBob:
Please post your revised code.

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

  • Moderator
[code#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float tempC;
int tempPin = 1;
int switchPin = 4;   
int Display = 0;








void setup()
{
  lcd.begin(16, 2);
  pinMode(switchPin, INPUT);
  digitalWrite(switchPin, HIGH);     



}
  

void loop()
{
        
      {  
        tempC = analogRead(tempPin);                     
        tempC = (5.0 * tempC * 100.0)/1024.0;         
        lcd.setCursor(10, 0);
        lcd.print(tempC,1);
        lcd.print("'C");
        
      }




    if (digitalRead(switchPin) == LOW){  
    delay(500);                      

    Display = Display + 1;
    if(Display > 5){
      lcd.clear();
      Display = 1;
    }
   
    
    switch (Display) {
      case 1: {
        {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Cab Temp");
        lcd.setCursor(0,1);
        lcd.print("Out Temp");
        
        break;
        }
         
        
        
      }
        
      case 2: {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Fr Temp");
        lcd.setCursor(0,1);
        lcd.print("Fr Pilot");
        break;
      }
        
       case 3: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("Main");
         lcd.setCursor(0, 1);
         lcd.print("House");
         
         break;
       }
      
       case 4: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("SP Volts");
         lcd.setCursor(0, 1);
         lcd.print("SP Amps");
         break;
       }
 
       case 5: {
         lcd.clear();
         lcd.setCursor(0, 0);
         lcd.print("Water Level");
         break;
       }
 }
}
}
]

thanks Nick Gammon

Well now you've got the code to read the temp from the sensor out of the case statement and in the main loop where it happens every pass through. That's good but you brought the code to display it on the lcd out there with it. So it displays temp on the lcd every time. That's not what you want is it? You want that display code to happen only in case 1. So doesn't it make sense to have that code in case 1?