Get Temperature from RTC DS3231/DS3232 Using Arduino

RTC DS3231/DS3232 has additional feature to get temperature instead of its main feature, get precision time data. However, the temperature data in RTC DS3231/DS3232 will only update every 64 seconds in its sampling rate. But okay, at least every 1 minute you will get temperature data that can be utilized for a variety of needs.

Arduino - RTC DS3231/3232 Circuit

First, wiring prototype circuit as follows:

Arduino - RTC DS3231/3232 Sketch Handler

Get temperature data from RTC DS3231/DS3232 using Arduino is pretty easy. You only need to declare a library 'DS3232RTC.h' (you can download here), and calling one of its functions, namely:

RTC.temperature ();

If you look at the library's datasheet, the function above would return a value of temperatures multiplied by four times. Thus, you must divide the result of RTC.temperature call function with a value of 4 that shows actual temperature value. The Arduino script is as follows:

float c = RTC.temperature () / 4;

Next, you should show data acquisition in Serial Monitor window to monitor temperature (debugging) with this script:

       Serial.print ( "Temperature =");
   Serial.print (c);
   Serial.println ( "C");

For more details, please copy and paste the following sketch in your Arduino IDE:

#include <DS3232RTC.h>
#include <Time.h> 
#include <Wire.h>

void setup() {
if (timeStatus() != timeSet) Serial.println("RTC fail");
else Serial.println("RTC sync"); 

void loop() {
static time_t tLast;
time_t t;
t = now();
if (t != tLast) {
tLast = t;

Serial.print(" ");
Serial.print(" - "); 
float c = RTC.temperature()/4.;
Serial.print("Suhu = "); 
Serial.println(" C "); 


Upload Arduino sketch above, and see the results in Serial Monitor window. Supposedly the result will be:

Easy enough, right? By utilizing the internal temperature sensor on the RTC DS3231 / DS3232 can obtain temperature data instantly without adding sensors. Thus it can save your budget and PCB layout space.
Next Post »