Retrieving one analog data output at the push of a digital button?

Hello,

I’m attempting to gather simply one analog data point from a thermistor with the push of a digital button. Essentially I would like to take the desired value (value obtained from button push) and compare it with the fluctuating temperature values. I have an RGB LED set in the system and what I would like it to do is if the selected value is less than analog temp values turn green and if it is greater than analog temp value turn red. I have a code that visually seems like it works but there are other things under the hood that I’m missing. I can click the button to display that current temperature, but when I try to compare the value with the analog temp values the LED doesn’t seem to respond like I want. I found that it works when I hold down the button but they both become fluctuating temp analogReads. I was wondering if someone could help me with the commands to retrieve an analog value. I’ve been all over the internet with this one but nothing pertains to what I’d like to do. The code I have so far is displayed below and I’ve also included an image of my project. Thanks in advance.

#include <LiquidCrystal.h>

int tempPin=0;

#define RED 10
#define BLUE 12
#define GREEN 11

LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin=9;
int buttonState=0;

void setup() {

  lcd.begin(16, 2);

  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
  pinMode(BLUE,OUTPUT);
  digitalWrite(BLUE,HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN,LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {

  int tempReading=analogRead(tempPin);
  
  double tempK=log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK);
float tempC = tempK - 273.15;
float tempF = (tempC * 9.0)/5.0 + 32.0;

lcd.setCursor(0,0);
lcd.print("Temp:");

lcd.setCursor(0,1);
lcd.print(tempC);

  delay(500);

 buttonState=digitalRead(buttonPin);

 if (buttonState == LOW)
 { Serial.println("Button Pressed");

 int setTemp=analogRead(tempPin);
 

  double tempK1=log(10000.0 * ((1024.0 / setTemp - 1)));
  tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1);
float tempC1 = tempK1 - 273.15;
float tempF1 = (tempC1 * 9.0)/5.0 + 32.0;
 
lcd.setCursor(7,0);
lcd.print("Set Temp:");
lcd.setCursor(7,1);
lcd.print(tempC1);
lcd.print(" (C)");

if (tempC<tempC1)

{digitalWrite(RED, HIGH);
digitalWrite(BLUE,LOW);
digitalWrite(GREEN,LOW);}

else if (tempC>tempC1)
{digitalWrite(GREEN,HIGH);
digitalWrite(BLUE,LOW);
digitalWrite(RED,LOW);}

 }

Serial.println(tempC);
}

I'm attempting to gather simply one analog data point from a thermistor with the push of a digital button.

Currently you are reading the temperature while the button [u]is[/u] pressed whereas you need to read the temperature when the button [u]becomes[/u] pressed.

Look at the StateChangeDetection example in the IDE to see how to do it.

UKHeliBob:
Currently you are reading the temperature while the button is pressed whereas you need to read the temperature when the button becomes pressed.

Look at the StateChangeDetection example in the IDE to see how to do it.

Ooooohhhh. Ok I see what you are saying. So I took the code from that and used it below. Right now the button is being staying on and I have to hold it to get the set temperature to remain still. Any suggestions?

buttonState=digitalRead(buttonPin);

if (buttonState != lastButtonState)
{ if (buttonState == HIGH)
{ Serial.println("Button Pressed");

 int setTemp=analogRead(tempPin);
 
 double tempK1=log(10000.0 * ((1024.0 / setTemp - 1)));
 tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * 
 tempK1 * tempK1 )) * tempK1);
 float tempC1 = tempK1 - 273.15;
 float tempF1 = (tempC1 * 9.0)/5.0 + 32.0;
 
 lcd.setCursor(7,0);
 lcd.print("Set Temp:");
 lcd.setCursor(7,1);
 lcd.print(tempC1);
 lcd.print(" (C)");

if (tempC<tempC1)

{digitalWrite(RED, HIGH);
digitalWrite(BLUE,LOW);
digitalWrite(GREEN,LOW);}

