I have been working on a program to view multiple different temperatures (DHT22 and Dallas DS18B20) from each individual sensor on a SainSmart LCD shield with an Arduino Uno board. My problem is that while I can toggle to view each sensor individually on my LCD, the first displayed temp freezes on the screen. For example: On start up, LCD displays first sensor reading "75" degrees. This is correct, however, I can heat the sensor up or cool it down and the number on the screen will not change. Unless, while the temperature is rising, I press any button on my LCD shield. Upon pressing a button, the temperature updates on the LCD screen... but it will freeze with that number until I press another button.
I am using a DHT22 Temp/Humid sensor along with a few serialized Dallas DS18B20 temperature sensors. I am having the problem with all the sensors, not just one. I have removed any and all unnecessary code lines that could be causing the issue with no change. Could this be that my board is getting overwhelmed or under powered? I am also having some lag while toggling, but it's nowhere near as significant. This should be an easy fix for a master programmer, but I'm still quite new to Arduino and I'm still learning all the tricks.
side note: while the Serial Monitor will display both Fahrenheit and Celsius temperatures consistently with no issues, I cannot get the Dallas sensors to display a simple Fahrenheit number instead of a Celsius decimal number. Any tips with that bit of code would really help!
Here's most of the code due to length restriction...
#include <LiquidCrystal.h> //LCD Screen
#include <DFR_Key.h> //LCD Keypad
#include "DHT.h"
#include <OneWire.h> //one wire input sensors
#include <DallasTemperature.h> //Dallas 1 wire DS18B20
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DFR_Key keypad;
#define DHTTYPE DHT22 // DHT 22 (AM2302)
int sensePin = 11; //Sensor input pin for the DHT22 sensor to control CHANNEL3
int currentButton = 0; //Current button pressed
int currentDisplay = 0;////Keeps track of what screen is currently being displayed. 0 = temp, 1 = humidity, 3 = Watering.
int displayTemp = 1; //Keeps track of what screen is currently being displayed. If displayTemp is 1 temp is showing. If 0 Humidity is showing.
int displayHumid = 0;
int waterDisplay = 0;//NEW SCREEN 1 = Inside or outside water temp display
int sensorsDisplay = 0;//NEW SCREEN 2 = Display for both, inside and outside water temps
int setTemp = 75; //Default to set the desired temp
int setHumid = 50; //Defualt to set the desired humidity
//int outputPin = 3; //Output pin to the relay to trip the fans with PowerTail
int displayInsideTemp = 0; //Dallas sensor 1
int displayOutsideTemp = 0; //Dallas sensor 2
int waterSetTemp = 140;
DHT dht(sensePin, DHTTYPE);
// 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);
DeviceAddress inside = { 0x28, 0xB3, 0x58, 0x66, 0x04, 0x00, 0x00, 0xEC };
DeviceAddress outside = { 0x28, 0x12, 0x31, 0x66, 0x04, 0x00, 0x00, 0x65 };
DeviceAddress waterTank = { 0x28, 0x3E, 0x43, 0x66, 0x04, 0x00, 0x00, 0x40 };
void setup()
{
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
dht.begin();
sensors.begin();
// set the resolution to 10 bit (good enough?)
// sensors.setResolution(inside, 10);
// sensors.setResolution(outside, 10);
float InsideTempC = sensors.getTempC(inside);
float OutsideTempC = sensors.getTempC(outside);
float waterTankTempC = sensors.getTempC(waterTank);
pinMode(CHANNEL1, OUTPUT);// House Duct fan
pinMode(CHANNEL2, OUTPUT);// Furnace Water Pump
pinMode(CHANNEL3, OUTPUT);// Solar Water Heater
}
void printTemperature(DeviceAddress deviceAddress)
{
double tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
} else {
lcd.print(tempC);
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop() {
currentButton = keypad.getKey();//Read Button Press
if (currentButton >= 0) // Makes the buttons respond faster. If no button is pressed it skips all the code and loops until button is pressed.
{
float h = dht.readHumidity();
float t = dht.readTemperature();
float insideTempC = sensors.getTempC(inside);
float outsideTempC = sensors.getTempC(outside);
float waterTankTempC = sensors.getTempC(waterTank);
float temp = (t * 1.8) + 32; //Convert *C to *F.
float wata = (insideTempC * 1.8) + 32; //Convert *C to *F.
float owside = (outsideTempC * 1.8) + 32; //Convert *C to *F.
if (displayTemp == 1) //Shows DHT22 SENSOR temp screen upon first boot
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ROOM ");
lcd.print(int(temp));
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
lcd.setCursor(0,1);
lcd.print("SET TEMP ");
lcd.print(setTemp);
lcd.print("");
lcd.print((char)223);
lcd.print("F");
currentDisplay = 0;
}
if (displayHumid == 1)// DHT22 SENSOR
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("HUMIDITY ");
lcd.print(int(h));
lcd.print(" %");
lcd.setCursor(0,1);
lcd.print("SET HUMID ");
lcd.print(setHumid);
lcd.print(" %");
currentDisplay = 1;
}
if (waterDisplay == 1)
{
sensors.requestTemperatures(); //This command must be there in order to get live stream of temperature data
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("inside WATER ");
printTemperature(inside);
lcd.print("");
lcd.print((char)223); // degree symbol
//lcd.print("F");
lcd.setCursor(0,1);
lcd.print("SET TEMP ");
lcd.print(waterSetTemp);
lcd.print("");
lcd.print((char)223);
lcd.print("F");
currentDisplay = 2;
}
if ( sensorsDisplay == 1)
{
sensors.requestTemperatures();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("inside: ");
printTemperature(inside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
lcd.setCursor(0,1);
lcd.print("outside: ");
printTemperature(outside);
lcd.print("");
lcd.print((char)223); // degree symbol
lcd.print("F");
currentDisplay = 3;
}
//MENU SYSTEM
if (currentButton == 5 && currentDisplay == 0)//Turns display temp off so it will show humidity after pressing right button
{
displayHumid = 1;
displayTemp = 0;
waterDisplay = 0;
sensorsDisplay = 0;
}
if (currentButton == 5 && currentDisplay == 1) //Inside Water Display
{
waterDisplay = 1;
sensorsDisplay = 0;
displayHumid = 0;
displayTemp = 0;
}
if (currentButton == 5 && currentDisplay == 2)
{
sensorsDisplay = 1;
displayTemp = 0;
waterDisplay = 0;
displayHumid = 0;
}
if (currentButton == 5 && currentDisplay == 3)
{
displayTemp = 1;
waterDisplay = 0;
displayHumid = 0;
sensorsDisplay = 0;
}
}