Yet Another Auto Feeder

Do you have a question on how to do something.
Ask in here.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Yet Another Auto Feeder

Post by dlplunkett44 »

I've been looking at other threads about auto feeders, but I'm not finding exactly what I'm looking for.

I am currently modifying an Eheim feeder to be powered off of a 3v wallwart and be activated by a 12v relay. The relay is powered by 12v wallwart plugged into the RA. I would like to know how to code (I'm still very new to coding, but catching on) the controller to turn off my return pump and my 2 powerheads, wait 60 seconds for the water to finish spilling over the overflow, then activate the outlet powering the 12v relay. I'm not sure how long power has to be applied to the relay, a second or two? I would then like it to wait for 10 minutes for the fish to eat, then for the return and powerheads to come back on. I would like for this to happen 3 times a day at set times, maybe 8AM, 2PM, 8PM. I would also like to be able to trigger this to happen manually.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

If you take a look at some of my code (in my signature) you can see a few examples of how I'm doing the auto feeder.

The 10 minute timeout would be controlled by your feeding timer (you can set in the portal if you have wifi)

The ports you want to disable during feeding mode are controlled by the variable ReefAngel.FeedingModePorts which should be in your setup() function already.

You only need the relay held for a second is plenty. Basically all you'll need to program is the time to start feeding mode and the time to turn on / off the feeder.

The way I have my code setup, if I trigger the feeder (whether manually or through code). It "presses" the button however many times I've configured with a set delay. My agressive fish need to get some and then a second feeding helps the shy fish to make sure everyone gets to eat.

Let me know if you have any questions. I can help fine tune this when I'm not at work.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

I've been looking at your code, but I just keep getting lost.
I'm still not sure how to program it to activate feeding mode at certain times.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

Would this work?
This is what I came up with so far:




static unsigned long feeding;
//FEEDER RELAY IS PORT 8

if ( ((hour()==08) && (now()%SECS_PER_HOUR==0)) || ((hour()==14) && (now()%SECS_PER_HOUR==0)) || ((hour()==20) && (now()%SECS_PER_HOUR==0))
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
feeding = now();

if ((now()-feeding>=60) && (now()-feeding<=61))
{
ReefAngel.Relay.On(Port8); //WAIT 60 SECOND, START FEEDER RELAY,WAIT 1 SECOND,
}ELSE
{
ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF

}
if ((now()-feeding>=900))
{
ReefAngel.FeedingModeStop(); //STOP FEEDING MODE


}
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

I think this would be better:

static unsigned long feeding;
//FEEDER RELAY IS PORT 8

if ( ((hour()==08) && (now()%SECS_PER_HOUR==0)) || ((hour()==14) && (now()%SECS_PER_HOUR==0)) || ((hour()==20) && (now()%SECS_PER_HOUR==0))
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
feeding = now();

while ((now()-feeding<=900)
{

if ((now()-feeding>=60) && (now()-feeding<=61))
{
ReefAngel.Relay.On(Port8); //WAIT 60 SECOND, START FEEDER RELAY,WAIT 1 SECOND,
}ELSE
{
ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF

}

}

ReefAngel.FeedingModeStop(); //STOP FEEDING MODE


}
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

The easiest way to do the time conditional would be to do this...

Let's say you want 8pm. So let's calculate 8pm in seconds.. (20 hours * 60 * 60) + (0 minutes *60) + (0 seconds).

So that breaks down to 20 * 60 * 60 since minutes/seconds will be 0. So 72,000 seconds. Now we do the following calculation to see if it's 8pm.

if (now()%SECS_PER_DAY==72000) ...

For multiple times now, you can do the (now()%SECS_PER_DAY==<X>) || (now()%SECS_PER_DAY==<Y>)

You could also use the function ScheduleTime(hour, min, seconds) to do the calculation.

So you could do if ( now()%SECS_PER_DAY==ScheduleTime(20,0,0) ) to save yourself the math.

As far as the code. You do not need the while loop. Your code is run continuosly already in a loop.. thats why we run everything in the loop() function. The first set of code your wrote looks better.

Also, I would not put in the FedingModeStop() function. Just make sure your feeding mode timer is already set to 900 seconds, unless you want a different feeding timer when automating feeding mode?
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

I think the if statement "if (now()%SECS_PER_DAY==72000)" is wrong. Shouldn't it be "if(now()%72000==0)"?

So this is my code now:

static unsigned long feeding;
//FEEDER RELAY IS PORT 8

if (now()%28800==0) || (now()%50400==0) || (now()%72000==0) //if it is 8am or 2pm or 8 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
feeding = now(); //set the time of the start of feeding to variable feeding

if ((now()-feeding>=60) && (now()-feeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Port8); //TURN FEEDER RELAY ON
}

ELSE
{
ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF
}

}


My other question would be, how would I change the feeding mode timer if I wanted it different that 900 seconds?
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Yet Another Auto Feeder

Post by binder »

dlplunkett44 wrote: My other question would be, how would I change the feeding mode timer if I wanted it different that 900 seconds?
This depends. There are several ways to do it.
1. Use either the Status App or Android or iOS app to change the feeding timer internal memory.
2. Inside your init() function, you can use this line:

Code: Select all

InternalMemory.FeedingTimer_write(1000);  // 1000 seconds
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

Awesome! Whenever I initiate the feeding mode manually, on my android app for example, how would I make it to run my code?
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Yet Another Auto Feeder

Post by binder »

dlplunkett44 wrote:Awesome! Whenever I initiate the feeding mode manually, on my android app for example, how would I make it to run my code?
You would have to modify things a little. Since you are keeping track of the time that feeding mode is started, we have to modify things slightly to have it execute when you trigger feeding mode from the android app.

What I did was pull out the code that executes during feeding mode and left your "auto triggered" feeding mode checks in place.

Code: Select all

static unsigned long feeding = 0;

if ((now()%28800==0) || (now()%50400==0) || (now()%72000==0)) //if it is 8am or 2pm or 8 pm
{
  ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
  if ( feeding == 0 ) {
    feeding = now(); //set the time of the start of feeding to variable feeding
  }
  
  if ((now()-feeding>=60) && (now()-feeding<=61)) //if between 60 and 61 seconds has past
  {
    ReefAngel.Relay.On(Port8); //TURN FEEDER RELAY ON
  }
  else 
  {
    ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF
  }
} else {
  if ( feeding > 0 ) {
    feeding = 0;
  }
}
Once feeding mode is triggered, the "DisplayedMenu" is set to FEEDING_MODE. When we enter this section, I immediately check to see if the feeding timer is 0 (unset). If it is, I set it to now() like you were previously doing. Then it proceeds with the rest of your code checks like before. Then, when feeding mode is exited, the "DisplayedMenu" variable is no longer set to FEEDING_MODE so we clear out the feeding timer by setting it back to 0. I put a check in there so we are not always setting it back to 0. You could remove my check if you want. It won't hurt anything at all (or at least it shouldn't).

I have not tested this code out. It should work but you should test it to confirm.
Last edited by binder on Thu Aug 15, 2013 10:08 am, edited 1 time in total.
Reason: Changed -1 to 0 to work with unsigned long variables
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Yet Another Auto Feeder

Post by binder »

Quick little note on my code, you will want to change the -1 assignment and checks to be 0. You cannot get a negative value in an unsigned long.

I just updated and edited the post with this change.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

This won't work.. The way you have it written may work, but your logic is saying this...

Take the number of seconds since midnight january 2000 and divide it by 20 hours (8pm) and and when the remainder is 0, then run this code...

So what you're saying with that logic to run that code every 20 hours.. so maybe the first day it will work and hit 8pm, but then 20 hours later it will be 4pm.

My logic takes the current seconds of time (now()) and divide it by the number of seconds per day (24 hours). If the remainder = 20 hours (8pm) then run that code.

Does that make sense?

dlplunkett44 wrote:I think the if statement "if (now()%SECS_PER_DAY==72000)" is wrong. Shouldn't it be "if(now()%72000==0)"?

So this is my code now:

static unsigned long feeding;
//FEEDER RELAY IS PORT 8

if (now()%28800==0) || (now()%50400==0) || (now()%72000==0) //if it is 8am or 2pm or 8 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
feeding = now(); //set the time of the start of feeding to variable feeding

if ((now()-feeding>=60) && (now()-feeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Port8); //TURN FEEDER RELAY ON
}

ELSE
{
ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF
}

}


