I have an Arduino UNO R3 and I am trying to set up a RTC DS1307 (with the I2C comm protocol) to take reading every 5 min of from a analog temp sensor. The RTC works perfectly! I am just unsure what commands I need to use to get the full potential out of the RTC.
Below is the current code I am using.
Thank you in advance for your help.
Code: Select all
// Date and time functions using just software, based on millis() & timer
#include <Wire.h>
#include "RTClib.h"
const int temp = 0;
const int LED = 13;
const int MIN = 0'
RTC_Millis RTC;
void setup ()
{
Serial.begin(9600);
pinMode(LED,OUTPUT);
RTC.begin(DateTime(__DATE__, __TIME__)); //sets the RTC to the date & time this sketch was compiled
}
void loop ()
{
float volt, degC;
int room, deadband, setpoint, degF, dispHour, dispDOW;
volt = getVoltage(temp);
degC = (volt - .5) * 100.0;
degF = degC * (9.0/5.0) + 32.0;
room = 70;
deadband = 5;
setpoint = room - deadband;
DateTime now = RTC.now();
dispHour = now.hour();
dispDOW = now.dayOfWeek();
if(now.minute == MIN
// RTD Day Of the Week
if(dispDOW == 0)
Serial.print("SUN: ");
if(dispDOW == 1)
Serial.print("MON: ");
if(dispDOW == 2)
Serial.print("TUE: ");
if(dispDOW == 3)
Serial.print("WED: ");
if(dispDOW == 4)
Serial.print("THU: ");
if(dispDOW == 5)
Serial.print("FRI: ");
if(dispDOW == 6)
Serial.print("SAT: ");
// RTD Date format D/M/TYYY
Serial.print(now.month());
Serial.print('/');
Serial.print(now.day());
Serial.print('/');
Serial.print(now.year() - 2000);
Serial.print(' ');
// RTC Time in 12 hour format with AM/PM
Serial.print((dispHour > 12) ? dispHour - 12 : ((dispHour == 12) ? 12 : dispHour));
Serial.print(":");
if (now.minute() < 10)
Serial.print("0");
Serial.print(now.minute());
Serial.print(':');
if (now.second() < 10)
Serial.print ("0");
Serial.print(now.second());
Serial.print((dispHour<12) ? " AM" : " PM");
Serial.println();
// Temp Display in Deg F
Serial.print(" Temp: "); // Temp will be in a format of
Serial.println(degF); // ##.#
delay(1000); // next step try to use the RTC to take readings every 5 min.
if (degF <= setpoint)
{
digitalWrite(LED,HIGH);
}
if (degF > room)
{
digitalWrite(LED,LOW);
}
}
float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
}