Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
RobotGeek TeamWade Filewich
Published © CC0

Using a Real Time Clock With Arduino

Ever wanted to make a project that activated on a schedule? Using a Real Time Clock (RTC) is a great way to do it!

BeginnerProtip15 minutes11,924
Using a Real Time Clock With Arduino

Things used in this project

Hardware components

RobotGeek Geekduino
RobotGeek Geekduino
×1
RobotGeek Sensor Shield
RobotGeek Sensor Shield
×1
RobotGeek Duino Mount
×1
RobotGeek Large Workbench
×1
Grove 4 Pin Connector to Female Jumper Wire Cable 20cm (5 pack)
×1
RobotGeek 2-Pin Coupler
×1
RobotGeek Relay
RobotGeek Relay
×1
RobotGeek 6V/2A Power Supply
×1
Seeed Studio Grove RTC
×1
Arduino UNO
Arduino UNO
OPTION: Can be used in place of Geekduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code snippet #2

Plain text
void setup()
{
	Serial.begin(9600);
	clock.begin();
	clock.fillByYMD(2013,1,19);//Jan 19,2013
	clock.fillByHMS(15,28,30);//15:28 30"
	clock.fillDayOfWeek(SAT);//Saturday
	clock.setTime();//write time to the RTC chip
}

Code snippet #3

Plain text
MON
TUE
WED
THU
FRI
SAT
SUN

Code snippet #5

Plain text
  switch (clock.second)
  {
    case 30: //when the clock reads 30 seconds (Once a minute at the halfway mark)
      digitalWrite(RELAY, HIGH);   // turn the Relay on (HIGH is the voltage level)
      delay(1000);              // wait for 1 second
      digitalWrite(RELAY, LOW);    // turn the Relay off by making the voltage LOW
      delay(1000);              // wait for 1 second
  }

Code snippet #6

Plain text
  switch (clock.dayOfWeek)
  {
    case MON: //on Monday
      switch (clock.hour)
      {
        case 14: //at 2 o'clock
          switch (clock.minute)
          {
            case 30: //at 30 minutes
              switch (clock.second)
              {
                case 1: //at 1 second
                  digitalWrite(RELAY, HIGH);   // turn the Relay on (HIGH is the voltage level)
                  delay(5000);              // wait for 5 seconds
                  digitalWrite(RELAY, LOW);    // turn the Relay off by making the voltage LOW
                  delay(5000);              // wait for 5 seconds
              }
          }
      }
  }

Github file

https://github.com/robotgeek/robotGeekLibrariesAndtools/archive/master.zip

Credits

RobotGeek Team

RobotGeek Team

35 projects • 208 followers
The RobotGeek team is a 6-man operation that wants to make it even easier to use Arduino to make electronics and robots.
Wade Filewich

Wade Filewich

35 projects • 103 followers
I make technology that makes plants grow

Comments