How to read Sensor values during pausing?

Hello, i just started with arduino. And as many i started with indoor watering system. :smiley:
I have a one water pump which feed my solenoid valves. Depending on the value from the sensor, arduino opens valve that belongs to that moisture sensor.
After reading the values from the sensors and watering i want to pause that cycle for like 1 hour before another sensor reading and so on. Beside this i wanted to add a crystal liquid display to disp. the values from the sensors. But i am not able to read this values because that 1 hour delay. So my question is, is there a way to having this 1 hour delay for my solenoids but at the same time turning on the display to read the values any time i want?

Thank you kindly for any help or advice :slight_smile:

  • my code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
// vents
const int LED1 = 13;
const int LED2 = 12;
const int LED3 = 11;
const int LED4 = 10;
// soil moisture sens.
const int SENS1 = A2;
const int SENS2 = A1;
const int SENS3 = A0;
const int SENS4 = A3;
// pump
int const HG = 2;
// const. for moisture sensors
int const DRY_C1 = 361;
int const DRY_C2 = 336;
int const WET_C1 = 250;
int const WET_C2 = 246;
int const DRY_C3 =388;
int const DRY_C4 =305;
int const WET_C3 =251;
int const WET_C4 =240;
const int z = 10000;
void setup() {
pinMode(SENS1,INPUT);
pinMode(SENS2,INPUT);
pinMode(SENS3,INPUT);
pinMode(SENS4,INPUT);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(HG,OUTPUT);
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
}
void loop() {
int C1 = analogRead(SENS1);
int C2 = analogRead(SENS2);
int C3 = analogRead(SENS3);
int C4 = analogRead(SENS4);
int H1 = map(C1,WET_C1,DRY_C1,100,0);
int H2 = map(C2,WET_C2,DRY_C2,100,0);
int H3 = map(C3,WET_C3,DRY_C3,100,0);
int H4 = map(C4,WET_C4,DRY_C4,100,0);
lcd.init();
lcd.backlight();

if (C3>DRY_C3){
lcd.setCursor(0,0);
lcd.print(0);
lcd.setCursor(4,0);
lcd.print("=H3[%]");
lcd.setCursor(11,0);
lcd.print(C3);
}
else if (C3<WET_C3){
lcd.setCursor(0,0);
lcd.print(100);
lcd.setCursor(4,0);
lcd.print("=H3[%]");
lcd.setCursor(11,0);
lcd.print(C3);
}
else{
lcd.setCursor(0,0);
lcd.print(H3);
lcd.setCursor(4,0);
lcd.print("=H3[%]");
lcd.setCursor(11,0);
lcd.print(C3);
}
if (C2>DRY_C2){
lcd.setCursor(0,1);
lcd.print(0);
lcd.setCursor(4,1);
lcd.print("=H2[%]");
lcd.setCursor(11,1);
lcd.print(C2);
}
else if (C2<WET_C2){
lcd.setCursor(0,1);
lcd.print(100);
lcd.setCursor(4,1);
lcd.print("=H2[%]");
lcd.setCursor(11,1);
lcd.print(C2);
}
else{
lcd.setCursor(0,1);
lcd.print(H2);
lcd.setCursor(4,1);
lcd.print("=H2[%]");
lcd.setCursor(11,1);
lcd.print(C2);
}
if (C1>DRY_C1){
lcd.setCursor(0,2);
lcd.print(0);
lcd.setCursor(4,2);
lcd.print("=H1[%]");
lcd.setCursor(11,2);
lcd.print(C1);
}
else if (C1<WET_C4){
lcd.setCursor(0,2);
lcd.print(100);
lcd.setCursor(4,2);
lcd.print("=H1[%]");
lcd.setCursor(11,2);
lcd.print(C1);
}
else {
lcd.setCursor(0,2);
lcd.print(H1);
lcd.setCursor(4,2);
lcd.print("=H1[%]");
lcd.setCursor(11,2);
lcd.print(C1);
}
if (C4>DRY_C4){
lcd.setCursor(0,3);
lcd.print(0);
lcd.setCursor(4,3);
lcd.print("=H4[%]");
lcd.setCursor(11,3);
lcd.print(C4);
}
else if (C4<WET_C4){
lcd.setCursor(0,3);
lcd.print(100);
lcd.setCursor(4,3);
lcd.print("=H4[%]");
lcd.setCursor(11,3);
lcd.print(C4);
}
else {
lcd.setCursor(0,3);
lcd.print(H4);
lcd.setCursor(4,3);
lcd.print("=H4[%]");
lcd.setCursor(11,3);
lcd.print(C4);
}
// H3 ///////////////////////////////
if (H3<35){

digitalWrite(HG,HIGH);
digitalWrite(LED1,LOW);// open
delay(z);
digitalWrite(LED1,HIGH); // close
digitalWrite(HG,LOW); // close
}
else{
digitalWrite(HG,LOW);
digitalWrite(LED1,HIGH);
}
// H4 ///////////////////////////////
if (H4<35){

digitalWrite(LED2,LOW);// open
digitalWrite(HG,HIGH); // open
delay(z);
digitalWrite(LED2,HIGH); // close
digitalWrite(HG,LOW); // close
}
else {
digitalWrite(HG,LOW);
digitalWrite(LED2,HIGH);
}
// H2 ///////////////////////////////
if (H2<35){

digitalWrite(LED3,LOW);
digitalWrite(HG,HIGH);
delay(z);
digitalWrite(LED3,HIGH);
digitalWrite(HG,LOW);
}
else{
digitalWrite(HG,LOW);
digitalWrite(LED3,HIGH);
}
// H1 ///////////////////////////////
if (H1<40){

digitalWrite(HG,HIGH);
digitalWrite(LED4,LOW);
delay(30000);
digitalWrite(LED4,HIGH);
digitalWrite(HG,LOW);
}
else{
digitalWrite(HG,LOW);
digitalWrite(LED4,HIGH);
}
delay(3600000UL);
}

Hello, well i am also a begineer here but I think you can separate the differents sensor into a void for each one, doing the sensing and in the void loop just call them when applies, do a while-for with a counting time before call it again. I hope it will works for you.

what do you mean by "read the values"? aren't they being displayed during the delay?

there are several ways this code could be improved

  • the sensors could be managed in arrays
  • a table of structs can be used to define display positions and formats
  • managing the solenoids and different delays could be managed using millis()

but it looks like the code does what your asking

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