Hi, I'm kind of new to Arduino coding and some help would be appreciated.
So basically my work consists of a solenoid valve operating at negative pressure. Here there is a two pressure sensors at the either ends of the valve, where when one of the sensor reaches a certain pressure, the valve opens to the other side. The issue starts here, I want the valve to stay open for 7 seconds and also during this time interval I want the second pressure sensor to give out reading and also there is a laser gauge in the second region which need to take reading during the time interval (serial output). The code I'm using doesn't seems to stay open for 7 sec and not getting data as well. Any help would be appreciated. I'm attaching my current code below.
// int sensors
int sensorA1=analogRead(A1);
int sensorA3=analogRead(A5);
int relay_pin=digitalRead(13);
int lasergauge_read=digitalRead(1);
void setup() {
Serial.begin(19200);
}
void loop(){
while(!Serial)
// Sensor A1 read and print
Serial.print("Sensor Value (A1): ");
Serial.print(analogRead(A1));
float voltageA1 = (analogRead(A1)*5.0)/1024.0;
Serial.print(" Volts:(A1) ");
Serial.print(voltageA1);
float pressure_pascalA1 = (0.505*((float)voltageA1-1))*1000000.0;
float pressure_barA1 = pressure_pascalA1/10e5;
Serial.print(" Pressure before solenoid (A1) = ");
Serial.print(pressure_barA1);//plotting data
Serial.println(" bars");
if (pressure_barA1<=0.32)// Pressure read when pressure below specific value.
{
digitalWrite(13, HIGH);
Serial.print("Sensor Value (A5): ");// Sensor A3 read and print, triggering of the second sensor for reading value.
Serial.print(analogRead(A5));
float voltageA5 = (analogRead(A5)*5.0)/1024.0;
Serial.print(" Volts:(A5) ");
Serial.print(voltageA5);
float pressure_pascalA5 = (0.505*((float)voltageA5-1))*1000000.0;
float pressure_barA5 = pressure_pascalA5/10e5;
Serial.print(" Pressure at chamber (A5) = ");
Serial.print(pressure_barA5);// plotting data
Serial.println(" bars");
Serial.print("Rise of Test Material/Subject = ");// Input of laser gauge reading.
Serial.print(digitalRead(1));
Serial.println(" mm");
delay (7000);
Serial.print("Presure=>0.3 waiting 7 sec");
} else
digitalWrite(13, LOW);
delay (7000);
}