rtc module ds3231 controlled led

PaulS:
I've NEVER seen an RTC return 24 for the hour. 0, yes. 1 to 22, yes. 23, yes. 24, no.

You need to configure your RTC to return time in 24 hour format.

yes u are correct rtc didnt return 24 but it did returned 00 ,,,, adding 24 was a wrong idea i will check again by adding new time

LarryD:
Why are you SHOUTING at the people you are asking for help.

Have you used Google to research what others have done with the DS3231?

You really should understand basic programming before starting out on your own projects.
Arduino Reference - Arduino Reference

.

not shouting at peoples who are helping me lolz

yes i used google to research for 1 week but i couldnt find a simple program which can demonstrate how ds3231 can trigger an led or make pins go high at particular time...

programs available are most with complex tasks and lcd included with it.

mrugen1991:
not shouting at peoples who are helping me lolz

yes i used google to research for 1 week but i couldnt find a simple program which can demonstrate how ds3231 can trigger an led or make pins go high at particular time…

programs available are most with complex tasks and lcd included with it.

i found 1 code posted by 1 youtuber controlling relays with rtc module.he states the code is correct but when i use in my arduino ide i get an error

error is as follow

exit status 1
expected unqualified-id before ‘?’ token

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

RTC_DS1307 rtc;


void setup() {

  Serial.begin(9600);
  Wire.begin();

  rtc.begin();

  if (! rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
  }
  //Any pin. I have used Pin 4
  pinMode(4, OUTPUT);
 

}

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(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();

    Serial.println();
    delay(1000);

      //The time is set as 24 hours
     //Pin 4 get high at 6pm and low at 6am
    if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(4,HIGH);
    }

    else if (now.hour() == 6 & now.minute() == 0 & now.second() == 0)
    {
      digitalWrite(4, LOW);
    }
 

}

Is that the complete error message ?
Are you sure that you have posted the program that produces the error ?

Try

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

RTC_DS1307 rtc;

void setup() 
{
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

  if (! rtc.isrunning())
  {
    Serial.println("RTC is NOT running!");
  }
  //Any pin. I have used Pin 4
  pinMode(4, OUTPUT);

}

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(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);

  //The time is set as 24 hours
  //Pin 4 get high at 6pm and low at 6am
  if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)
  {
    digitalWrite(4,HIGH);
  }

  else if (now.hour() == 6 & now.minute() == 0 & now.second() == 0)
  {
    digitalWrite(4, LOW);
  }

}

LarryD:
Try

#include <Wire.h>

#include “RTClib.h”

RTC_DS1307 rtc;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

if (! rtc.isrunning())
  {
    Serial.println(“RTC is NOT running!”);
  }
  //Any pin. I have used Pin 4
  pinMode(4, OUTPUT);

}

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(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);

//The time is set as 24 hours
  //Pin 4 get high at 6pm and low at 6am
  if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)
  {
    digitalWrite(4,HIGH);
  }

else if (now.hour() == 6 & now.minute() == 0 & now.second() == 0)
  {
    digitalWrite(4, LOW);
  }

}

very much thank you it solved the problem and working very well

thank you to all of the peoples who put their brains in figuring out my problem and solving it

To set PC time into the RTC.

  • Put the following line of code into setup(), upload the sketch 'once'.

  • Then remove the line of code from setup() and upload the sketch again.

rtc.adjust(DateTime(DATE, TIME));

void setup() 
{
  Serial.begin(9600);
  Wire.begin();
  rtc.begin();

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



//Set the RTC to PC time:
//uncomment the next line, upload, then comment the next line, then upload again. 
//  rtc.adjust(DateTime(__DATE__, __TIME__));



  //Any pin. I have used Pin 4
  pinMode(4, OUTPUT);

}

.
.
.

** if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)**
What is the difference between using & and && ?
** if (now.hour() == 18 && now.minute() == 0 && now.second() == 0)**

.

LarryD:
** if (now.hour() == 18 & now.minute() == 0 & now.second() == 0)**
What is the difference between using & and && ?
** if (now.hour() == 18 && now.minute() == 0 && now.second() == 0)**

.

do i try the above codes with & and && and see what happens ????

1 more query i have is that will this code work everytime the clock strikes 18hrs ???

or do i have to do something for this to make it work on daily bases ????

Read these links, then answer the question:

https://www.arduino.cc/en/Reference/BitwiseAnd

https://www.arduino.cc/en/Reference/Boolean

If the RTC is read in 24 hour format 18:00:00 will work.

BTW the DS3231 is better than the DS1307.
.

FYI

.

You can prove 18:00:00 will work by setting the time to see what will happen:

 // This line sets the RTC with an explicit date & time, for example to set
 // May 21, 2016 at 6pm you would call: (use 24 hour time)
 //                    YYYY MM  DD  HH  MM  SS
 //rtc.adjust(DateTime(2016, 5, 21, 17, 59, 50));

.