Arduino Nano and DS3231 led function problems

*// time repeat alarms to control led
#include <RTClib.h>
#include <TimeLib.h>
#include <TimeAlarms.h>
#include <Wire.h>
#include <DS3231.h> // a basic DS3231 library that returns time as a time_t
RTC_DS3231 rtc;

const int led = 4 //Sets pin 4 as led

void setup() {
// wait for Arduino Serial Monitor
while (!Serial) ;
setSyncProvider(getExternalTime()); // the function to get the time from the RTC
if (timeStatus()!= timeSet)
Serial.println("Unable to sync with the RTC");
Serial.println("RTC has set the system time");

// create the alarms, to trigger functions at specific times
Alarm.alarmRepeat(5,30,0,MorningAlarm); // 5:30am every day
Alarm.alarmRepeat(21,30,0,EveningAlarm); // 21:30 -> 9:30 pm every day

void loop() {
// wait one second between each clock display in serial monitor

// functions to be called when an alarm triggers
void EveningAlarm() {
// write here the task to perform every morning
Serial.println("Tturn light on");
digitalWrite(led, HIGH);
void MorningAlarm() {
// write here the task to perform every evening
Serial.println("Turn light off");
digitalWrite(led, LOW);

You have to state what you are trying to do , what’s not working and any errors you are getting ?

Turn an LED on at 21:30 (9:30 pm) and turn it off at 5:30 a.m.
The problem is the DS3231 knows the time but the alarm repeats do not turn the led on. I am using an Arduino Nano and do I have to include a statement about A4 SDL and A5 SCL?

Read the forum guidelines. Post your test code in code tags. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.

A pin must be set to OUTPUT with the pinMode() function before you can use it to turn a LED on and off.

Thank you, I made the call out per your insight and it worked but only after I got rid of the alarm repeat commands and just looked for a specific time, once it found that time, I set the delay for eight hours. Now it works well enough.
Now that it is finished, I will toy with it some more so I can develop a better understanding of these amazing circuits.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.