RTC and LED with days of the week

Im making a project that has 7 LEDs. The first one turns on on Monday, second on Tuesday, third on Wednesday, and so on. I already have some RTC code up and running. On the serial monitor, it shows the day of the week. How do I use this to make my LED light up at the right time?
Here is my code Im currently using to find day of the week, date, and time:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
void setup () {
while (!Serial); // for Leonardo/Micro/Zero
Serial.begin(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
rtc.adjust(DateTime(F(DATE), F(TIME)));
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
//rtc.adjust(DateTime(F(DATE), F(TIME)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}

}
void loop () {
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}

Thanks you!!

Just after the now.day serial print put in code to turn the correct LED on and the previous one off.

Can you explain a bit more? There are 7 LEDs. Which one should I turn on and turn off?

Serial.println(now.dayOfTheWeek());

Do you understand what the above will print to the serial monitor?

Try it to see.

Which one should I turn on and turn off?

You first turn all of them off. Then you immediately turn on the one that is given to you by the daysOfTheWeek[now.dayOfTheWeek()] variable.

byte ledToTurnnOn = daysOfTheWeek[now.dayOfTheWeek()];

Use an if statement with that variable for each LED to see what pin to do a digitalWrite to.

Grumpy_Mike:
You first turn all of them off. Then you immediately turn on the one that is given to you by the daysOfTheWeek[now.dayOfTheWeek()] variable.

byte ledToTurnnOn = daysOfTheWeek[now.dayOfTheWeek()];

Use an if statement with that variable for each LED to see what pin to do a digitalWrite to.

Yes but how will the Arduino know which LED is for Sunday, or any day of the week for that matter?
Thank you for your help so far!

larryd:
Serial.println(now.dayOfTheWeek());

Do you understand what the above will print to the serial monitor?

Try it to see.

Yes. It is working, although it resets to the time the code was compiled each time it is unplugged. But it shows the right date, year, and time

it resets to the time the code was compiled each time it is unplugged.

Compile and load your code and the rtc will be set to the compile time.

Then comment out this line and recompile and load the code. Then it will not reset to compile time each time the code restarts/

//comment out this line after the first time it runs.
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

but how will the Arduino know which LED is for Sunday,

You tell it in your code.
The now.dayOfTheWeek() returns a number, print it out and see. The daysOfTheWeek is a string array that returns the day of the week. Which is why daysOfTheWeek[now.dayOfTheWeek()] returns a string to print out.

So you make an array that has the LED pins you need to turn on for each day of the week and index it with your now.dayOfTheWeek() variable to turn on the right LED.

Or if that is too advanced just use a bunch of if statements on your day of the week number.

Okay... I’ll try it. Thank you! :slight_smile:

Grumpy_Mike:
You tell it in your code.
The now.dayOfTheWeek() returns a number, print it out and see. The daysOfTheWeek is a string array that returns the day of the week. Which is why daysOfTheWeek[now.dayOfTheWeek()] returns a string to print out.

So you make an array that has the LED pins you need to turn on for each day of the week and index it with your now.dayOfTheWeek() variable to turn on the right LED.

Or if that is too advanced just use a bunch of if statements on your day of the week number.

I will probably have to use the if statements. But Im afraid that might take up the memory space. Is it possible for you to explain what you mean by indexing the variable into the array or give me some resources to figure it out?

Thank you in advance!

But Im afraid that might take up the memory space

That is program memory and you have loads of that free.

Is it possible for you to explain what you mean by indexing the variable into the array

It is exactly what

Serial.print(daysOfTheWeek[now.dayOfTheWeek()];

Does.
Here is a little thing I wrote some time ago about arrays.
http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

You make an array with the PIN numbers of each of the seven LEDs you want to light up in turn.
Let’s say you have done that and called it imaginatively LEDs. Then you simply do

digitalWrite(LEDs[now.dayOfTheWeek()], HIGH);

For the correct LED to be turned on.

Try it and post what you have done if it doesn’t work.

Thank you! I will try to test this weekend. I will post the code anyways if you still have suggestions. I also need a buzzer to ring at a certain time everyday so, if that is in the code, thats why.

Thank you for all your help!