DS1307RTC and hour.now error

Apperantly my brain will not wrap itself around the whole RTC thing.

I am a complete newbie when it comes to programing. JUst trying to make a few basic things that I can use around the house.

Arduino Nano with a DS1307RTC and a relay Any help welcomed.

Arduino: 1.8.12 (Windows Store 1.8.33.0) (Windows 10), Board: "Arduino Nano, ATmega328P"

C:\Users\ricks\OneDrive\Pictures\Desktop\Pool_Pump_4\Pool_Pump_4.ino: In function 'void loop()':

Pool_Pump_4:20:10: error: overloaded function with no contextual type information

if (hour.now >= 0 && hour.now) == 5){

^~~

Pool_Pump_4:20:27: error: overloaded function with no contextual type information

if (hour.now >= 0 && hour.now) == 5){

^~~

Pool_Pump_4:20:32: error: expected primary-expression before '==' token

if (hour.now >= 0 && hour.now) == 5){

^~

exit status 1
overloaded function with no contextual type information

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

It is always best to post your complete sketch and do it inside code tags. It helps people help you.

I am assuming you have some sort of declaration near the top of your sketch

#include <DS1307RTC.h>

This will introduce the variable RTC into the sketch. You can then fetch the hour by calling the hour()
method

int hour = RTC.hour();

Look at the examples that come with the library (File->Examples->DS1307RTC->ReadTest)

BLH64, this for the help.

The DS1307RTC library is installed and included.

Add your suggestion and got a new error

Pool_Pump_4:6:6: error: ‘int hour’ redeclared as different kind of symbol

int hour = time.hour();

here is the whole sketch

#include <DS1307RTC.h>
#include <Wire.h>
#include <TimeLib.h>

int hour = RTC.hour();

void setup() {
// put your setup code here, to run once:
// Wire.begin;
// time.begin;
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(3, LOW);
digitalWrite(7, LOW);

}

void loop() {
// put your main code here, to run repeatedly:
//if (now.hour >= 0 && now.hour == 5) {
if (hour.now >= 0 && hour.now) == 5){
// Do a thing
digitalWrite(3, HIGH);
digitalWrite(7, HIGH);
}
else {
// Do something else
digitalWrite(3, LOW);
digitalWrite(7, LOW);
}
}

You are mixing together two time libraries. Why have you included the Wire.h library? Why have you included the TimeLib.h library?

As is painfully obvious, I have very little clue what I am doing regarding the use of lime libraries. What I read said to be able to use the serial monitor, Wire.h had to be called so that Serial.begin would function.

Here is a new version of the code. It compiles but fails to function correctly. It will not set the relay low after the specified time. Thanks for the response.

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

RTC_DS1307 rtc;

char buf1[20];

void setup()
{
Serial.begin(9600);
rtc.begin();
digitalWrite(3, LOW);
digitalWrite(7, LOW);
}

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

if (now.hour() >= 15 && (now.hour() <= 17));
{
digitalWrite (3, HIGH); // Activate the relay
digitalWrite (7, HIGH); //Activeate the Relay LED

}

// else

digitalWrite(3, LOW);
digitalWrite(7, LOW);
}
}

 if (now.hour() >= 15 && (now.hour() <= 17));

Read about Trap # 13 here
http://www.gammon.com.au/tips

Why have you commented out the else ? It should probably be uncommented.
The else block needs brackets around the code to be executed, just like an if block.

As is painfully obvious, I have very little clue what I am doing

Studying all the Traps and Tips in Nick Gammon’s Tutorial will help alot.

Cattledog, thank you for the input. If the Else command is uncommented, it will not compile. Says there is no corisponding IF statement.

I will read up on the traps and see if I can solve this

“ Says there is no corisponding IF statement. ”

That’s because you had a ; at the end of the if(); <——-<<<<<

larryd, thanks for that catch.

All the time code seems to be working but the the digitalWrite calls to the pins is not. They are staying HIGH all of the time

Be default, pins are INPUT. If you want to make them an OUTPUT, you have to use the pinMode() function within setup()