if (tempC>tempC1)
{digitalWrite(GREEN,HIGH);
digitalWrite(BLUE,LOW);
digitalWrite(RED,LOW);}

 } else {
  Serial.println("off");
 }

[\code]

Where do you save buttonState to lastButtonState so that from one loop() iteration to the next, the state change can be detected?

And look carefully at the bracket arraignment in this part.

if (buttonState != lastButtonState)
{ if (buttonState == HIGH)
{ Serial.println("Button Pressed");

It looks like this with better formatting and CTRL-T autoformat

buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState)
{
  if (buttonState == HIGH)
  }
{
  Serial.println("Button Pressed");

Sorry, I excluded some things. Here is the whole code. I want it to store the one value of the analog read at the time of the button push. I don’t want it to display on the LCD screen until I push it too.

#include <LiquidCrystal.h>

int tempPin=0;

#define RED 10
#define BLUE 12
#define GREEN 11

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin=9;
int buttonState=0;
int lastButtonState=0;
int buttonPushCounter=0;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);

  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
  // Print a message to the LCD.
  //lcd.print("TEMP:  SET TEMP:");

  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
  pinMode(BLUE,OUTPUT);
  digitalWrite(BLUE,HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN,LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {

int tempReading=analogRead(tempPin);
  
double tempK=log(10000.0 * ((1024.0 / tempReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK);
float tempC = tempK - 273.15;
float tempF = (tempC * 9.0)/5.0 + 32.0;

lcd.setCursor(0,0);
lcd.print("Temp:");

lcd.setCursor(0,1);
lcd.print(tempC);

delay(500);

buttonState=digitalRead(buttonPin);

if (buttonState != lastButtonState)
{ if (buttonState == LOW)
{ buttonPushCounter++;
Serial.println("on");
Serial.println("number of button pushes:   ");
Serial.println(buttonPushCounter);
} else {
  Serial.println("off");
}

delay(50);

lastButtonState=buttonState;

if (buttonPushCounter %1 == 0) {
  
 int setTemp=analogRead(tempPin);
 
 double tempK1=log(10000.0 * ((1024.0 / setTemp - 1)));
 tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1);
 float tempC1 = tempK1 - 273.15;
 float tempF1 = (tempC1 * 9.0)/5.0 + 32.0;
 
 lcd.setCursor(7,0);
 lcd.print("Set Temp:");
 lcd.setCursor(7,1);
 lcd.print(tempC1);
 lcd.print(" (C)");

//if (tempC<tempC1)

//{digitalWrite(RED, HIGH);
//digitalWrite(BLUE,LOW);
//digitalWrite(GREEN,LOW);}

//else if (tempC>tempC1)
//{digitalWrite(GREEN,HIGH);
//digitalWrite(BLUE,LOW);
//digitalWrite(RED,LOW);}
}
}
}

What does the new code do? How is that different from what you want?

Your code would be easier to read (and troubleshoot) if you put each and every curly bracket on its own line and use the autoformat feature of the IDE (ctrl-t or Tools, Auto Format).

if (buttonPushCounter % 1 == 0)

What does that do? What is the remainder when a number is divided by 1. https://www.arduino.cc/en/Reference/Modulo

When I start the code, the LCD displays the analog temp values (tempC) on the left side and on the right side it displays the setTemp (tempC1). It automatically “pauses” the setTemp with the current temperature reading from the left side on start-up. I don’t want it to do this until I press the button. I have it so where it sets the desired Set Temp: after every 1 button push which is what I wanted. I just don’t want it to automatically set temp on start up. Also I need to be able to save the selected temp value to a variable. And I apologize about the coding format. Hopefully this works better.

#include <LiquidCrystal.h>

int tempPin = 0;

#define RED 10
#define BLUE 12
#define GREEN 11

LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin = 9;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;

void setup() {
  
  lcd.begin(16, 2);

  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {

  int tempReading = analogRead(tempPin);
  int setTemp = analogRead(tempPin);

  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * 
  tempK);
  float tempC = tempK - 273.15;
  float tempF = (tempC * 9.0) / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp:");

  lcd.setCursor(0, 1);
  lcd.print(tempC);

  delay(500);

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  { if (buttonState == LOW)
    { buttonPushCounter++;
      Serial.println("on");
      Serial.println("number of button pushes:   ");
      Serial.println(buttonPushCounter);
    } else {
      Serial.println("off");
    }

    delay(50);

    lastButtonState = buttonState;

    if (buttonPushCounter % 1 == 0) {

      // Converts analog readings to temperature values.

      double tempK1 = log(10000.0 * ((1024.0 / setTemp - 1)));
      tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * 
      tempK1 )) * tempK1);
      float tempC1 = tempK1 - 273.15;
      float tempF1 = (tempC1 * 9.0) / 5.0 + 32.0;

      // Displays set temp on LCD screen.

      lcd.setCursor(7, 0);
      lcd.print("Set Temp:");
      lcd.setCursor(7, 1);
      lcd.print(tempC1);
      lcd.print(" (C)");

      //if (tempC<tempC1)

      //{digitalWrite(RED, HIGH);
      //digitalWrite(BLUE,LOW);
      //digitalWrite(GREEN,LOW);}

      //else if (tempC>tempC1)
      //{digitalWrite(GREEN,HIGH);
      //digitalWrite(BLUE,LOW);
      //digitalWrite(RED,LOW);}
    }
  }
}

