not declared in this scope , something i dont know the value of

Hello People

Please be gentle i am brand new at this and dont really know what i am doing, it may be a simple answer but i keep getting error message!
"not declared in this scope", i kind of understand its something to do with a variable, however how do i declare a variable if i dont know its value?

any help will be gladly received.

[
 In function 'void loop()':

lights-on-off-with-day-night:132: error: 'hour' was not declared in this scope

   if (hour >= 19 && minute >= 45)digitalWrite (relayPin, LOW); // ON

       ^

lights-on-off-with-day-night:132: error: 'minute' was not declared in this scope

   if (hour >= 19 && minute >= 45)digitalWrite (relayPin, LOW); // ON

                     ^

lights-on-off-with-day-night:137: error: 'hour' was not declared in this scope

   if (hour >= 19 && minute >= 58)digitalWrite (relayPin, HIGH); // OFF

       ^

lights-on-off-with-day-night:137: error: 'minute' was not declared in this scope

   if (hour >= 19 && minute >= 58)digitalWrite (relayPin, HIGH); // OFF

                     ^

exit status 1
'hour' was not declared in this scope]

you can declare a variable and initialize it:

int hour = 24;
int minute = 60;
int second = 60;

Thank you that seems to have solved the scope problem but now the pin does not seem to change state
here is the code

 [
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
const int relayPin =8;
const int cyclePin =A0;
boolean cycle = 0;





//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Clock~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,42,21,4,26,11,14);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
 // Wire.beginTransmission(DS3231_I2C_ADDRESS);
 // Wire.write(0); // set next input to start at the seconds register
 // Wire.write(decToBcd(second)); // set seconds
 // Wire.write(decToBcd(minute)); // set minutes
 // Wire.write(decToBcd(hour)); // set hours
 // Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
 // Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
 // Wire.write(decToBcd(month)); // set month
  //Wire.write(decToBcd(year)); // set year (0 to 99)
 // Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Timer and day night output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  cycle, relayPin;
  
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop()
{ 
  
  {
  if (hour >= 19 && minute >= 45)digitalWrite (relayPin, LOW); // ON
  if (!cycle ==0) Serial.println ("DAYTIME");
  else Serial.println ("NIGHTTIME");
  }
  {
  if (hour >= 19 && minute >= 58)digitalWrite (relayPin, HIGH); // OFF
  }


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Time ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
 
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second
} ]

The pin is an input, isn't it?

No the relayPin is set to an output!

Oh.
Any good reason you didn't set it as such in setup()?

FYI... this may not do what you expect it to do:

if (hour >= 19 && minute >= 45)digitalWrite (relayPin, LOW); // ON

it would only be true for 15 minutes each hour after 7:45pm (8:45pm, 9:45pm, etc.) and before midnight.

Is that what you want?

  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);

You should set a pin’s pinMode and its initial state in the setup function, not every time you display something. As it is, this will reset the state of the relayPin to HIGH every time through the loop function, which is every second.

  cycle, relayPin;

What is this statement supposed to do?

Pete

what i need it to do is turn on a relay at a certain time and display day, and then off at a certain time and display night.

PETE

pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);

They are in the setup not the loop!

as for
cycle, relayPin;
i was trying to asign cycle to the relay pin as when the relay pin changes state i need it to print night or day

pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);

They are in the setup not the loop!

void setup()
{
  Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,42,21,4,26,11,14);
}

OK, right.

I dont understand why does it matter where in the setup they are?

[//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Timer and day night output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
cycle, relayPin;

}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop()
{

{
if (hour >= 19 && minute >= 45)digitalWrite (relayPin, LOW); // ON
if (!cycle ==0) Serial.println ("DAYTIME");
else Serial.println ("NIGHTTIME");
}
{
if (hour >= 19 && minute >= 58)digitalWrite (relayPin, HIGH); // OFF
}
]

I posted the whole of your setup()

E235:
They are in the setup not the loop!

They are in displayTime() which is called every iteration through loop() !

Ok i think i understand so here is the code now i have moved it and the relay keeps flicking state as before!

[
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
const int relayPin =8;
const int cyclePin =A0;
boolean cycle = 0;
int hour = 24;
int minute = 60;
int second = 60;



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Clock~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  digitalWrite(relayPin, HIGH);
  pinMode(relayPin, OUTPUT);
  
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,42,21,4,26,11,14);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
 // Wire.beginTransmission(DS3231_I2C_ADDRESS);
 // Wire.write(0); // set next input to start at the seconds register
 // Wire.write(decToBcd(second)); // set seconds
 // Wire.write(decToBcd(minute)); // set minutes
 // Wire.write(decToBcd(hour)); // set hours
 // Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
 // Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
 // Wire.write(decToBcd(month)); // set month
  //Wire.write(decToBcd(year)); // set year (0 to 99)
 // Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Timer and day night output ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  
 
  cycle, relayPin;
 
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Loop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void loop()
{ 
  
  {
  if (hour >= 22 && minute >= 17)digitalWrite (relayPin, LOW); // ON
  if (!cycle ==0) Serial.println ("DAYTIME");
  else Serial.println ("NIGHTTIME");
  }
  {
  if (hour >= 22 && minute >= 19)digitalWrite (relayPin, HIGH); // OFF
  }


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Time ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
 
  displayTime(); // display the real-time clock data on the Serial Monitor,
  
}]
cycle, relayPin;

Still makes no sense. = is the assignment operator.
relayPin always == 8

You write to the pin before you set it as an output

How did you manage to copy these two statements:

 pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);

from displayTime to setup

 digitalWrite(relayPin, HIGH);
  pinMode(relayPin, OUTPUT);

and get them the wrong way round?

as for
cycle, relayPin;
i was trying to asign cycle to the relay pin

You may have tried but you've failed. That is not an assignment statement.
If you succeed in assigning cycle to the relay pin, things are only going to get a lot worse.
You need to think carefully about why you would do that.

Pete

I have them the correct way now its been a long day!

All i want it to do is display day or night i asumed that the boonlean needed somehow to be asigned to the pin so it could monitor its state!

cycle = digitalRead(relayPin);

But why not just

if (digitalRead(relayPin) == LOW) Serial.print("DAY");