Countdown timer for relay

Community contributed apps

Posts: 171
Joined: Fri May 23, 2014 8:09 am
PostPosted: Wed Oct 07, 2015 10:24 am
I didn't know where to put this for sure, but I guess this would be an app option.

I would like to be able to set a countdown timer to control a relay for a select amount of time. For example, I may want to fill a container with RODI water.

Currently I have a solenoid plugged into a relay. I can toggle the relay on and off to fill the container, but it would be much more convenient to be able to set the relay to be on for 30 minutes, or 60 minutes or whatever I like, then automatically shut off.

Has anyone done this? Is it possible? Is is something anyone else is even interested in?
Image
User avatar
Posts: 2741
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Wed Oct 07, 2015 10:56 am
paperdesk wrote:I didn't know where to put this for sure, but I guess this would be an app option.

I would like to be able to set a countdown timer to control a relay for a select amount of time. For example, I may want to fill a container with RODI water.

Currently I have a solenoid plugged into a relay. I can toggle the relay on and off to fill the container, but it would be much more convenient to be able to set the relay to be on for 30 minutes, or 60 minutes or whatever I like, then automatically shut off.

Has anyone done this? Is it possible? Is is something anyone else is even interested in?

yes this is possible. this is exactly what the feeding mode and water change modes do (well...water change mode is not a timed feature, but functions the same none the less).

it will require custom code being added. you will need to set the timer duration, ports to toggle and how you want to activate it. i would suggest looking at the feeding mode function inside the libraries to see how we handle it. what we do is retain the state of the existing relays that get toggled and then when the mode is entered, we turn off all the ports that are specified to be turned off and then leave the others alone. once the mode is exited, we return the ports back to their previous state. i'm assuming that you want to force a specific port (or set of ports) on during the function and then return them to their previous state (or force them off) when the function/countdown finishes.

so, let's get you started (i'll help get the questions going and get you started and others will probably chime in as well).

First off, we need to know these questions:
  • How many ports or what ports do you want to toggle?
  • How long do you want the countdown to be? Do you want it to be changeable on the fly (like via a memory location)?
  • How do you want to activate it? Via a virtual relay port, custom variable value, memory location

Now, once we get this information, we can proceed forward with more of the details.
User avatar
Posts: 5349
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Wed Oct 07, 2015 12:52 pm
I have something more specific. I use it for my swabbie. If I turn on the swabbie, it will run for 2 minutes.

Here's the code I use.

Code: Select all
void RunSwabbie() {
  int repeat=InternalMemory.read(Mem_B_SwabbieRepeat)*60;
  int runtime=InternalMemory.read(Mem_B_SwabbieTime)*60;
  static time_t t;
 
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Swabbie)) {
    ReefAngel.Relay.Auto(Swabbie);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Swabbie);
  } else {
    ReefAngel.DosingPumpRepeat(Swabbie,0,repeat,runtime);   
  } 
}


Here it is a bit more generic that you can put directly into your loop() function:

Code: Select all
  int repeat=3600; // in minutes
  int runtime=120; // in seconds
  static time_t t;
 
  // Manual mode
  if (ReefAngel.Relay.isMaskOn(Box1_Port2)) {
    ReefAngel.Relay.Auto(Box1_Port2);
    t=now();
  } 

  if (now()-t < runtime) {
    ReefAngel.Relay.On(Box1_Port2);
  } else {
    ReefAngel.DosingPumpRepeat(Box1_Port2,0,repeat,runtime);   
  } 


Just change Box1_Port2 to whatever port you want to control and then use the repeat and runtime to set how long you want the port to run and how often to repeat. If you don't want it to repeat then just take out the else statement at the end.

Posts: 171
Joined: Fri May 23, 2014 8:09 am
PostPosted: Wed Oct 07, 2015 5:26 pm
Aeesome, i will reply properly when I get back to my computer, don't like typing on the phone!
Image

Posts: 171
Joined: Fri May 23, 2014 8:09 am
PostPosted: Thu Oct 08, 2015 7:23 pm
binder wrote:
paperdesk wrote:I didn't know where to put this for sure, but I guess this would be an app option.

I would like to be able to set a countdown timer to control a relay for a select amount of time. For example, I may want to fill a container with RODI water.

Currently I have a solenoid plugged into a relay. I can toggle the relay on and off to fill the container, but it would be much more convenient to be able to set the relay to be on for 30 minutes, or 60 minutes or whatever I like, then automatically shut off.

Has anyone done this? Is it possible? Is is something anyone else is even interested in?

yes this is possible. this is exactly what the feeding mode and water change modes do (well...water change mode is not a timed feature, but functions the same none the less).

it will require custom code being added. you will need to set the timer duration, ports to toggle and how you want to activate it. i would suggest looking at the feeding mode function inside the libraries to see how we handle it. what we do is retain the state of the existing relays that get toggled and then when the mode is entered, we turn off all the ports that are specified to be turned off and then leave the others alone. once the mode is exited, we return the ports back to their previous state. i'm assuming that you want to force a specific port (or set of ports) on during the function and then return them to their previous state (or force them off) when the function/countdown finishes.

so, let's get you started (i'll help get the questions going and get you started and others will probably chime in as well).

First off, we need to know these questions:
  • How many ports or what ports do you want to toggle?
  • How long do you want the countdown to be? Do you want it to be changeable on the fly (like via a memory location)?
  • How do you want to activate it? Via a virtual relay port, custom variable value, memory location

Now, once we get this information, we can proceed forward with more of the details.


I have only one port I want to toggle.
I would like to be able to change the countdown.
I'd like to control it from the app, not sure what options there are with the app other than toggling the relay.
Image
User avatar
Posts: 2741
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Fri Oct 09, 2015 6:25 pm
ok. using lnevo's sample we can make the app start the countdown by turning the port on.
then we can have it read the countdown value from the internal memory.

Sent from my Moto X

Posts: 166
Joined: Wed Nov 26, 2014 8:53 am
PostPosted: Fri Oct 09, 2015 7:52 pm
Any way to get this out to everyone in an update?

Sent from my XT1254 using Tapatalk
Image
User avatar
Posts: 2741
Joined: Fri Mar 18, 2011 6:20 pm
Location: Illinois
PostPosted: Sat Oct 10, 2015 5:00 am
Lionfan wrote:Any way to get this out to everyone in an update?

Sent from my XT1254 using Tapatalk

well, that would require adding it to the libraries and making it versatile. I know it can be done but I don't know how fast it would get merged. I will see what I can do.

Sent from my Moto X
User avatar
Posts: 5349
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Oct 10, 2015 6:44 am
There's already the TimedPort class that can help with this.
User avatar
Posts: 5349
Joined: Fri Jul 20, 2012 9:42 am
PostPosted: Sat Oct 10, 2015 8:24 am
Code: Select all
TimedPort swabbie;

swabbie.Port=Box1_Port2;
swabbie.StartTime=120; // StartTime is when explicitly triggering the port vs the scheduled usage (Time)
swabbie.Run();

if (ReefAngel.Relay.IsMaskOn(swabbie.Port);
  ReefAngel.Relay.Auto(swabbie.Port);
  swabbie.Start();
}


Although I think I discovered a bug with the Repeat part which may inadvertently cause your port to go on when it shouldn't, but not sure. :) Looking into that. However, that should be available to anyone and there's a lot more functionality in that port.

I had hoped to extend it at some point by having a dosing pump class that would be aware of it's rate and how long it ran for. Curt I'd love if you'd take a look at the class and let me know what you think :)
Next

Return to Apps

Who is online

Users browsing this forum: ReefingHavoc and 4 guests