Running an Uno with Adafruit WiFi shield, 20x4 LCD display (on I2C), a single DHT22 and two DS18B20 probes.
The DHT22 is for room temp/humidity and the two DS18B20 probes go in the refrigerator and freezer respectively.
DHT22 is on pin 2 and the DS18B20s are on pin 7.
Everything works great until the probe in the freezer goes below 4.1°F. At that point that particular probe just returns the value -196.60°F until the temp rises to 4.1 or greater again.
I tried physically swapping the probes to eliminate hardware issues, and no change. Whichever probe is in the freezer gives the -196.60 value below 4.1°F
Both DS18B20 probes are wired together, and I've tried 4.7k and 2.2k pullup resistors (+5VDC to data).
I'm using the DallasTemperature and OneWire libraries for the DS18B20.
The specs of the DS18B20 are -55°C to +125°C (-67°F to +257°F) which is well within the range of a freezer.
I'm hoping this is some strange math issue. Let me know if you have any ideas. My code is below. I've removed unrelated sections because the whole thing wouldn't fit.
Thanks!
#include <Adafruit_CC3000.h> // WiFi stuff
#include <SPI.h>
#include "utility/debug.h"
#include "utility/socket.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //LCD
#include <OneWire.h>
#include <DallasTemperature.h> //Temp Probes
#include <DHT.h> // DHT Temp
#define ONE_WIRE_BUS 7 // Pin for Temp Probes
#define I2C_ADDR 0x27 //Address for LCD
#define BACKLIGHT_PIN 3 //LCD Don't need this but code breaks without it
#define En_pin 2 // LCD
#define Rw_pin 1 // LCD
#define Rs_pin 0 // LCD
#define D4_pin 4 // LCD
#define D5_pin 5 // LCD
#define D6_pin 6 // LCD
#define D7_pin 7 // LCD
#define DHTPIN 2 // DHT Pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DHT dht(DHTPIN, DHTTYPE);
float probeAF; // floating pt variables for probes in F and C
float probeAC;
float probeBF;
float probeBC;
float dhtTF; // DHT Temp in F
float dhtDP; // DHT DP in C
float dhtDPF; // DHT DP in F
void setup()
{
sensors.begin();
dht.begin();
lcd.begin(20,4); // initialize the lcd
lcd.clear();
lcd.home ();
lcd.print("Room: |REF: "); //Line 0 Base Text
lcd.setCursor (0, 1);
lcd.print ("T: |FRZ: "); //Line 1 Base Text
lcd.setCursor(0,2);
lcd.print("DP: |"); //Line 2 Base Text
lcd.setCursor(9,3);
lcd.print("|"); //Line 3 Base Text
}
void loop()
{
sensors.requestTemperatures(); // Send the command to get PROBE temperatures
float h = dht.readHumidity();
float t = dht.readTemperature();
delay(1000);
dhtTF = ((t*9)/5)+32;
dhtDP = (dewPointFast(t, h));
dhtDPF= ((dhtDP*9)/5)+32;
probeAC = (sensors.getTempCByIndex(0)); // Get 1st probe temp
probeBC = (sensors.getTempCByIndex(1)); // Get 2nd probe temp
probeAF = probeAC * 1.8 + 32.0;
probeBF = probeBC * 1.8 + 32.0;
lcd.setCursor(15,0);
lcd.print(probeBF); // Refrigerator Temp
lcd.setCursor(19,0);
lcd.print(char(223));// Degree Symbol
lcd.setCursor(15,1);
lcd.print(probeAF); // Freezer Temp
lcd.setCursor(19,1);
lcd.print(char(223));
lcd.setCursor(3,1); // Room Temp and DP
lcd.print(dhtTF);
lcd.setCursor(8,1);
lcd.print(char(223));
lcd.setCursor(3,2);
lcd.print(dhtDPF);
lcd.setCursor(8,2);
lcd.print(char(223));
}
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
double Td = (b * temp) / (a - temp);
return Td;
}