My other question would be, how would I change the feeding mode timer if I wanted it different that 900 seconds?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

This is the code I use in my "vacation" mode. I want feeding mode triggered every day at 7pm while I'm away. This way my Smart_NTM get's triggered and the fish don't have their daily routine changed :) I'm sure they care so much...

Code: Select all

    
    if (now()%SECS_PER_DAY==19*SECS_PER_HOUR) {
      ReefAngel.FeedingModeStart();
    }
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

AH! so now() is the seconds since jan 2000. I thought it was the seconds since midnight last night. I'll fix my code and post it back up here in a little bit. Thanks so much everyone!!
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

Either 2000 or 1970. I forget which. I know the swfltk libraries we use for GPS sunrise uses one and not the other...

So finally, the now()%SECS_PER_DAY will give you the seconds since midnight today.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

Does this code sound good? If so, I'm going to try it tonight.


static unsigned long feeding = 0;

if ((now()%SECS_PER_DAY==28800) || (now()%SECS_PER_DAY==50400) || (now()%SECS_PER_DAY==72000)) //if it is 8am or 2pm or 8 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( feeding == 0 ) {
feeding = now(); //set the time of the start of feeding to variable feeding
}

if ((now()-feeding>=60) && (now()-feeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Port8); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF
}
} else {
if ( feeding > 0 ) {
feeding = 0;
}
}


