Go Down

Topic: temp sensor not updating (Read 1 time) previous topic - next topic

aaronchan

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  :smiley-razz:

 
#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;
       }
 }
}
}

aaronchan

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






Code: [Select]


#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;
       }
 }
}
}

Delta_G

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

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

aaronchan

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

UKHeliBob

Quote
I've taken it out, but no matter where i put it nothing nothing happens
Please post your revised code.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

aaronchan

Code: [Select]

#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;
       }
 }
}
}

Delta_G

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

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

PaulS

What's the matter? You don't like the answers you are getting in your other thread with the same name?
The art of getting good answers lies in asking good questions.

aaronchan

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

aaronchan

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

Delta_G

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

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

aaronchan

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

Delta_G

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

nickgammon

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

Threads merged.

- Moderator
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

aaronchan

Code: [Select]
[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;
       }
 }
}
}
]

Go Up