LM 34 Temp Sensor

Hey guys,

I’m trying to make an arduino read multiple LM34cz temperature sensors for a project at work. I have the temp sensors working and also have it outputting to a sparkfun 16x2 serLCD. The problem is that I have 3 lm34’s hooked up to it, so to see all 3 sensors I want it to show the first 2 sensors and their temps, wait 5 seconds, then clear the lcd and show the 3rd one on the first line. I also have this working, but because I am using delay functions, the temps are not updating in real time. I am also going to need to make this output to a buzzer/alarm to warn me when a temperature is too high. I am extremely new to arduino, as this is only my 2nd day trying to code this, and my code is probably extremely sloppy. I am assuming I need to use the millis() function instead of delay? and how exactly would I go about doing this? Any help on the alarm output would be nice as well. I’ll post my code and let you guys see what I’m talking about. I do plan on putting comments and stuff on the rest of my code lol this is just a rough sketch.

#include <serLCD.h>

#include <SoftwareSerial.h>

#define txPin 2

SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10;  // conservative, 2 actually works

// wbp: goto with row & column
void lcdPosition(int row, int col) {
  LCD.write(0xFE);   //command flag
  LCD.write((col + row*64 + 128));    //position 
  delay(LCDdelay);
}
void clearLCD(){
  LCD.write(0xFE);   //command flag
  LCD.write(0x01);   //clear command.
  delay(LCDdelay);
}
void backlightOn() {  //turns on the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(157);    //light level.
  delay(LCDdelay);
}
void backlightOff(){  //turns off the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(128);     //light level for off.
   delay(LCDdelay);
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  LCD.write(0xFE);
}

//declare variables
float tempF1;
float tempF2;
float tempF3;
int tempPin1= 0;
int tempPin2= 1;
int tempPin3= 2;



void setup()
{
  backlightOn();
  Serial.begin(9600);
  pinMode(txPin, OUTPUT);
  LCD.begin(9600);
   
 
}

void loop()
{
clearLCD();
  lcdPosition(0,0);
  LCD.print("Dish:");
  lcdPosition(0,11);
  LCD.print((char)223);
  lcdPosition(1,0);
  LCD.print("Direct:");
  lcdPosition(1,13);
  LCD.print((char)223);
  
  tempF1 = analogRead(tempPin1);           //read the value from the sensor
  tempF1 = (5.0 * tempF1 * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print("\n"); //new line
  Serial.print("Dish");
  Serial.print((float)tempF1);  //send the data to the computer
  Serial.print("\n"); //new line
  lcdPosition(0,6);
  LCD.print(tempF1);
                             //wait one second before sending new data

  tempF2 = analogRead(tempPin2);           //read the value from the sensor
  tempF2 = (5.0 * tempF2 * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print("\n"); //new line
  Serial.print("Direct:");
  Serial.print((float)tempF2);  //send the data to the computer
  Serial.print("\n"); //new line
  lcdPosition(1,8);
  LCD.print(tempF2);
  delay(5000);                           //wait one second before sending new data
  
  clearLCD();
  lcdPosition(0,0);
  LCD.print("Svr Room:");
  lcdPosition(0,15);
  LCD.print((char)223);
  
  tempF3 = analogRead(tempPin3);           //read the value from the sensor
  tempF3 = (5.0 * tempF3 * 100.0)/1024.0;  //convert the analog data to temperature
  Serial.print("\n"); //new line
  Serial.print("Svr Room:");
  Serial.print((float)tempF3);  //send the data to the computer
  Serial.print("\n"); //new line
  lcdPosition(0,10);
  LCD.print(tempF3);
  delay(5000);                           //wait one second before sending new data
  
}

Moderator edit:CODE TAGS

As is always said, look at the blink without delay example. For easier progress, adapt it to alternate between two different pages of LCD data, then extend it to do three.

and a link - http://arduino.cc/en/Tutorial/BlinkWithoutDelay -

that said:

void lcdPosition(int row, int col) {
  LCD.write(0xFE);   //command flag
  LCD.write((col + row*64 + 128));    //position 
  delay(LCDdelay);
}
void clearLCD(){
  LCD.write(0xFE);   //command flag
  LCD.write(0x01);   //clear command.
  delay(LCDdelay);
}
void backlightOn() {  //turns on the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(157);    //light level.
  delay(LCDdelay);
}
void backlightOff(){  //turns off the backlight
  LCD.write(0x7C);   //command flag for backlight stuff
  LCD.write(128);     //light level for off.
   delay(LCDdelay);
}

a small helper function can make LCD -life easier and decrease your code-base
==>

void lcdHelper(uint8_t a, uint8_t b)
{
  LCD.write(a);
  LCD.write(b);    
  delay(LCDdelay);
}

void lcdPosition(int row, int col) 
{
  lcdHelper(0xFE, col + row*64 + 128);
}
void clearLCD()
{
   lcdHelper(0xFE, 0x01); 
}
void backlightOn()
{  
   lcdHelper(0x7C, 157); // 157 = 0x9D
}
void backlightOff()
{
   lcdHelper(0x7C, 128); // 128 = 0x80
}

Thanks for the input guys, I'm going to read up on that example you linked and see if I can figure it out.