Time off Delay for pump control without using delay

Hi all, I am new to Arduino and have little experience programming. I am working on a pump control for heating and want to have a time off delay timer for the circulators without the use of delay(). There are multiple pumps so a delay() would block the other pumps. I am using the productivity open P1am plc.

this is a snipping of the code.

type or paste covoid loop() {
    //*****DHW****
 
  if (P1.readDiscrete (2,4) == HIGH){
    P1.writeDiscrete (HIGH, 1,4); //DWH PUMP ON
  }
    else
    P1.writeDiscrete(LOW, 1,4);
  //****end switch for heat****
   if (P1.readDiscrete(2,1) || P1.readDiscrete(2,2) || P1.readDiscrete(2,3) ||  P1.readDiscrete(2,4) == HIGH){
      P1.writeDiscrete(HIGH, 1,8);
    }
    else{
      P1.writeDiscrete(LOW, 1,8);
    }de here

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

void loop() {
    //*****DHW****
 
  if (P1.readDiscrete (2,4) == HIGH){
    P1.writeDiscrete (HIGH, 1,4); //DWH PUMP ON
  }
    else
    P1.writeDiscrete(LOW, 1,4);
  //****end switch for heat****
   if (P1.readDiscrete(2,1) || P1.readDiscrete(2,2) || P1.readDiscrete(2,3) ||  P1.readDiscrete(2,4) == HIGH){
      P1.writeDiscrete(HIGH, 1,8);
    }
    else{
      P1.writeDiscrete(LOW, 1,8);
    }

Sorry about the editing issue, I didn't realize ther </> was for code. Thanks for having a look

Please post your full sketch

#include <P1AM.h>


void setup() {
  while(!P1.init()){
  }
}

void loop() {
    //*****DHW****
 
  if (P1.readDiscrete (2,4) == HIGH){
    P1.writeDiscrete (HIGH, 1,4); //DWH PUMP ON
  }
    else
    P1.writeDiscrete(LOW, 1,4);
  //****end switch for heat****
   if (P1.readDiscrete(2,1) || P1.readDiscrete(2,2) || P1.readDiscrete(2,3) ||  P1.readDiscrete(2,4) == HIGH){
      P1.writeDiscrete(HIGH, 1,8);
    }
    else{
      P1.writeDiscrete(LOW, 1,8);
    }

    //*********zone 1,2,3 pump control*********
 //**********************************************
  if ( P1.readDiscrete(2,1) == HIGH){ //zone pump 1
    P1.writeDiscrete(HIGH, 1,1);
  }
  else{
    P1.writeDiscrete(LOW, 1,1);
  }
 //**********************************************
  if ( P1.readDiscrete(2,2) == HIGH){ //zone pump 2
    P1.writeDiscrete(HIGH, 1,2);
  }
  else{
    P1.writeDiscrete(LOW, 1,2);
  }
 //**********************************************
  if ( P1.readDiscrete(2,3) == HIGH){ //zone pump 3
    P1.writeDiscrete(HIGH, 1,3);
  }
  else{
    P1.writeDiscrete(LOW, 1,3);
  }
}

Ideally, the plan is to have the end switch go low while each of the pumps keep water circulating through the boiler for around 60 seconds to prevent the eco from opening.

Not really enough information…
What is the ‘end switch’ ?
When is the delay time ‘started’ ?

The problem appears to besimple, but we can’t kick the dog until we know which dog bit you.

Well, the end switch just turns the boiler on and off. I would like the delay to start as soon as the end switch opens, turns boiler off, that way the water will continues circulating through the heat exchanger for around 60 seconds. The additional pump timing will remove heat from the exchanger and prevent the unit from locking out due to high temperature.

the pump turning off would be:

else{
P1.writeDiscrete(LOW, 1,4);
}

I like that!

Trying to be gentle, but I can’t see the ‘end’ switch defined in your code.

Perhaps you should name your program elements so we know what they are.

BTW, by now, you should be leaning toward a millis() solution.
Because we can’t see the whole program, it will probably be a static timer variable - somewhere near that ‘end’ switch.

  //****end switch for heat****
   if (P1.readDiscrete(2,1) || P1.readDiscrete(2,2) || P1.readDiscrete(2,3) ||  P1.readDiscrete(2,4) == HIGH){
      P1.writeDiscrete(HIGH, 1,8);
    }
    else{
      P1.writeDiscrete(LOW, 1,8);
    }

That's the end switch. When I refer to end switch It's just the contact that "makes" to turn the boiler on and off.

P1-08TRS | P1AM Documentation (facts-engineering.github.io)

This is the output module I am using ^

What you could do in the future - both for to yourself and us… is #define or ‘name’ whatever P1.readDiscrete(2,1) and his friends are…

Yes, we could probably resolve your question now, but why not learn something on the way through.
You don’t pass an exam by attending, you have to add something to the process…

Here’s a start…

// global 
#define minRunDuration (60L * 1000)
—- or —-
const unsigned long minRunDuration (60L * 1000);

unsigned long whenStarted; // keep track of the start event

//****end switch for heat****
   if (P1.readDiscrete(2,1) || P1.readDiscrete(2,2) || P1.readDiscrete(2,3) ||  P1.readDiscrete(2,4) == HIGH){
      whenStarted = millis();
      P1.writeDiscrete(HIGH, 1,8);
    }
    else if (millis() - whenStarted > minRunDuration) {
      P1.writeDiscrete(LOW, 1,8);
    }

I’ll leave the rest to you.

Sorry I had to wait 24 hours before I could post again because I am new. I agree with you 100% about learning something new and thank you for your patients. I attempted to #define P1.readDiscrete(2,4) dhwTT and the compiler had numerous errors. Is it possible they cannot be defined?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.