So I got a 1602A LCD successfully hooked up to an LM335Z temperature sensor and got it to update and display a temperature every half a second.
I'm trying to do the same with a DS18B20 sensor but the code is a little different and whenever the sensor is read and the LCD displays the temperature, it disappears almost instantly.
Where have I gone wrong in my code? How do I keep the temperature reading constantly display on the LCD until the next reading half a second later?
#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11 , 12); //declares what pins on the Arduino are used for the lcd
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
lcd.begin(16, 2); //sets up the number of columns and rows. For the 1602A-type LCD, there are 16 columns and 2 rows
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
void loop(void)
{
lcd.clear();
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Standby...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temperature for Device 1 is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
lcd.setCursor(0,0); // sets where to begin the LCD display
lcd.print("T1: ");
lcd.print(sensors.getTempCByIndex(0)); //display calculated value for celsius on LCD
lcd.print((char)223); //displays degrees symbol
lcd.print("C");
delay(500);
}