i want to code to make output trigger every hour using rtc and arduino can any one help me
Your topic was moved to its current location as it is more suitable.
Could you also take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Thank you
First decide which RTC your going to use.
Then look for an Arduino library for that RTC.
The Arduino libraries for most RTCs will contain examples of how to read and use the RTCs.
type
rtc ds3231
Hello, related datasheet to examine: DS3231.
E.g. with DS3232RTC library tutorial:
Don't forget to disable square wave output, so INT/SQW output is asserted when alarm occures.
Are you using RTC module breakout?

Because if not, you also need external pullup resistor on INT/SQW pin (it is most probably already applied on the board). From datasheet:
can you help me with sketch
You can start here...
RTClib/DS3231_alarm.ino at master · adafruit/RTClib · GitHub
Or Google: "RTC alarm arduino"
CODE NOT WORKINNG CAN ANY ONE HELP ME
// Hardware:
// Arduino Uno, DS3231 RTC.
// Connect RTC SDA to Arduino pin A4.
// Connect RTC SCL to Arduino pin A5.
//
// Jack Christensen 16Sep2017
#include <DS3232RTC.h> // https://github.com/JChristensen/DS3232RTC
#include <Streaming.h> // https://github.com/janelia-arduino/Streaming
#define LED_PIN 11
DS3232RTC myRTC;
void setup()
{
Serial.begin(115200);
// initialize the alarms to known values, clear the alarm flags, clear the alarm interrupt flags
myRTC.begin();
myRTC.setAlarm(DS3232RTC::ALM1_MATCH_DATE, 0, 0, 0, 1);
myRTC.setAlarm(DS3232RTC::ALM2_MATCH_DATE, 0, 0, 0, 1);
myRTC.alarm(DS3232RTC::ALARM_1);
myRTC.alarm(DS3232RTC::ALARM_2);
myRTC.alarmInterrupt(DS3232RTC::ALARM_1, false);
myRTC.alarmInterrupt(DS3232RTC::ALARM_2, false);
myRTC.squareWave(DS3232RTC::SQWAVE_NONE);
// set the RTC time and date to the compile time
myRTC.set(compileTime());
myRTC.setAlarm(DS3232RTC::ALM1_MATCH_MINUTES, 0, 0, 0, 1);
// clear the alarm flag
myRTC.alarm(DS3232RTC::ALARM_1);
Serial << millis() << " Start ";
printDateTime(myRTC.get());
Serial << endl;
}
void loop()
{
if ( myRTC.alarm(DS3232RTC::ALARM_1) ) { // check alarm flag, clear it if set
Serial << millis() << " ALARM_1 ";
digitalWrite(LED_PIN, HIGH);
delay(5000);
digitalWrite(LED_PIN, LOW);
printDateTime(myRTC.get());
Serial << endl;
}
if ( myRTC.alarm(DS3232RTC::ALARM_2) ) { // check alarm flag, clear it if set
Serial << millis() << " ALARM_2 ";
printDateTime(myRTC.get());
Serial << endl;
}
delay(100); // no need to bombard the RTC continuously
}
void printDateTime(time_t t)
{
Serial << ((day(t)<10) ? "0" : "") << _DEC(day(t));
Serial << monthShortStr(month(t)) << _DEC(year(t)) << ' ';
Serial << ((hour(t)<10) ? "0" : "") << _DEC(hour(t)) << ':';
Serial << ((minute(t)<10) ? "0" : "") << _DEC(minute(t)) << ':';
Serial << ((second(t)<10) ? "0" : "") << _DEC(second(t));
}
// function to return the compile date and time as a time_t value
time_t compileTime()
{
const time_t FUDGE(10); //fudge factor to allow for upload time, etc. (seconds, YMMV)
const char *compDate = __DATE__, *compTime = __TIME__, *months = "JanFebMarAprMayJunJulAugSepOctNovDec";
char compMon[4], *m;
strncpy(compMon, compDate, 3);
compMon[3] = '\0';
m = strstr(months, compMon);
tmElements_t tm;
tm.Month = ((m - months) / 3 + 1);
tm.Day = atoi(compDate + 4);
tm.Year = atoi(compDate + 7) - 1970;
tm.Hour = atoi(compTime);
tm.Minute = atoi(compTime + 3);
tm.Second = atoi(compTime + 6);
time_t t = makeTime(tm);
return t + FUDGE; //add fudge factor to allow for compile time
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
