Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO with DS1307 RTC Controlled LED Lighting System

View and Edit Project In Cirkit DesignerImage of Arduino UNO with DS1307 RTC Controlled LED Lighting System

Circuit Documentation

Summary

The circuit in question is designed to interface an Arduino UNO with a DS1307 Real-Time Clock (RTC) module and control an LED based on the time provided by the RTC. The LED is connected through a 330-ohm resistor to limit the current. The RTC communicates with the Arduino via the I2C protocol, using the SDA and SCL lines. The LED is controlled by a digital output pin on the Arduino and is turned on or off depending on the time of day.

Component List

Arduino UNO

DS1307 RTC (Wokwi Compatible)

LED: Two Pin (red)

Resistor

Wiring Details

Arduino UNO

DS1307 RTC (Wokwi Compatible)

LED: Two Pin (red)

Resistor

Documented Code

#include <Wire.h>
#include <RTClib.h>  // Ensure this is the RTCLib by NeiroN

RTC_DS1307 rtc;

const int lightPin = 8;  // Pin connected to the LED or relay

void setup() {
  Serial.begin(9600);
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  
  if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running, setting the time...");
    // Uncomment the following line to set the RTC to the time the sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  pinMode(lightPin, OUTPUT);
  digitalWrite(lightPin, LOW);  // Start with light off
}

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

  int currentHour = now.hour();
  int currentMinute = now.minute();

  // Check if the current time is between 11:00 AM and 11:43 AM
  if ((currentHour == 11) && (currentMinute >= 0 && currentMinute <= 43)) {
    digitalWrite(lightPin, HIGH);  // Turn on the light
    Serial.println("Light ON");
  } else {
    digitalWrite(lightPin, LOW);   // Turn off the light
    Serial.println("Light OFF");
  }

  delay(1000);  // Check every second
}

Filename: sketch.ino

Description: This code initializes the RTC and sets the current time if the RTC is not running. It then enters a loop where it checks the current time and turns on an LED connected to pin D8 of the Arduino if the time is between 11:00 AM and 11:43 AM. The LED is turned off outside of this time window. The status of the LED is printed to the serial monitor every second.