Suspected problem with code for a timer (RTC) activated Pet Feeder.

Hello, I'm currently building a Pet Feeder for my dogs that is inspired by this project from instructables :

Basically it is an automatic pet feeder that uses a rotary encoder to set the real time, the quantity, 1st feeding time, and the 2nd feeding time. And when it is either feeding time 1 or 2 the servo motor is activated to dispense the kibble.

I built it no problem, and made it work, but the thing that keeps happening is after I set the time of feeding, the program loads the feed() function every few seconds indefinitely and I don't know what the problem is.

I'm only new in using Arduino and I appreciate the help if anyone will provide. Thank you. (Code posted in next post.)

Cheers.

I don't know what the problem is.

And without seeing your code, neither do we.

I think he's hit the 5-minute limit for newbies. Just wait and the code will appear.

Hello thanks for the prompt reply ,and I apologize I didn't know there is a 5 minute post limit for newbies. The code by the author also exceeded the 9,000 word limit so I attached it here instead.

Code for Pet Feeder1.txt (13.5 KB)

Here is the video of the problem:

As shown in the video the clock is set to 21:33 which is 9:33pm to 12-hr time format. And the first and second feed is set to 7:00, and 17:30, respectively. And you can hear that the servo motor is activated even neither of the feeding times are equal to the current time that is set. So that's about it.

Thanks.

Are there 2 sketches, the instructables one, and yours? Which one did you post?

             }  // end of fun

It would be
more fun if
your code was
properly
indented.

Your code looks like it was typed by a drunken monkey. Use Tools + Auto Format and get that monkey into treatment.

The code to adjust deal with the encoder, and adjust the values, should be in a function that is called from loop().

It is possible to use Serial.print() to print data to the Serial Monitor app, to see why the if statements evaluate to true when you don't think they should.

I see a lot of "do {} while". That facility exists for a reason, but so many of them make me suspicious because a "while" is a much more common control structure for most tasks.

I'm only skimming the code because it's so hard to read.

aarg:
Are there 2 sketches, the instructables one, and yours? Which one did you post?

Hi, the one I posted is identical to the instructable one, I only edited the LCD display parts, and the servo values since I use a different one. But all others I just copy pasted.

PaulS:

             }  // end of fun

It would be
more fun if
your code was
properly
indented.

Your code looks like it was typed by a drunken monkey. Use Tools + Auto Format and get that monkey into treatment.

The code to adjust deal with the encoder, and adjust the values, should be in a function that is called from loop().

It is possible to use Serial.print() to print data to the Serial Monitor app, to see why the if statements evaluate to true when you don't think they should.

Haha thanks. I didn't know that. I'll definitely do it next time. Thanks.

Ok I will think of a way to do that. I will get back to you when I do. Thanks for the suggestions.

PaulS:
It is possible to use Serial.print() to print data to the Serial Monitor app, to see why the if statements evaluate to true when you don't think they should.

Hello good day! I did this and I added a SerialPrint command in the feed() function to show the current time, feed1 time, and feed2 time. I attached a screenshot for the output. The feed times looks to be correct, but the current time displayed is wrong. It supposed to be 13:53 for 1:53pm but instead it displayed 135:3, and it seems to reset to a value of 244:8 at the next execution of the function and it stays there.

EDIT:

Sorry I'm still getting used to posting here. This is my second attempt how about this one:

I attached a screenshot for the output.

I am not going to waste the time downloading and viewing a picture OF TEXT.

Post the text AS TEXT!

but the current time displayed is wrong. It supposed to be 13:53 for 1:53pm but instead it displayed 135:3, and it seems to reset to a value of 244:8 at the next execution of the function and it stays there.

Then your ARE crapping on memory you don't own, somewhere.

You have WAY too much code for solving this problem. Pick 90% of to dump. Leave the code for reading the RTC. Does just that code work?

Start adding code back in, to read the encoder, for instance. Test, thoroughly, each piece of code that you add. The last part that you added, before results went pear-shaped, is the part of the code that is wrong.

I think you need to look back at the examples that came with the rtc library

with out researching im guessing that

RTC.write(tm);

would normally load the rtc chip with a bunch of data like hour, min, second, day, month, year

so you read the hour

virtualPosition = tm.Hour;

then change the displayed hour then try to write it back to the chip using a update rtc instruction

tm.Hour = virtualPosition;
RTC.write(tm);

now some library's may allow you to update the hour but most will insist that you update all of the information or use a instruction that tells it you only want to update the hour.

What you are trying to do isn't that difficult. The way you are trying to do it is messed up