Timer or Countdown

Hi

We have a interactive station in our museum for our small visitors. The Arduino controls a pump for a liquid. The pump is directly controlled by a push-button "drop". With a push-button "manu" we can purge the whole system when it is filled by air.

Now I have to adapt the code and don't know how! :confused:

If the system isn't used for 15 minutes the pump should start for 2 seconds. Also when the push-button "drop" isn't pressed for 15minutes the pump should be activated for 2 seconds. If the push-button "drop" is pressed in the 15min the countdown/timer should start from the beginning. How can i do this?!

I hope you can give me some advice. And sorry about my bad english - i hope you understand my problem!

/*
* The push-button (manu) will activate the pump (pump) and keeps it high as long as the button is pressed.
* The pump should be activated for 2 seconds if the push-button (drop) isn't pressed for 15 minutes.
*/


int pump = 3;  //output pump

int drop = 5; //drop
int manu = 7; //manual purge

int ledPin = 13; //control led




void setup() 
{
 pinMode(drop, INPUT_PULLUP);
 pinMode(manu, INPUT_PULLUP);

 pinMode(pump, OUTPUT); 
 pinMode(ledPin, OUTPUT);

 digitalWrite(pump, LOW);
 digitalWrite(ledPin, LOW);
}

void loop() 
{

 if (digitalRead(manu) == LOW)
 {
   digitalWrite(pump, HIGH);
   digitalWrite(ledPin, HIGH);
 }

 if (digitalRead(manu) == HIGH)
 {
   digitalWrite(pump, LOW);
   digitalWrite(ledPin, LOW);
 }

}

If the system isn't used for 15 minutes the pump should start for 2 seconds.

When was the system last used? You MUST keep track of this.

Where do you suppose that you should check this? At the very least, there should be a comment in the code that shows you have a clue.

Turning a pin on, twiddling your thumbs for 2 seconds, and turning a pin off is trivial. Doing so after 15 minutes of inactivity is simple.

Also when the push-button "drop" isn't pressed for 15minutes the pump should be activated for 2 seconds.

How does this requirement differ from the previous one?

If the push-button "drop" is pressed in the 15min the countdown/timer should start from the beginning.

Once you understand how to implement the first requirement, you'll see that this requirement is like saying "the red LED must be red".

By the way, that is NOT how to post code. Clearly, you did not bother to read the stickies at the top of the forum. Take time to do so, and fix your post.

thx Paul

PaulS: When was the system last used? You MUST keep track of this.

The system is always used for the last time when the push-button "drop" was used by a visitor. That's why i think i need a countdown or something like this.

PaulS: By the way, that is NOT how to post code. Clearly, you did not bother to read the stickies at the top of the forum. Take time to do so, and fix your post.

Sorry about that! I fixed it! It's my second post! I'm still learning! ;)

But now I still have no idea how to fix my problem with some code...

Have a look at planning and implementing a program. As well as suggestions for organization it illustrates how to use millis() for timing. And some of the concepts in the code are likely to be relevant to your project.

...R

The system is always used for the last time when the push-button "drop" was used by a visitor.

Hello. What time was that?

That's why i think i need a countdown or something like this.

Do you need a "countdown or something like this" to know what time you got up this morning?

But now I still have no idea how to fix my problem with some code...

Well, here's a hint: millis()