See comments, please.

#include <LiquidCrystal.h>

int tempPin = 0;

#define RED 10
#define BLUE 12
#define GREEN 11

LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin = 9;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;

void setup()
{
  lcd.begin(16, 2);
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop()
{
  int tempReading = analogRead(tempPin);
  int setTemp = analogRead(tempPin);

  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) *
               tempK);
  float tempC = tempK - 273.15;
  float tempF = (tempC * 9.0) / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp:");

  lcd.setCursor(0, 1);
  lcd.print(tempC);

  delay(500);

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  {
    if (buttonState == LOW)
//******************************
      // here is where you put the code that runs when the button becomes pushed
      // assuming a switch wired to ground with a pullup.
      // the code will run one time and not again until the button becomes pushed
      // again.  Will ignore levels (high low) and the low to high transition 
      //(becomes not pushed).
//****************
    {
      buttonPushCounter++;  // is useless
      // if you are going to print something, at least make it relevant.
      Serial.println("on");
      Serial.println("number of button pushes:   ");
      Serial.println(buttonPushCounter);
    }
    else
    {
      Serial.println("off");
    }

    delay(50);

    lastButtonState = buttonState;

    if (buttonPushCounter % 1 == 0) // is useless. Will always be true
    {
 //**********************     
// if this is the code that you want to run on each button press, move it to 
// the indicated place in the state change detection code.     
      
      // Converts analog readings to temperature values.
      double tempK1 = log(10000.0 * ((1024.0 / setTemp - 1)));
      tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 *
                                   tempK1 )) * tempK1);
      float tempC1 = tempK1 - 273.15;
      float tempF1 = (tempC1 * 9.0) / 5.0 + 32.0;

      // Displays set temp on LCD screen.

      lcd.setCursor(7, 0);
      lcd.print("Set Temp:");
      lcd.setCursor(7, 1);
      lcd.print(tempC1);
      lcd.print(" (C)");
      
// ***************
     
    }
  }
}