BTW, how to I put the code in a box like you guys did?
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Yet Another Auto Feeder

Post by binder »

You need to use the "code" tags:

Code: Select all

[code]insert code here
[/code]
There's a button above the text box that says "code" right next to the quote button.
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

It should be ok, but I would put the feeding=0 assignment where you turn off the relay and then it's one less else statement.
dlplunkett44 wrote:Does this code sound good? If so, I'm going to try it tonight.


static unsigned long feeding = 0;

if ((now()%SECS_PER_DAY==28800) || (now()%SECS_PER_DAY==50400) || (now()%SECS_PER_DAY==72000)) //if it is 8am or 2pm or 8 pm
{
ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
if ( feeding == 0 ) {
feeding = now(); //set the time of the start of feeding to variable feeding
}

if ((now()-feeding>=60) && (now()-feeding<=61)) //if between 60 and 61 seconds has past
{
ReefAngel.Relay.On(Port8); //TURN FEEDER RELAY ON
}
else
{
ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF
}
} else {
if ( feeding > 0 ) {
feeding = 0;
}
}


BTW, how to I put the code in a box like you guys did?
binder
Posts: 2865
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
Contact:

Re: Yet Another Auto Feeder

Post by binder »

yeah but if you do that inside the feeding mode if statement, feeding will be reset and it will trigger again during the feeding mode duration. that's why I put it outside of displayedmenu == feeding mode so it would only trigger once.

Sent from my Galaxy Nexus
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

Ah got it.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

So I finished modifying my Eheim auto feeder last night both for relay trigger and ac adapter. It runs fine when there are batteries, but when I have the ac adapter plugged in and set to 3v, whenever the "feed now" button is pressed, or the relay triggered (which does the same thing), it quickly turns off and on the feeder instead of rotating the feeding drum. This will happen 9 times out of 10, but every once in a while it will work. I don't have a multimeter, but I figured maybe the ac adapter wasn't giving it enough power (maybe less than 3v?), so I set it to the next step up which is 4.5v. When it is set at 4.5v, it works fine everytime; it also turns the feeding drum a little faster. I'm not sure if this is ok for the feeder long term, but it seems to work ok for now. Since it is opperating on a higher voltage, I don't want to leave the feeder itself powered all the time, so I've modified the code yet again to come on 5 seconds before the relay is activated so it has time to initialize, then stay on for 15 seconds after activating the relay giving the feeder time to fully rotate (I may have to modify the timing). Again, I'm going to try it tonight if you guys think the code is ok. THANKS AGAIN!!!!

Code: Select all

static unsigned long feeding = 0;

if ((now()%SECS_PER_DAY==28800) || (now()%SECS_PER_DAY==50400) || (now()%SECS_PER_DAY==72000)) //if it is 8am or 2pm or 8 pm
{
  ReefAngel.FeedingModeStart(); //START FEEDING MODE
}

if (ReefAngel.DisplayedMenu==FEEDING_MODE)
{
  if ( feeding == 0 ) {
    feeding = now(); //set the time of the start of feeding to variable feeding
  }
  
  if ((now()-feeding>=55) && (now()-feeding<=76)) //if between 55 and 76 seconds has past
  {
    ReefAngel.Relay.On(Port1);  //TURN FEEDER POWER ON
  }
  else
  {
    ReefAngel.Relay.Off(Port1);  //TURN FEEDER POWER OFF
  }

  if ((now()-feeding>=60) && (now()-feeding<=61)) //if between 60 and 61 seconds has past
  {
    ReefAngel.Relay.On(Port8); //TURN FEEDER RELAY ON
  }
  else 
  {
    ReefAngel.Relay.Off(Port8); //TURN FEEDER RELAY OFF
  }
} else {
  if ( feeding > 0 ) {
    feeding = 0;
  }
}
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

It does sound like your not getting enough power. If it turns off when hitting the feed button manually... odd. Do you have another adapter you could try?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Yet Another Auto Feeder

Post by rimai »

