I am using Arduino to: read analog Pressure Sensor. then control Pump and Valve if its more than 800 stop Pump and Valve... start timer for 5 seconds then turn on Valve. if its less than 200 stop Pump and Valve... start timer for 3 seconds then turn on Pump. if its between 800 and 200 before timer do the job... stop / reset timer and continue old job (if pump is on or valve is on)
Your thought process seems to start in the future and time runs backward until the present.
Start your thought process here:
You have just turned power ON and pressure is less than 100.
How i can do it ? because pressure sensor will break. i need to turn pump off in pressure more than 80% and turn off valve in pressure less than 20% ...
after low pressure first turn off the valve... then start timer ... then turn on pump.
after high pressure first turn off the pump... then start timer ... then turn on valve.
I have run the last code you edited. not sure whats happening
didn't turn off pump in the more than 80% pressure before timer.
didn't turn off valve in the less than 20% pressure before timer.
valve is on in pressure less than 20% and pump is on in more than 80 before timer. please let me know how to turn it off before timer enabled.
i am so confused
Set up a couple variables such as previous milli and current milli.. Before the the loop, set millis() as the "previous millis". If you then set millis() as the "current millis" you now have a time difference. Then all you need to do is have a variable set point defined and something along the lines oif if Current Millis - Previous Millis >= X, then do something. Much easier to control than a delay since that is no matter what going to delay for X amount of time whether the value of the sensor goes lower than threshold or not.
Is this a pump that could be controlled with a PLC? If so try an open source like Open PLC that works with arduino. I'd try and stick with discreet I/O if you can. Look at www.a2btransportsystems.com for some sensors that may work.