RTC-controlled LED Strips

Hello! I'm a beginner in arduino and I really tried my best to do it on my own, but I'm running out of my own wits so I really need to ask for help now.

So basically my project is to build a lamp that changes its color depending on the time. So I made it rtc-controlled. I think I may be having code problems, or missed out connections but I am not sure where. I really don't know where I made a mistake so I am now asking. This is currently my breadboard and my code.

It would really mean a lot for me to get help in this. Thank you in advance and I truly appreciate it.

I am using Arduino Uno, a couple of N-type MOSFETS, a 12V LED strip, and a DS3231 RTC.

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

RTC_DS3231 rtc;
#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
#define FADESPEED 50 

void setup()
{
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
  
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

  if (! rtc.begin())
  {
    Serial.println("RTC is NOT running!");
  }


  pinMode(8, OUTPUT);

}

void loop()
{

    int r, g, b;
  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(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print(")");
  Serial.println();

  Serial.println();
  delay(1000);

  //lights code
//blue light
  if (now.hour() == 05 & now.minute() == 0 & now.second() == 0)
  {
     for (r = 0; r < 256; r++) { 
    analogWrite(REDPIN, r);
    delay(FADESPEED);}
  }
  else if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)
  {
     for (r = 0; r < 256; r++) { 
    analogWrite(REDPIN, r);
    delay(FADESPEED);
     }}
 // golden light
  else if (now.hour() == 06 & now.minute() == 45 & now.second() == 0)
  {
     for (b = 255; b > 0; b--) { 
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
 }
   else if (now.hour() == 17 & now.minute() == 45 & now.second() == 0)
  {
     for (b = 255; b > 0; b--) { 
    analogWrite(BLUEPIN, b);
    delay(FADESPEED);
  }
  }
  //midday light
   else if (now.hour() == 8 & now.minute() == 0 & now.second() == 0)
  {
  for (g = 0; g < 256; g++) { 
    analogWrite(GREENPIN, g);
    delay(FADESPEED);
  }}
  //cloudy light
     else if (now.hour() == 15 & now.minute() == 0 & now.second() == 0)
  {
 for (r = 255; r > 0; r--) { 
    analogWrite(REDPIN, r);
    delay(FADESPEED);
  }}

}

At a glance you may want to prefer using && logical and instead of & bitwise. google it, not sure it makes any difference here, but.

After that, tell us what it isn’t doing that it should or vice versa.

a7

Have you run some simple test sketches to test the RTC and LED circuit separately? The RTC library should have example sketches to run.

Don't run LED strip power through a breadboard.

Please post clear and complete images of your actual wiring.

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