Sounds like the power supply doesn't have enough juice.
Roberto.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

Yeah, thats what I was thinking. I don't have another power supply. It says it outputs 1 amp at 3/4.5/5/6/9/12v. It works fine at 4.5 volts. I just wonder if its not really 3 volts. Maybe 2.5? The feeder specifically says don't use rechargable batteries. I wonder if this is because they are 1.2 volts instead of 1.5. That would be 2.4 instead of 3. Maybe this is the problem. That would also mean that just because I have it set at 4.5v, it may not be quite that high. Without a multimeter I don't know. I think I may pick one up on the way home. Does this look like a good one? http://www.radioshack.com/product/index ... =CT2032235
Or should I get:
http://www.radioshack.com/product/index ... =CT2032235
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Yet Another Auto Feeder

Post by rimai »

I like #2 myself.
What I think is happening is this....
The motor requires a lot of energy to start spinning. It's the nature of any electric motor. They required an in-rush current as much as 40 times greater than the operating current (when the motor is spinning).
Battery are able to discharge a lot of current for a short period of time without changing the voltage too much, so it is able to keep the mcu inside the feeder from browning out.
Unregulated power supplies, like the one you are using, can't do that too well. So, I think when the motor starts to spin, it draws too much current that the voltage of the power supply drops below the brown out voltage of the mcu in the feeder and it causes it to reset, which disengages the motor, which leads to voltage brought back to normal and the feeder comes back alive. Just a microsecond in the brownout voltage is enough to cause this.
The best solution is for you to get a regulated power supply.
Roberto.
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

I think I will pick up the multimeter on the way home tonight. Do you think it will be ok to operate the feeder on 4.5v if I can't find a regulated 3v power supply?
User avatar
lnevo
Posts: 5422
Joined: Fri Jul 20, 2012 9:42 am

Re: Yet Another Auto Feeder

Post by lnevo »

Here, grab one of these when your getting that multimeter :)

http://www.radioshack.com/product/index ... Id=3802149
Piper
Posts: 298
Joined: Fri Jul 20, 2012 7:13 am
Location: Oakley, CA

Re: Yet Another Auto Feeder

Post by Piper »

I used 5v cell phone wall wart to power a LM317T adjustable voltage regulator on my feeder and it's working great so far. There are a couple of links in the original auto feeder thread that talk, albeit briefly, about the adjustable regulator.

[EDIT]Just realized that the adapter below in unregulated. The one Lee posted above would be the better choice.[/EDIT]

Jameco.com has adapters though: http://www.jameco.com/webapp/wcs/stores ... _123158_-1

~Charlie
dlplunkett44
Posts: 74
Joined: Mon Aug 05, 2013 3:16 am

Re: Yet Another Auto Feeder

Post by dlplunkett44 »

Well I thought I would update everyone. First of all, thanks for all your help. I got the multimeter and did some tests. The original unregulated ac adapter at 3v was putting out ~3.050v, however when feeding was started, it briefly went to 0v and back up. Just like rimai said, it is requiring more current than is available and the volts are dropping causing it to reset. I was hoping I could just use the 4.5v setting. It was ~4.6 volts and would drop to ~4.2v when feeding was started, however it soon started to drop to 0v causing the feeder to reset. Because of this and not wanting to run it at 50% more voltage all the time, I got the 700mA 3v regulated power supply. It is putting out ~3.060 volts, and when running the feeder it drops to ~2.950, which is fine.
Again, thanks so much for everyone's help!
User avatar
Sacohen
Posts: 1833
Joined: Sun Apr 21, 2013 6:25 am
Location: Davie, FL

Re: Yet Another Auto Feeder

Post by Sacohen »

dlplunkett44 wrote:Well I thought I would update everyone. First of all, thanks for all your help. I got the multimeter and did some tests. The original unregulated ac adapter at 3v was putting out ~3.050v, however when feeding was started, it briefly went to 0v and back up. Just like rimai said, it is requiring more current than is available and the volts are dropping causing it to reset. I was hoping I could just use the 4.5v setting. It was ~4.6 volts and would drop to ~4.2v when feeding was started, however it soon started to drop to 0v causing the feeder to reset. Because of this and not wanting to run it at 50% more voltage all the time, I got the 700mA 3v regulated power supply. It is putting out ~3.060 volts, and when running the feeder it drops to ~2.950, which is fine.
Again, thanks so much for everyone's help!
How did you connect the power supply to the feeder?
I got the same 700mA 3v regulated power supply from Radio Shack and connected it to the battery terminals. positive to positive (or the red wire) and negative to the black wire.
I'm getting no power at all.
Any suggestions would help.
Post Reply