Perfect! Thank you so much. If I could ask one last thing from you … I’m attempting to get the LEDs to light depending on certain conditions. If the analog readings (tempC) are greater than the value received on the button push (tempC1) turn red, If the analog readings are less than the received value turn green, and finally, if they are equal turn blue. I feel as if I have the correct if statements but when I upload code it says that tempC1 is not declared in the scope. I receive that error if I put them outside the button if statement. If I put them inside it works but only for one time! Any suggestions?

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  { if (buttonState == LOW)
      int tempPin = 0;
    int setTemp = analogRead(tempPin);

    double tempK1 = log(10000.0 * ((1024.0 / setTemp - 1)));
    tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1);
    float tempC1 = tempK1 - 273.15;
    float tempF1 = (tempC1 * 9.0) / 5.0 + 32.0;

    // Displays set temp on LCD screen.

    lcd.setCursor(7, 0);
    lcd.print("Set Temp:");
    lcd.setCursor(7, 1);
    lcd.print(tempC1);
    lcd.print(" (C)");

    Serial.println(tempC1);
  }

    delay(10);
  
    if (tempC < tempC1)

    { digitalWrite(RED, HIGH);
      digitalWrite(BLUE, LOW);
      digitalWrite(GREEN, LOW);
    }

    if (tempC > tempC1)
    { digitalWrite(GREEN, HIGH);
      digitalWrite(BLUE, LOW);
      digitalWrite(RED, LOW);
    }

    if (tempC = tempC1)
    { digitalWrite(GREEN, LOW);
      digitalWrite(BLUE, HIGH);
      digitalWrite(RED, LOW);
  lastButtonState = buttonState;
}

That is not all of your code so I can't compile it. Please post the whole sketch.

says that tempC1 is not declared in the scope.

Read about variable scope here. You declare (create) the tempC1 variable inside the state change detection if block. That means that the variable tempC1 is only available inside of the if block. Then you try to use the tempC1 variable outside of that block where it does not exist. The solution is to make tempC1 a global variable so that the whole sketch has access to it.

if (buttonState != lastButtonState)
  { if (buttonState == LOW)
      int tempPin = 0;
    int setTemp = analogRead(tempPin);

In this part, the lack of a curly bracket after the if statement (if(buttonState == LOW)) means that the next statement is the only statement that will be executed conditionally (int tempPin = 0). Is that what you intended? If not, you need to mind your brackets better. That is why all { and } have their own line. It is easier to see if one is missing and shows code blocks better, if properly indented. Look at the code that I posted. Is it not easier to follow?

Again my apologies. Difficult to notice. So the code below works much better. I put the { AND } in where it was supposed to be and defined a global variable for tempC1 called temphold. The LED changes but it’ll only change once and after that it’s done. Below is what I have.

#include <LiquidCrystal.h>

int tempPin = 0;

#define RED 10
#define BLUE 12
#define GREEN 11

LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin = 9;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;

void setup() {

  lcd.begin(16, 2);

  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {

  int tempReading = analogRead(tempPin);

  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK);
  float tempC = tempK - 273.15;
  float tempF = (tempC * 9.0) / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp:");

  lcd.setCursor(0, 1);
  lcd.print(tempC);

  delay(500);

  float temphold;

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  { if (buttonState == LOW)
    { int tempPin = 0;
      int setTemp = analogRead(tempPin);

      double tempK1 = log(10000.0 * ((1024.0 / setTemp - 1)));
      tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1);
      float tempC1 = tempK1 - 273.15;
      float tempF1 = (tempC1 * 9.0) / 5.0 + 32.0;

      // Displays set temp on LCD screen.

      lcd.setCursor(7, 0);
      lcd.print("Set Temp:");
      lcd.setCursor(7, 1);
      lcd.print(tempC1);
      lcd.print(" (C)");

      Serial.println(tempC1);

      if (tempC < temphold)
      { digitalWrite(RED, HIGH);
        digitalWrite(BLUE, LOW);
        digitalWrite(GREEN, LOW);
      }

      if (tempC > temphold)
      { digitalWrite(GREEN, HIGH);
        digitalWrite(BLUE, LOW);
        digitalWrite(RED, LOW);
      }

      if (tempC = temphold)
      { digitalWrite(GREEN, LOW);
        digitalWrite(BLUE, HIGH);
        digitalWrite(RED, LOW);
      }
    }
  }
  delay (10);

  lastButtonState = buttonState;
}

