Creating a thermometer

Hi there
I am sooo new to Arduino. But in a short time I have gotten to the point where I am creating a baby bath thermometer. In this the user can enter a max temp and a minimum temp and the thermister reads the temp and writes it to the LED. On the LCD screen the user is warned if the bath water is getting too cold or is too hot. I have a red (too hot), green (just right) and blue (too cold) LED lights that glow in accordance to the temperature.

I have gotten as far as:

  • LCD prompts the user for max and min temperature
  • User uses the serial monitor to enter the desired temperature
  • All the temperature prompts and readings work

My code for this is:

#include <math.h>         //loads the more advanced math functions
#include <LiquidCrystal.h> //Load Liquid Crysatal Library

LiquidCrystal LCD (10,9,5,4,3,2); //Creating the LCD object named LCD and how we hooked up the pins

 int redLED=11;
 int blueLED=13;
 int greenLED=12;
 float tooHot;
 float tooCold;

 
void setup() {            //This function gets called when the Arduino starts
  Serial.begin(9600);   //This code sets up the Serial port at 115200 baud rate
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);

LCD.print("max temp?");  //Prompt the use for the max temp
delay (5000);
 while (Serial.available()==0) {}//makes computer wait
 tooHot = Serial.parseFloat(); //reads the imput
 LCD.clear();

LCD.print("min temp?");  //Prompt the user for the min temp
 while (Serial.available()==0) {}//makes computer wait
 tooCold = Serial.parseFloat(); //reads the imput
 LCD.clear();
  
}
 
double Thermister(int RawADC) {  //Function to perform the fancy math of the Steinhart-Hart equation
 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 Celsius
 return Temp;
}
 
void loop() {             //This function loops while the arduino is powered
  int val;                //Create an integer variable
  double temp;            //Variable to hold a temperature value
  val=analogRead(0);      //Read the analog port 0 and store the value in val
  temp=Thermister(val);   //Runs the fancy math on the raw analog value
  LCD.begin(16,2); //Tell arduino the LCD has 16 col 2 rows
  LCD.setCursor(0,0); //Set LCD cursor to upper left
  LCD.print("Temp:"); //Print first line
  LCD.print(temp);   //Print the value to the LCD
  LCD.print((char)223);  //Print the degree symbol to LCD
  LCD.print ("C");  //Print the C to LCD
  delay(1000);            //Wait one second before we do it again
  

  if (temp <=tooCold){    //if statement sets blue LED if temp is above max temp
    LCD.setCursor(0,1);//set cursor to first col and second row
    LCD.setCursor(0,1);//set cursor to first col and second row
    LCD.print("burrr TOO COLD!"); //Print first line
  digitalWrite(blueLED,HIGH);
  digitalWrite(greenLED,LOW);
  digitalWrite(redLED,LOW);
  delay(1000);//units appear in seconds
 }
  if ((temp>tooCold)&&(temp<tooHot)) { //if statement sets green LED if temp is between min and max temp
    LCD.setCursor(0,1);//set cursor to first col and second row
    LCD.setCursor(0,1);//set cursor to first col and second row
    LCD.print("mmm..Just Right!"); //Print first line
  digitalWrite(greenLED,HIGH);
  digitalWrite(blueLED,LOW);
  digitalWrite(redLED,LOW);
    delay(1000);//units appear in seconds
 }
  if (temp >=tooHot){ //if statement sets red LED if temp is below min temp
    LCD.setCursor(0,1);//set cursor to first col and second row
    LCD.setCursor(0,1);//set cursor to first col and second row
    LCD.print("TOO HOT!!!"); //Print first line
  digitalWrite(redLED,HIGH);
  digitalWrite(blueLED,LOW);
  digitalWrite(greenLED,LOW);
  delay(1000);//units appear in seconds
 }
}

However, I want the user to be able to enter the desired temperature values using a 'Çar MP3' IR remote that came with the Arduino kit I bought. I would use a keypad, but I have no more pins remaining on the Arduino board! I have looked everywhere for a sketch to help. The closest I got was this:

/* YourDuino.com Example Software Sketch
 IR Remote Kit Test: Returns numeric value for button pressed
 Uses YourDuino.com IR Infrared Remote Control Kit V2
 http://arduino-direct.com/sunshop/index.php?l=product_detail&p=153
 based on code by Ken Shirriff - http://arcfn.com
 terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include "IRremote.h"
#include "IRremoteInt.h"

/*-----( Declare Constants )-----*/
#define  REPEAT_DELAY  500   // Delay before checking for another button / repeat
int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11
                   // NOTE: Other pins can be used, except pin 3 and 13
                  
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'

/*-----( Declare Variables )-----*/
int  ButtonValue;  // 0..9,100,200, top 9 buttons encoded 10..18, -1 Bad Code


void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("YourDuino.com IR Infrared Remote Control Kit V2");  
  Serial.println("IR Receiver Raw Data + Button Decode Test");
  irrecv.enableIRIn(); // Start the receiver

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
//    Serial.println(results.value, HEX); // UN Comment to see raw values
    ButtonValue = translateIR(); 
    Serial.println(ButtonValue, DEC);
    delay(REPEAT_DELAY);    // Adjust for repeat / lockout time
    irrecv.resume(); // receive the next value
  }  
}/* --(end main loop )-- */

/*-----( Declare User-written Functions )-----*/
int translateIR() // returns value of "Car MP3 remote IR code received

{

 switch(results.value)

  {

  case 0xFFA25D:  
    return 10;  // CH-
    break;

  case 0xFF629D:  
    return 11; // CH
    break;

  case 0xFFE21D:  
    return 12; // CH+
    break;

  case 0xFF22DD:  
    return 13; // PREV
    break;

  case 0xFF02FD:  
    return 14; // NEXT
    break;

  case 0xFFC23D:  
    return 15; //  PLAY/PAUSE     
    break;

  case 0xFFE01F:  
    return 16; // VOL-
    break;

  case 0xFFA857:  
    return 17; // VOL+ 
    break;

  case 0xFF906F:  
    return 18; // EQ 
    break;

  case 0xFF6897:  
    return 0; // ZERO
    break;

  case 0xFF9867:  
    return 100; // 100+ 
    break;

  case 0xFFB04F:  
    return 200; // 200+ 
    break;

  case 0xFF30CF:  
    return 1;  // 1 etc.. to 9
    break;

  case 0xFF18E7:  
    return 2; 
    break;

  case 0xFF7A85:  
    return 3; 
    break;

  case 0xFF10EF:  
    return 4;  
    break;

  case 0xFF38C7:  
    return 5; 
    break;

  case 0xFF5AA5:  
    return 6; 
    break;

  case 0xFF42BD:  
    return 7; 
    break;

  case 0xFF4AB5:  
    return 8;  
    break;

  case 0xFF52AD:  
    return 9; // 9 
    break;

  case 0xFFFFFFFF:  
    return -2; // REPEAT: Button Held down longer than 
    break;
  default: 
    return -1; // Other Button  / Bad Code

  } //END case

} //END translateIR



/* ( THE END ) */

I have searched and search and tried combining the two sketches using my knowledge so far. I want to be able to:

  • Have the user enter the temperature values (often double digit) using the IR Remote and have the LCD display them as they do.
  • Reset the temperatures if they wish at any time.

Please help if you can point me in the right direction, I would be really grateful.

What sort of values are you expecting the user to enter? The first code uses parseFloat(), which implies decimal points. It is rather unusual to see a maximum temperature, for batch water, with fractional values.

When the user is supposed to be entering a temperature value, you can see of anything has been pressed on the remote. If so, use a lookup table to see which key the value belongs to. If you find, for instance, that the user pressed the 1 button, then multiply the value by 10 and add the new value. (0 * 10 = 0; 0 + 1 = 1). It the user presses 0 and then 4, 1 * 10 = 10; 10 + 0 = 10; 10 * 10 = 100; 100 + 4 = 104.

You'll want some key on the remote to mean "Use the value that you have been computing".
You'll want some key on the remove to mean "Oops, I want to start over; I really don't want the maximum temperature to be 904 degrees".

but I have no more pins remaining on the Arduino board!

The unused pins A1 to A5 can be used as Digital I/Os or buy one of the cheap lcd parallel to serial converters which make wiring a 16x2 lcd so much easier.