RGB Room Lamp With Clock

by perantesh2 in Circuits > Arduino

187 Views, 2 Favorites, 0 Comments

RGB Room Lamp With Clock

Regebe Clock / 11.06.2023 -Kerem Gül
Untitled design (4).png
u23.jpg
u22.jpg
u21.jpg
u20.jpg

I made a clock with rgb leds to experience colors in my room while can see the time.

Supplies

Arduino Nano

RTC Module

Breadboard

7 segment display

RGB Led strips

Powerbank / powersupply

Jumpers

u5.jpg
u4.jpg
u3.jpg
u2.jpg
u.jpg

Components

u7.jpg
u6.jpg

Connect the RTC and Display on Nano with breadboard. Make sure to connect the gnd pins with same line on nano, and make sure your data connections will be same on code section.

u11.jpg
u10.jpg
u9.jpg
u8.jpg

Connect the 2 part of leds while using Arduino as a bridge, black cables for ground make sure while using nano as bridge to connect same color of cables.

#include <Wire.h>
#include <RTClib.h>


RTC_DS1307 rtc;


// 7-Segment Display Connections
const int CLK_PIN = 2;
const int DIO_PIN = 3;


// RGB LED Strip Connections
const int RED_PIN = 6;
const int GREEN_PIN = 5;
const int BLUE_PIN = 4;


// Time Variables
DateTime now;


void setup() {
  Wire.begin();
  rtc.begin();
  
  // Set initial time (change this to the desired start time)
  rtc.adjust(DateTime(2023, 6, 11, 12, 0, 0));


  pinMode(CLK_PIN, OUTPUT);
  pinMode(DIO_PIN, OUTPUT);
  
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);
}


void loop() {
  now = rtc.now();
  
  // Update 7-segment display with current time
  displayTime(now.hour(), now.minute());


  // Change RGB LED strip color slowly
  changeLEDColor(now.second());
  
  delay(1000); // Wait for 1 second
}


// Function to display time on the 7-segment display
void displayTime(int hour, int minute) {
  int hour_tens = hour / 10;
  int hour_ones = hour % 10;
  int minute_tens = minute / 10;
  int minute_ones = minute % 10;
  
  displayDigit(hour_tens, 0);
  displayDigit(hour_ones, 1);
  displayDigit(minute_tens, 3);
  displayDigit(minute_ones, 4);
}


// Function to display a digit on the 7-segment display
void displayDigit(int digit, int position) {
  digitalWrite(CLK_PIN, LOW);
  digitalWrite(DIO_PIN, LOW);


  for (int i = 0; i < 8; i++) {
    digitalWrite(CLK_PIN, LOW);


    if (i == digit)
      digitalWrite(DIO_PIN, HIGH);
    else
      digitalWrite(DIO_PIN, LOW);
    
    digitalWrite(CLK_PIN, HIGH);
  }


  digitalWrite(CLK_PIN, LOW);
  digitalWrite(DIO_PIN, LOW);


  digitalWrite(CLK_PIN, HIGH);


  digitalWrite(CLK_PIN, LOW);
  digitalWrite(DIO_PIN, HIGH);


  digitalWrite(CLK_PIN, HIGH);
  
  digitalWrite(CLK_PIN, LOW);
  digitalWrite(DIO_PIN, LOW);
  
  digitalWrite(CLK_PIN, HIGH);
}


// Function to change the color of the RGB LED strip
void changeLEDColor(int second) {
  int redValue = map(second, 0, 59, 0, 255);
  int greenValue = map(second, 0, 59, 255, 0);
  int blueValue = map(second, 0, 59, 0, 255);
  
  analogWrite(RED_PIN, redValue);
  analogWrite(GREEN_PIN, greenValue);
  analogWrite(BLUE_PIN, blueValue);
}


This code assumes you have connected the RTC module, 7-segment display, and RGB LED strips to the Arduino Nano correctly. You will need to adjust the pin numbers based on your specific wiring.

The code initializes the RTC module in the setup() function and sets the initial time using rtc.adjust(). In the loop() function, it retrieves the current time from the RTC module and updates the 7-segment display accordingly. It also changes the color of the RGB LED strip slowly based on the current second value.

Make sure to include the required RTClib library in your Arduino sketch. You can install it using the Arduino Library Manager.

Please test the code and adjust it according to your specific hardware configuration and requirements.

u14.jpg
u15.jpg
u16.jpg
u17.jpg

After all connection put the breadboard carefully to the structure.