I want to make relay on and off when it's:
on 19:2:0 and off 19:3:30
but why this code make relay off in two times?
on at 19:2:0 then off at 19:2:30
on again at 19:3:0 then second off at 19:3:30
anyone can help me, please.
if
((waktu.Hour==19)&&(waktu.Minute>=2)&&(waktu.Minute<=3)&&(waktu.Second<=30)){digitalWrite(relay,LOW);}
If the time is after the switchOffTime, you will get a brief on/off cycle every time this check is made. Much better to test to see if you are within the on window or not
If (actualSecondOfDay >= switchOnTime && actualSecondOfDay < switchOffTime) {
//switch on
}
else {
// switch off
}
Yes, much better, THX. Imma say that's what I meant by implications. But I shoulda seen that.
It's the kind of mistake that would be hard to see, while one was wondering what was going wrong what might be caused by a "a brief on/off cycle", which might not matter to an LED but not everything switched on and off might be so forgiving.
I suggest that you start by using Excel to convert each cell containing a time into seconds since midnight, then export them as a .csv file
The data is then practically in the right format to put into a 2 dimensional array. You could put that in PROGMEM on the Uno to save memory if necessary
Once in the array have you worked out how you are going to use the data ? Perhaps start with a few rows and columns entered manually
You are asking for almost each and every detail of your project. How much are you gonna pay me if I realise your project?
Look up the specs of an arduino uno
how much flash rom?
how much RAM?
lookup how many bytes a single variable of
type unsigned long needs
then calculate
16 columms * 30 rows * bytes per unsigned long.
compare the number with the memory of the arduino uno
Also, minutes MM is always zero. All you need for a fake time like seconds since midnight is actually just a number that is guaranteed to get bigger.
So
magicTime = hours * 100 + seconds;
would be integers between 0 and 2359. Just cut your data in half, that.
Now the on time is hours only, and only 8 different hours, so you can store that in three bits. The other time is the same hour, and 59 max, that's a byte or really only 6 bits.
Each event of on-ness for this odd table is 9 bits.
There are libraries that make using N bit numbers easy with minimum possible storage. I'd have to do more work I am too lazy to do to see the code / bits of storage tradeoff.
Games to play.
But srsly, what needs to run for 12 seconds one day and 13 the next?