How to retrieve data simultaneous from three sensors and create a loop system?

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);
}

Welcome to the forum

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

1 Like

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

1 Like

What are these lines supposed to do?

You now understand the problem of using delay() to time events -- the microprocessor can't do anything else during delay.

Instead, you do all the timing and decision making using the built in millisecond timer. Avoid delay(), as explained in this Blink without Delay tutorial, then look for the tutorials on "How to do several things at once".

These are all the sensor data lines connected to the Arduino uno board.

multi things

1 Like

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