I am using a DS3231 with an LCD.. I converted the C temp to F, which seems to be working now. THe issue is that it is taking a full minute almost exactly for the temp to change after triggering it. And it only change a few degrees at a time.. then waits another minute and changes a little again until it gets where it needs to be. Any way t fix this or is this typical of the sensor in the DS3231?
#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
DS3231 rtc(SDA, SCL);
Time t;
#define buz 11
int Hor;
int Min;
int Sec;
int tempC;
int tempF;
int tempCDS3231;
int tempFDS3231;
void setup()
{
Wire.begin();
rtc.begin();
Serial.begin(9600);
pinMode(buz, OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
t = rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
}
void loop()
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.print(rtc.getTimeStr());
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(rtc.getDateStr());
lcd.setCursor(0,1);
tempFDS3231 = (tempCDS3231 * 1.8) + 32.0; // Convert C to F
tempCDS3231 = (rtc.getTemp());
lcd.setCursor(0,1);
lcd.print(tempFDS3231);
lcd.print(" F ");
lcd.print(rtc.getDateStr());
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(01, 33, 00); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(23, 8, 2018); // Set the date to August 8th, 2018
}
The update rate is every 64 seconds, it’s documented in the datasheet.
Also in the datasheet is an explanation why you can read a temperature from a real time clock chip. Curious? That temperature is part of a compensation scheme to make the clock more accurate. It’s the internal temperature of the integrated circuit, not the outside air temperature which is why it doesn’t appear very responsive. BTW, the temperature accuracy is a rather poor +/-3 degrees C.
If you want a better air temperature sensor, a thermistor, DS18B20 or LM35 are common solutions.
Thank you for your response. That's exactly what I needed to know. I mainly don't mind the delay, I just wanted to make sure that the delay didn't have to do with something in my code. Yes I have a thermistor which is highly responsive, but it shows up with a temperature that has two decimal places, which takes up too much room on the LCD for what im doing.. Know of a way to rid the extra decimals? Here is the code im using for that sensor..
/*
Name: Christopher Steele
Date: 8/26/2018
Project: Use DS3231 RTC to print Time, Temp, Date on LCD screen, Sound time Alarm
*/
//----------------------------------------------------------------
// Define variables.
#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
DS3231 rtc(SDA, SCL);
Time t;
#define buz 11
int tempPin = 0;
int Hor;
int Min;
int Sec;
int tempC;
int tempF;
int tempCDS3231;
int tempFDS3231;
//-----------------------------------------------------------------
// Used to fix Date, Time, Day of Week
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(01, 33, 00); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(23, 8, 2018); // Set the date to August 8th, 2018
//------------------------------------------------------------------
void setup()
{
Wire.begin();
rtc.begin();
Serial.begin(9600);
pinMode(buz, OUTPUT);
lcd.begin(16,2);
lcd.setCursor(0,0);
t = rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
}
//---------------------------------------------------------------------
void loop()
{
int tempReading = analogRead(tempPin);
// This is OK
double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
lcd.setCursor(0,0); //Top line of the LCD
lcd.print(" ");
lcd.print(rtc.getTimeStr());
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(rtc.getDateStr());
//----------------------------------------------------------
lcd.setCursor(0,1); //Second line of the LCD
tempFDS3231 = (tempCDS3231 * 1.8) + 32.0; // Convert C to F
tempCDS3231 = (rtc.getTemp());
lcd.setCursor(0,1);
lcd.print(tempF);
lcd.print((char)223); //This creates a Degree symbol
lcd.print("F ");
lcd.print(rtc.getDateStr());
//--------------------------------------------------------------------------
t = rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
if( Hor == 21 && (Min == 38 || Min == 15)) //Comparing the current time with the Alarm time
{
Buzzer();
Buzzer();
lcd.clear();
lcd.print("Alarm ON");
lcd.setCursor(0,1);
lcd.print("Wake Up!!");
Buzzer();
Buzzer();
}
delay(1000);
}
void Buzzer()
{
digitalWrite(buz,HIGH);
delay(500);
digitalWrite(buz, LOW);
delay(500);
}
CSteele:
Yes I have a thermistor which is highly responsive, but it shows up with a temperature that has two decimal places, which takes up too much room on the LCD for what im doing..
lcd.print(tempF, 1); // print with one decimal place
lcd.print(tempF, 0); // print without decimal place