Servo keeps going every 12mins

I'm building an automatic chicken feeder and I've got all my sensors, and a screen working fine.

The one thing that's giving me grief is the servo side of things. I'm using the Time/TimeAlarm libraries to set alarms which will move the servo. In my code I'm setting it to activate once per day. So, for example:

Alarm.alarmRepeat(17,30,0,EveningAlarm);

By rights it should only activate at 17:30 each day. And it does. But after that it activates about every 12 minutes.

My full code is at: Automatic Chicken Feeder · GitHub

Yeah, the code is a bit sloppy, but I'm an amateur at this. :grin:

Any help would be much appreciated.

Do you have a PULLUP resistor on button?
If not try one, or use INPUT_PULLUP.

I have a pull down resistor on my push button. Would the push button (which is for a manual feed) be able to falsely trigger the servo?

Thanks for the idea. I'll certainly look into that. It's something I hadn't thought of.

It's much easier if you post your code here. If it is too long you can add it as an attachment.

...R

The code is pretty long, so I'll attach it to this post.

chicken-feeder.ino (7.2 KB)

I don't know the Alarm library or why it keeps repeating but you can easily stop it by setting a variable to record that the alarm action has happened. For example

void EveningAlarm(){
  if (alarmDone == false) {
    Serial.println("Alarm!");
    digitalWrite(greenLED, HIGH);      // GREEN LED ON
    dispense(opened,closed);
    digitalWrite(greenLED, LOW);      // GREEN LED OFF
    alarmDone = true;
  }
}

You would obviously need to set alamDone back to false at some other time of the day.

...R

LarryD:
Do you have a PULLUP resistor on button?
If not try one, or use INPUT_PULLUP.

I tried taking the button out of circuit completely, and it still randomly triggers :confused:

Remove the section of code (and switch) that enables manual feeding.
If things correct, you are picking up noise on the switch.

LarryD:
Remove the section of code (and switch) that enables manual feeding.
If things correct, you are picking up noise on the switch.

Yep. Took the switch out (I think we posted at about the same time) and it still happens randomly. :confused:

Show us a good picture of your wiring.

By the way, how much RAM are you using?

LarryD:
By the way, how much RAM are you using?

For RAM I'm using about 29k of the 30k available in the Nano I'm using.

Even with more RAM free (ie: no screen library) it still happens.

Picture!

Put a debug print in your alarmrepeat routine to see if it is causing the problem.

Your supply voltage is ok?

But after that it activates about every 12 minutes.

it still happens randomly.

Please try and clarify the problem statement. Is the unwanted dispense at random or fixed intervals?

Does the feeder ever trigger falsely before the evening alarm is called?

When the false trigger occurs, do you see the print out of "Alarm!" from within the EveningAlarm function or does the dispense function just run.

ronnietucker:
For RAM I'm using about 29k of the 30k available in the Nano I'm using.

Even with more RAM free (ie: no screen library) it still happens.

That's ROM, where the program goes. How much RAM are you using, where the variables go. You only get 2KB of that on a Nano.

cattledog:
Please try and clarify the problem statement. Is the unwanted dispense at random or fixed intervals?

Does the feeder ever trigger falsely before the evening alarm is called?

When the false trigger occurs, do you see the print out of "Alarm!" from within the EveningAlarm function or does the dispense function just run.

The problem is quite random. Initially I thought it was 12mins, but after much more testing it's random.

Nope. Never falsely triggers before the timer.

Yes, I do see the 'alarm!' print and the FEEDING on the LCD screen.

Delta_G:
That's ROM, where the program goes. How much RAM are you using, where the variables go. You only get 2KB of that on a Nano.

I have to plead ignorance on this one and say I've no idea. :confused: Sorry.

Yes, I do see the 'alarm!' print and the FEEDING on the LCD screen.

OK, its evident that the alarm itself is being retriggered.

I would suggest modifying the EveningAlarm() function to include a print out of the time with a call to digitalClockDisplay. It's possible that there is something wrong with the rtc sync, or a memory problem as has been suggested, and the program is loosing the correct time and is resetting to before the alarm is triggered and will retrigger the alarm when the trigger time comes around again.

void EveningAlarm(){
  Serial.println("Alarm!");
  digitalClockDisplay();
  digitalWrite(greenLED, HIGH);      // GREEN LED ON
  dispense(opened,closed);
  digitalWrite(greenLED, LOW);      // GREEN LED OFF
}

cattledog:
OK, its evident that the alarm itself is being retriggered.

I would suggest modifying the EveningAlarm() function to include a print out of the time with a call to digitalClockDisplay. It's possible that there is something wrong with the rtc sync, or a memory problem as has been suggested, and the program is loosing the correct time and is resetting to before the alarm is triggered and will retrigger the alarm when the trigger time comes around again.

void EveningAlarm(){

Serial.println("Alarm!");
  digitalClockDisplay();
  digitalWrite(greenLED, HIGH);      // GREEN LED ON
  dispense(opened,closed);
  digitalWrite(greenLED, LOW);      // GREEN LED OFF
}

I have the code printing the time to the serial every few seconds, so I can see exactly the time when it triggers.

Tried it again this evening. Triggered on time at 18:03 then triggered (when it shouldn't have) at 18:07 :confused: