Switching between 4 DS18B20 temp. sensors and displaying on LCD key pad shield

Hello,

I am working on my first Arduino project and it's going relatively well, just need a bit of help with the programming end. I am stoked to be a part of the community and can't wait to get involved more.

I am monitoring automotive fuel temperatures at four different locations using daisy chained DS18B20's and custom made thermowells. I am using an Arduino UNO with a basic 16x2 LCD key pad shield to output the four temps. in the cab of my truck.

I have successfully been able to, thanks to some code online, show two temperatures and then after a delay show the last two. This was a feat for me but ideally I would like to use the buttons on the key pad shield to switch between the two sets of temps.

This is what I have so far:

// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

// Connections:
// rs (LCD pin 4) to Arduino pin 8
// rw (LCD pin 5) to Arduino pin 11
// enable (LCD pin 6) to Arduino pin 9
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 4, 5, 6, 7
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int d=1000;
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

int read_LCD_buttons()
{
 adc_key_in = analogRead(0);      // read the value from the sensor
 // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
 // we add approx 50 to those values and check to see if we are close
 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 if (adc_key_in < 50)   return btnRIGHT; 
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;  
 return btnNONE;  // when all others fail, return this...
}

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress Therm1 = { 0x28, 0x00, 0xFA, 0xAA, 0x03, 0x00, 0x00, 0x53 };//Pin 1-Black, 2-Red,3-White
DeviceAddress Therm2 = { 0x28, 0x78, 0x5A, 0x4B, 0x04, 0x00, 0x00, 0xE5 };//1-Green, 2-Black, 3-White
DeviceAddress Therm3 = { 0x28, 0x90, 0x51, 0x4B, 0x04, 0x00, 0x00, 0x1D };//1-Green, 2-Black, 3-White
DeviceAddress Therm4 = { 0x28, 0x17, 0x2D, 0x4B, 0x04, 0x00, 0x00, 0x3E };//1-Green, 2-Black, 3-White

void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Therm1, 10);
sensors.setResolution(Therm2, 10);
sensors.setResolution(Therm3, 10);
sensors.setResolution(Therm4, 10);

//analogWrite(10, 255); // set brightness on pin 10 to 0-255
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.print("Push one fool"); // start with a blank screen
}

void printTemperature(DeviceAddress deviceAddress)
{
double tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
} else {
lcd.print(tempC);

}
}

void loop(void)
{
lcd_key = read_LCD_buttons();  // read the buttons
 switch (lcd_key)               // depending on which button was pushed, we perform an action
 {
   case btnUP:
     {
     delay(500);
     sensors.requestTemperatures();
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Temp1: ");
     printTemperature(Therm1);
     lcd.setCursor(0,1);
     lcd.print("   Temp2  : ");
     printTemperature(Therm2);
     break;
     }
   case btnDOWN:
     {
     delay(500);
     lcd.clear();
     sensors.requestTemperatures();
     lcd.setCursor(0,0);
     lcd.print("Temp3:");
     printTemperature(Therm3);
     lcd.setCursor(0,1);
     lcd.print("Temp4:");
     printTemperature(Therm4);
     break;
     }
 
 }
}

This actually does what I want it to do except that I am worried it's not going to keep updating my temperatures (all 4). Will it become stuck on getting the temperatures only once? Do I need to change up the code completely? Not sure if this is even the best way to go about what I want to do.

Any help would be greatly appreciated.

Thanks

You've got the right approach, it seems. Since it is in the cab, you might consider using identifying lables, yes, pen and sticky paper and display all four temps simultaneously. DS18B20 returns six digits at most, so it just a case of setting the cursor for each. No need for any buttons.

The Hacktronics programme just reads and prints, reads and prints, then goes round for another session. If you are doing that in the loop, which you are, nothing is going to get stuck. I think your concern is because, at the moment, your action in the loop is dependant on a button being pushed.

You can dispense with the either/or streams and subtitute a delay (1000); , and it will update all sensors every second.

If you can't find pen and paper, another possibility is to read and display two, delay 1 sec, then read and display the other two. Again, no buttons needed.

If the sensors return 6 digits at most why not just display all 4 temperatures at the same time with shorter labels, perhaps (1):, (2): etc ? No need to fumble for the correct button to push whilst driving then. How much accuracy do you need anyway ? If you removed the decimal part of the temperature, rounding the whole part if necessary, you could still get the full labels on the screen with 4 temperatures.

As it stands at the moment the display will only update when you hold down the up or down button. Is that what you want ?

Hello brokespokes,
I want to do something similar to your setup but instead of measuring fuel REFRIGERANT want to measure temperatures of the diesel engine in multiple sites: radiator, cylinder head, thermostat, etc..
I thought I could serve what you already have done.
Please, you can report how it went?
I want to mount it on my Classic California 1995 Volkswagen van.
I use to write an online translator, please forgive my mistakes because Inles is not my language.
Greetings and thanks.

Hola brokespokes,
Yo quiero hacer algo parecido a tu montaje, pero en vez de medir combustible yo quiero medir temperaturas del regrigerante del motor diesel en varios sitios: radiador, culatas, termostato, etc.
Yo he pensado que me podría servir lo que tu ya tienes hecho.
Por favor, tu puedes informar de cómo te fue?
Yo quiero montarlo en mi furgoneta clásica Volkswagen California del 1995.
Yo uso para escribir un traductor en línea, por favor, perdona mis errores porque el inlés no es mi idioma.
Saludos y gracias.