With the code I sent you I realize since it's in the scope so you wouldn't need a global variable thus making it incorrect, but when I move it outside the scope after the (delay(10)) the temphold variable will save the value for temp C for a split second and will continue spitting out zeros therefore keeping the LED green. Any suggestions?

defined a global variable for tempC1 called temphold

Why? All that you had to do was put int float tempC1 =0 up in the global variable section (above setup()) and remove the int float from where you were declaring tempC1 in the if block.

Adding temphold did less than nothing because: 1. It is not global, it is local to loop(). 2. It is an uninitialized local variable which means that its value is undefined (could be anything). 3, And then you never give it a value.

if (tempC = temphold)

A couple of things about this line. One is that for comparising two variables it is == , = is for assigning a value to a variable. And using equality with floats always leads to heartache. Floating point numbers are not stored with super accuracy. 5.999999999 is not equal to 6.0 even if you want it to be.

groundFungus: All that you had to do was put int tempC1 =0 up in the global variable section (above setup()) and remove the int from where you were declaring tempC1 in the if block.

What did you mean by remove the int tempC1? When I removed the variable temphold and put tempC1 = 0 above setup it keeps putting out zeros and when I compare tempC to tempC1 it stays green because it's constantly comparing tempC to 0. I'm not getting an undeclared error though.

What did you mean by remove the int tempC1?

OK My bad. :o tempC1 is a float. So, above setup() put float tempC1 = 0.0; Then where you declare float tempC1 now, instead of

float tempC1 = tempK1 - 273.15;

it should be

tempC1 = tempK1 - 273.15;

If you don't remove the "float" from that line, you are declaring another version of tempC1 local to the if block and if you use tempC1 outside of the if block it refers to the global tempC1 which is 0 because it was never given any other value.

Any time you change the code, please post the latest.

Perfect. I cannot express how thankful I am for your help. Once it worked I took a lap around the campus in joy. Haha. I hooked you up with as much karma I could send :)

Thank you for the feedback. Not everyone takes the time once their project works.

It’s no problem at all. You used your time to help me. However, just when I thought everything was up and running there is one last problem I need solved and I believe it’s an easy fix. I need the LED comparison to not happen until the button is pushed. I want the LED to stay blue until I push the button to obtain the selected value, and then have it compare it and have the LEDs change accordingly. Is it just a matter of adding an “else if” after the button push statement or add another if statement before the LED if statements?

Thanks again and look forward to your response. The code is included below:

#include <LiquidCrystal.h>

int tempPin = 0;

#define RED 17
#define BLUE 18
#define GREEN 16

LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin = 6;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;
float tempC1 = 0.0;
float tempF1 = 0.0;


void setup() {

  lcd.begin(16, 2);

  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {

  int tempReading = analogRead(tempPin);

  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK);
  float tempC = tempK - 273.15;
  float tempF = (tempC * 9.0) / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp:");

  lcd.setCursor(0, 1);
  lcd.print(tempC);

  delay(500);

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  { if (buttonState == LOW)
    { int tempPin = 0;
      int setTemp = analogRead(tempPin);

      double tempK1 = log(10000.0 * ((1024.0 / setTemp - 1)));
      tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1);
      tempC1 = tempK1 - 273.15;
      tempF1 = (tempC1 * 9.0) / 5.0 + 32.0;

      // Displays set temp on LCD screen.

      lcd.setCursor(7, 0);
      lcd.print("Set Temp:");
      lcd.setCursor(7, 1);
      lcd.print(tempC1);
      lcd.print(" (C)");
    }
  }
  delay(10);

  Serial.println("Temp:");
  Serial.println(tempC);
  Serial.println("============");
  Serial.println("Set Temp:");
  Serial.println(tempC1);
  Serial.println("============");

  if (tempC > tempC1)
  { digitalWrite(RED, HIGH);
    digitalWrite(BLUE, LOW);
    digitalWrite(GREEN, LOW);
  }

  if (tempC < tempC1)
  { digitalWrite(GREEN, HIGH);
    digitalWrite(BLUE, LOW);
    digitalWrite(RED, LOW);
  }

  if (tempC == tempC1)
  { digitalWrite(GREEN, LOW);
    digitalWrite(BLUE, HIGH);
    digitalWrite(RED, LOW);
  }

  lastButtonState = buttonState;
}

