Read analog input and turn on relay for 30 minutes without using delay

HI,

I am making device which needs to turn on relay and keep running it for 30 minutes after some analog pin reads less voltage. I don’t want to use delay to achieve 30 minutes because arduino is dead for that time, and it can not react if state on that analog pin changes

Here is my version of code:

int led =13;      //signalna led dioda
int pumpa =10;   //izlaz za pumpu
#include "Timer.h"
 
Timer t;

float vout = 0.000;    // 
float vin = 0.000;    //
float R1 = 100000.0; // Otpornost R1 (100K)   ovaj delitelj za napone do 30v
float R2 = 10000.0; // Otpornost R2 (10K)     ovaj delitelj za napone do 30v
int value = 0.00;

void setup() {
///////////
// setup //
///////////
  
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(pumpa, OUTPUT);
t.pulse(pumpa, 30 * 60 * 1000, HIGH); // 30 minutes

digitalWrite(led, HIGH);
//digitalWrite(pumpa, HIGH);
delay(100);

}

void loop() {
Serial.println (vin);   //ispiši i pošalji vrednost napona na serijski port


value = analogRead(A0);   //pročitaj vrednost napona na portu A0
vout = (value * 5.0) / 1024.0; // izračunaj vrednost napona 
vin = vout / (R2/(R1+R2)); 
            
/////////////
//  USLOV  //
/////////////

if (vin < 05.00)       //Isključi rele na portu 10 ako je napon na portu A0 manji od 5v
{
 
 t.update();
 digitalWrite(led, HIGH);    // uključi signalnu LED


}
else if (vin > 05.00)  //Uključi rele na portu 10 ako je napon na portu A0 veći od 5v
{
 t.stop(pumpa);
 digitalWrite(led, LOW);
 digitalWrite(pumpa, LOW);

 }
 
  delay(1000);
}

Problem is that this does not work,
Any suggestion?

Regards

zoomtronic

I don't wanna use delay

But . . . you do!delay(1000);

Look at the blink without delay example in the IDE to see how to time events without using delay().

Yes I do use it for one second, but I don't want to use it for 30 minutes

Get the code right, and you don't need to use it all.

(BTW, we say "want to", not "wanna")

Ok, thanks for writing correction

'millis()' is easy enough to use without the "Timer" library, but if you still want to use it, I think you need to move 't.update();' out of the 'if' conditional statement to the main body of the 'loop()' function.