I have a relay set to activate when the time (rtc) and the potentiometer are of the correct value. For example if it is between 00:00 and 14:00, and the potentiometer is set to the voltage that corresponds to that it will turn on. However if you adjust the potentiometer it will just stay on. I tried using "else digitalWrite(RelayS,LOW);" but that made it only turn on for the 24hr setting. I'm not sure what command I am missing... any help would be greatly appreciated. This is the full code...
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
RTCDateTime dt;
const int RelayS = 8;
int Pot = A2;
int readVal;
float V2;
void setup()
{
Serial.begin(9600);
Serial.println("Initialize RTC module");
clock.begin();
pinMode(8,OUTPUT);
clock.setDateTime(__DATE__, __TIME__);
}
void loop()
{
dt = clock.getDateTime();
Serial.print("Time: ");
Serial.print(dt.hour); Serial.print(":");
Serial.print(dt.minute); Serial.print(":");
Serial.print(dt.second); Serial.println("");
delay(1000);
// RELAY TEST // RELAY TEST // RELAY TEST // RELAY TEST // RELAY TEST // RELAY TEST
//if(dt.minute > 45)
//{digitalWrite(RelayS,LOW);}
// POT. TEST // POT. TEST // POT. TEST // POT. TEST // POT. TEST // POT. TEST
readVal=analogRead(Pot);
V2=(5./1023.)*readVal;
Serial.print ("Pot. Voltage Is ");
Serial.println(V2);
// Light Hours //// Light Hours //// Light Hours //// Light Hours //// Light Hours //// Light Hours //
//1
if ((V2>0.00 && V2<0.20) && (dt.hour>00 && dt.hour<1))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 01:00");}
//2
if ((V2>0.21 && V2<0.41) && (dt.hour>00 && dt.hour<2))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 02:00");}
//3
if ((V2>0.42 && V2<0.62) && (dt.hour>00 && dt.hour<3))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 03:00");}
//4
if ((V2>0.63 && V2<0.83) && (dt.hour>00 && dt.hour<4))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 04:00");}
//5
if ((V2>0.84 && V2<1.04) && (dt.hour>00 && dt.hour<5))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 05:00");}
//6
if ((V2>1.05 && V2<1.25) && (dt.hour>00 && dt.hour<6))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 06:00");}
//7
if ((V2>1.26 && V2<1.45) && (dt.hour>00 && dt.hour<7))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 07:00");}
//8
if ((V2>1.46 && V2<1.66) && (dt.hour>00 && dt.hour<8))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 08:00");}
//9
if ((V2>1.67 && V2<1.87) && (dt.hour>00 && dt.hour<9))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 09:00");}
//10
if ((V2>1.88 && V2<2.08) && (dt.hour>00 && dt.hour<10))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 10:00");}
//11
if ((V2>2.09 && V2<2.29) && (dt.hour>00 && dt.hour<11))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 11:00");}
//12
if ((V2>2.30 && V2<2.50) && (dt.hour>00 && dt.hour<12))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 12:00");}
//13
if ((V2>2.51 && V2<2.70) && (dt.hour>00 && dt.hour<13))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 13:00");}
//14
if ((V2>2.71 && V2<2.91) && (dt.hour>00 && dt.hour<14))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 14:00");}
//15
if ((V2>2.92 && V2<3.12) && (dt.hour>00 && dt.hour<15))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 15:00");}
//16
if ((V2>3.13 && V2<3.33) && (dt.hour>00 && dt.hour<16))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 16:00");}
//17
if ((V2>3.34 && V2<3.54) && (dt.hour>00 && dt.hour<17))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 17:00");}
//18
if ((V2>3.55 && V2<3.75) && (dt.hour>00 && dt.hour<18))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 18:00");}
//19
if ((V2>3.76 && V2<3.95) && (dt.hour>00 && dt.hour<19))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 19:00");}
//20
if ((V2>3.96 && V2<4.16) && (dt.hour>00 && dt.hour<20))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 20:00");}
//21
if ((V2>4.17 && V2<4.37) && (dt.hour>00 && dt.hour<21))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 21:00");}
//22
if ((V2>4.38 && V2<4.58) && (dt.hour>00 && dt.hour<22))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 22:00");}
//23
if ((V2>4.59 && V2<4.79) && (dt.hour>00 && dt.hour<23))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 23:00");}
//24
if ((V2>4.80 && V2<5.00) && (dt.hour>00 && dt.hour<24))
{digitalWrite(RelayS,HIGH); Serial.println("00:00 To 24:00");}
}