Is it just a matter of adding an "else if" after the button push statement or add another if statement before the LED if statements?

You have an idea there, why not try it? You can't really hurt anything by experimenting with code and, I believe, that you can learn a great deal. Put Serial.print statements in different places so that you can monitor what the sketch is doing and follow code execution,

So try your idea and if it doesn't work and you can't figure it out, post the new code and say what it does and how that is different from what you want.

Well using the serial print I found that before I “select” the value using the button the value is zero, thus having the temperature always being greater, thus turning the LED red. I tried using an “else if” after the if statement that detects the button push and saves the value that states that if the button hasn’t been pushed remain blue, but noticed that the LED flickers between red and blue until the button is pushed then flickers red blue and green and blue so that didn’t work. Everything after the button push works fine before altering the code it’s just keeping the light blue until it is pushed. I used the code below. Any suggestions?

#include <LiquidCrystal.h>

int tempPin = 0;

#define RED 17
#define BLUE 18
#define GREEN 16

LiquidCrystal lcd(8, 7, 5, 4, 3, 2);

const int buttonPin = 6;
int buttonState = 0;
int lastButtonState = 0;
int buttonPushCounter = 0;
float tempC = 0.0;
float tempF = 0.0;
float tempC1 = 0.0;
float tempF1 = 0.0;


void setup() {

  lcd.begin(16, 2);

  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  pinMode(BLUE, OUTPUT);
  digitalWrite(BLUE, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
}

int redValue;
int greenValue;
int blueValue;

void loop() {

  int tempReading = analogRead(tempPin);

  double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
  tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK);
  tempC = tempK - 273.15;
  tempF = (tempC * 9.0) / 5.0 + 32.0;

  lcd.setCursor(0, 0);
  lcd.print("Temp:");

  lcd.setCursor(0, 1);
  lcd.print(tempC);

  delay(500);

  buttonState = digitalRead(buttonPin);

  if (buttonState != lastButtonState)
  { if (buttonState == LOW)
    { int tempPin = 0;
      int setTemp = analogRead(tempPin);

      double tempK1 = log(10000.0 * ((1024.0 / setTemp - 1)));
      tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1);
      tempC1 = tempK1 - 273.15;
      tempF1 = (tempC1 * 9.0) / 5.0 + 32.0;

      // Displays set temp on LCD screen.

      lcd.setCursor(7, 0);
      lcd.print("Set Temp:");
      lcd.setCursor(7, 1);
      lcd.print(tempC1);
      lcd.print(" (C)");
    }
  }

  else if (buttonState = lastButtonState)
  { digitalWrite(BLUE, HIGH);
    digitalWrite(RED, LOW);
    digitalWrite(GREEN, LOW);
  }

  delay(10);

  Serial.println("Temp:");
  Serial.println(tempC);
  Serial.println("============");
  Serial.println("Set Temp:");
  Serial.println(tempC1);
  Serial.println("============");

  if (tempC > tempC1)
  { digitalWrite(RED, HIGH);
    digitalWrite(BLUE, LOW);
    digitalWrite(GREEN, LOW);
  }

  if (tempC < tempC1)
  { digitalWrite(GREEN, HIGH);
    digitalWrite(BLUE, LOW);
    digitalWrite(RED, LOW);
  }

  if (tempC == tempC1)
  { digitalWrite(GREEN, LOW);
    digitalWrite(BLUE, HIGH);
    digitalWrite(RED, LOW);
  }

  lastButtonState = buttonState;
}