Getting output highs when I should be getting lows

PaulS:
If you take AWOL's advice to move the pin reading/average calculation code into a function, you would call it like so:

void loop()

{
  float voltage = readVoltage(PHOS_IN_A1);
  if( voltage <= 2000 )  //If voltage less than 2V
  {
    digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
  }
  else if( voltage > 2000 )   //If voltage more than 2V
  {
    digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
  }

voltage = readVoltage(BOR_IN_A2);
  if( voltage <= 2000 )  //If voltage less than 2V
  {
    digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
  }
  else if( voltage > 2000 )   //If voltage more than 2V
  {
    digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
  }

voltage = readVoltage(ARS_IN_A3);
  if( voltage <= 2000 )  //If voltage less than 2V
  {
    digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
  }
  else if( voltage > 2000 )   //If voltage more than 2V
  {
    digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
  }
}



which clearly would be a problem, as the timer would be turned on if a gas was flowing, and off if the last gas was not flowing. So, you fix that by adding a flag:


void loop()
{
  bool gasIsFlowing = false;
  float voltage = readVoltage(PHOS_IN_A1);
  if( voltage <= 2000 )  //If voltage less than 2V
     gasIsFlowing = true;

voltage = readVoltage(BOR_IN_A2);
  if( voltage <= 2000 )  //If voltage less than 2V
     gasIsFlowing = true;

voltage = readVoltage(ARS_IN_A3);
  if( voltage <= 2000 )  //If voltage less than 2V
     gasIsFlowing = true;

// If gas is flowing, turn on the timer
  if(gasIsFlowing)
  {
    digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
  }
  else
  {
    digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
  }
}

Cheers Paul. I was just editing my reply as you did this and that is how I was thinking. I have never declared a flag before so I was a bit unsure of where it went etc. I was just digging through my notes while I tried to see what you meant, but it was making sense what I had to do

if( voltage <= 2000 )  //If voltage less than 2V
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else if( voltage > 2000 )

And, of course, if a voltage is not less than or equal to a particular value, it isn't really necessary to test to see if it is greater than that same value.

AWOL:

if( voltage <= 2000 )  //If voltage less than 2V

{
    digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
  }
  else if( voltage > 2000 )



And, of course, if a voltage is not less than or equal to a particular value, it isn't really necessary to test to see if it is greater than that same value.

I thought that mate but when I did my original sketch, my chip latched out and stayed high when I wanted it low. I am learning bit by bit. Work wanted me to use pressure switches on the pneumatics that open the gas vales etc but I wanted to go this way and try to learn a bit more rather than just the brief look I got last year at uni. I know I have gone around the houses a bit and made life difficult for myself but I have learnt some stuff and I am thankfull for your help and advice :slight_smile:

For all my sins fellas. How does this look? Please be gentle

int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 5;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input


void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

void loop()
{

bool gasIsFlowing = false;
float voltage = readVoltage(PHOS_IN_A1);

for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(PHOS_IN_A1);  //Reads phos in pin
aRead = aRead/10;        //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;   //Converts to digital
voltage = voltage*1000;           //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;
}


float voltage = readVoltage(BOR_IN_A2);

for(int i=0; i <10; i++)  //Takes 10 readings
aRead += analogRead(BOR_IN_A2);  //Reads boron in pin
aRead = aRead/10;        //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;  //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

}


float voltage = readVoltage(ARS_IN_A3);

for(int i=0; i <10; i++) //Takes 10 readings
aRead += analogRead(ARS_IN_A3); //Reads arsine in pin
aRead = aRead/10; //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;          //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

}

 // If gas is flowing, turn on the timer
   if(gasIsFlowing)
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else
   {
     digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
   }


for(int i=0; i <10; i++)  //Takes 10 readings
aRead += analogRead(BGA_IN_A4);  //Reads BGA in pin
aRead = aRead/10; //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;          //Converts to millivolts

if( voltage <= 2000 )           //If voltage less than 2V
{
digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
}
else
{
digitalWrite(A_SIDE, LOW);   //Give no output on a side
}


aRead = 0;  //Assumes voltage range from input


for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(BGB_IN_A5);  //Reads BGB in pin
aRead = aRead/10;   //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;  //Converts to digital
voltage = voltage*1000;  //Converts to millivolts

if( voltage <= 2000 )  //If voltage less than 2V

{
digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer

}
else 
{
digitalWrite(B_SIDE, LOW);   //Give no output on B side
}

aRead = 0;  //Assumes voltage range from input
//Debug info to serial console
    Serial.print("Analog: ");  
    Serial.print(aRead);
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}
float voltage = readVoltage(PHOS_IN_A1);

So, where is this function?

for(int i=0; i <10; i++)   //Takes 10 readings
aRead += analogRead(PHOS_IN_A1);  //Reads phos in pin
aRead = aRead/10;        //Takes the average of 10 readings
voltage = (aRead * 5.0)/1024.0;   //Converts to digital
voltage = voltage*1000;           //Converts to millivolts

Why is this still here? It belongs in the function.

I am not sure what I am doing in the function. I have just been speaking to AWOL. I just tried upping my code and it did not like it lol. Suppose as long as I learn from my mistakes then I will get there eventualy

#define N_READINGS 10    // somewhere near the top of your program

// just about anywhere in your program, except inside another function
float readVoltage (int pin)
{
  long aRead = N_READINGS / 2;  //pre-round the result
  for(int i=0; i <N_READINGS; i++)   //Takes 10 readings
    aRead += analogRead(pin);  //Reads phos in pin
  
  aRead = aRead / N_READINGS;        //Takes the average of 10 readings
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;       
}

I am lost now peeps. It is starting to drive me mad

int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 5;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input

#define N_READINGS 10    // somewhere near the top of your program
void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

// just about anywhere in your program, except inside another function
float readVoltage (int pin)
{
  long aRead = N_READINGS / 2;  //pre-round the result
  for(int i=0; i <10; i++)   //Takes 10 readings
    aRead += analogRead(pin);  //Reads phos in pin
  
  aRead = aRead / N_READINGS;        //Takes the average of 10 readings
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;       
}

void loop()
{
   bool gasIsFlowing = false;
   float voltage = readVoltage(PHOS_IN_A1);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;


   voltage = readVoltage(BOR_IN_A2);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;


   voltage = readVoltage(ARS_IN_A3);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;
}
{

   // If gas is flowing, turn on the timer
   if(gasIsFlowing)
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else
   {
     digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
   }

{
float voltage = readVoltage(BGA_IN_A4 );
if( voltage <= 2000 )           //If voltage less than 2V
{
digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
}
else
{
digitalWrite(A_SIDE, LOW);   //Give no output on a side
}

{
float voltage = readVoltage(BGB_IN_A5 );

if( voltage <= 2000 )  //If voltage less than 2V

{
digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer

}
else 
{
digitalWrite(B_SIDE, LOW);   //Give no output on B side
}

aRead = 0;  //Assumes voltage range from input
//Debug info to serial console
    Serial.print("Analog: ");  
    Serial.print(aRead);
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}

Way too many { and } in loop. Try this:

void loop()
{
   bool gasIsFlowing = false;
   float voltage = readVoltage(PHOS_IN_A1);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(BOR_IN_A2);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(ARS_IN_A3);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   // If gas is flowing, turn on the timer
   if(gasIsFlowing)
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else
   {
     digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
   }

   voltage = readVoltage(BGA_IN_A4 );
   if( voltage <= 2000 )           //If voltage less than 2V
   {
      digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
   }
   else
   {
      digitalWrite(A_SIDE, LOW);   //Give no output on a side
   }

   voltage = readVoltage(BGB_IN_A5 );
   if( voltage <= 2000 )  //If voltage less than 2V
   {
      digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer
   }
   else 
   {
      digitalWrite(B_SIDE, LOW);   //Give no output on B side
   }

//Debug info to serial console
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}

Finally managed to get this code into my uno but I am getting absolutely nothing now :frowning:
I am full out of ideas now

int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 5;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input

#define N_READINGS 10    // somewhere near the top of your program
void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

// just about anywhere in your program, except inside another function
float readVoltage (int pin)
{
  long aRead = N_READINGS / 2;  //pre-round the result
  for(int i=0; i <10; i++)   //Takes 10 readings
    aRead += analogRead(pin);  //Reads phos in pin
  
  aRead = aRead / N_READINGS;        //Takes the average of 10 readings
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;       
}

void loop()
{
   bool gasIsFlowing = false;
   float voltage = readVoltage(PHOS_IN_A1);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(BOR_IN_A2);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(ARS_IN_A3);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   // If gas is flowing, turn on the timer
   if(gasIsFlowing)
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else
   {
     digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
   }

   voltage = readVoltage(BGA_IN_A4 );
   if( voltage <= 2000 )           //If voltage less than 2V
   {
      digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
   }
   else
   {
      digitalWrite(A_SIDE, LOW);   //Give no output on a side
   }

   voltage = readVoltage(BGB_IN_A5 );
   if( voltage <= 2000 )  //If voltage less than 2V
   {
      digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer
   }
   else 
   {
      digitalWrite(B_SIDE, LOW);   //Give no output on B side
   }

//Debug info to serial console
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}

Your remaining debug output isn't very useful, it seems to me.
Scatter some more prints around and see what pops out.

const int PHOS_IN_A1 = 1; 
const int BOR_IN_A2 = 2; 
const int ARS_IN_A3 = 3; 
const int BGA_IN_A4 = 4;
const int BGB_IN_A5 = 5;
const int DEP_TIME = 12; 
const int A_SIDE = 11;   
const int B_SIDE = 10;    

#define N_READINGS 10 
void setup()
{
  Serial.begin(9600);  //Serial console for debugging

  pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
  pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
  pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

float readVoltage (int pin)
{
  long aRead = N_READINGS / 2;  //pre-round the result
  for(int i=0; i <N_READINGS; i++)   
    aRead += analogRead(pin);  
  aRead = aRead / N_READINGS;
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;       
}

void loop()
{
   bool gasIsFlowing = false;
   float phosVoltage = readVoltage(PHOS_IN_A1);
   if( phosVoltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;
   Serial.print(" gasIsFlowing:");
   Serial.println(gasIsFlowing ? "true":"false");
   // If gas is flowing, turn on the timer
   digitalWrite(DEP_TIME, gasIsFlowing ? HIGH : LOW); 
 
   float bgaVoltage = readVoltage(BGA_IN_A4 );
   digitalWrite(A_SIDE, bgaVoltage <= 2000 ? HIGH : LOW);   //Gives 5V output to BGA timer
   Serial.print("bgaVoltage:");
   Serial.println(bgaVoltage);
// and so on

I put a few in but I don't understand what I am suppose to be getting out. It is driving me mad now and I seem to be going backwards rather than forwards.
I amended my code to the following

int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 5;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input

#define N_READINGS 10    // somewhere near the top of your program
void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

// just about anywhere in your program, except inside another function
float readVoltage (int pin)
{
  long aRead = N_READINGS / 2;  //pre-round the result
  for(int i=0; i <10; i++)   //Takes 10 readings
    aRead += analogRead(pin);  //Reads phos in pin
  
  aRead = aRead / N_READINGS;        //Takes the average of 10 readings
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;       
}

void loop()
{
   bool gasIsFlowing = false;
   float voltage = readVoltage(PHOS_IN_A1);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(BOR_IN_A2);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(ARS_IN_A3);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;
 Serial.print(" gasISFlowing:");
    Serial.println(gasIsFlowing ? HIGH : LOW);

   // If gas is flowing, turn on the timer
   if(gasIsFlowing = true)
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else
   {
     digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
   }

   voltage = readVoltage(BGA_IN_A4 );
   if( voltage <= 2000 )           //If voltage less than 2V
   {
      digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
   }
   else
   {
      digitalWrite(A_SIDE, LOW);   //Give no output on a side
       Serial.print("BGA_IN_A4:");
    Serial.println(BGA_IN_A4);

   }

   voltage = readVoltage(BGB_IN_A5 );
   if( voltage <= 2000 )  //If voltage less than 2V
   {
      digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer
   }
   else 
   {
      digitalWrite(B_SIDE, LOW);   //Give no output on B side
   }

//Debug info to serial console
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}

The output from the serial monitor I really do not understand. Someone please help :frowning:

 Serial.print(" gasISFlowing:");
    Serial.println(gasIsFlowing ? HIGH : LOW);

This should print "gasIsFlowing: true" or "gasIsFlowing: false", depending on what was read from the gas sensor pins.

      Serial.print("BGA_IN_A4:");
    Serial.println(BGA_IN_A4);

I'm not sure why you are printing the pin number.

    Serial.print(" Voltage:");
    Serial.println(voltage);

Move these into readVoltage(), so you can see the voltage from each of the 5 pins, not just the voltage from the last pin.

Show us the output.

Right peeps, heres what I changed the code with, with all the serial parts. I am totally lost now but determined not to give up

int PHOS_IN_A1 = 1; //Declares an integer of Phos input
int BOR_IN_A2 = 2;  //Declares an integer of Boron input
int ARS_IN_A3 = 3;  //Declares an integer of Arsine input
int BGA_IN_A4 = 4;  //Declares an integer of BGA input
int BGB_IN_A5 = 5;  //Declares an integer of BGB input
int DEP_TIME = 12;  //Declares an integer of Dep timer
int A_SIDE = 11;    //Declares an integer of BGA timer
int B_SIDE = 10;    //Declares an integer of BGB timer

long aRead = 0;  //Assumes voltage range from input

#define N_READINGS 10    // somewhere near the top of your program
void setup()
{
Serial.begin(9600);  //Serial console for debugging

pinMode(DEP_TIME, OUTPUT);  //Sets dep timer as an output
pinMode(A_SIDE, OUTPUT);    //Sets BGA as an output
pinMode(B_SIDE, OUTPUT);    //Sets BGB as an output
}

// just about anywhere in your program, except inside another function
float readVoltage (int pin)
{
  long aRead = N_READINGS / 2;  //pre-round the result
  for(int i=0; i <10; i++)   //Takes 10 readings
    aRead += analogRead(pin);  //Reads phos in pin
  
  aRead = aRead / N_READINGS;        //Takes the average of 10 readings
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;    
  Serial.print(" Voltage:");
    Serial.println(voltage);  
}

void loop()
{
   bool gasIsFlowing = false;
   float voltage = readVoltage(PHOS_IN_A1);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(BOR_IN_A2);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;

   voltage = readVoltage(ARS_IN_A3);
   if( voltage <= 2000 )  //If voltage less than 2V
      gasIsFlowing = true;
      
        Serial.print(" Voltage:");
    Serial.println(voltage);

   // If gas is flowing, turn on the timer
   if(gasIsFlowing = true)
   {
     digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
   }
   else
   {
     digitalWrite(DEP_TIME,  LOW) ;   //Gives no output if no gasses are flowing
   }

   voltage = readVoltage(BGA_IN_A4 );
     Serial.print(" Voltage:");
    Serial.println(voltage);
   if( voltage <= 2000 )           //If voltage less than 2V
   {
      digitalWrite(A_SIDE, HIGH);   //Gives 5V output to BGA timer
   }
   else
   {
      digitalWrite(A_SIDE, LOW);   //Give no output on a side
         Serial.print(" A_SIDE:");
    Serial.println(A_SIDE);
    
   }

   voltage = readVoltage(BGB_IN_A5 );
   if( voltage <= 2000 )  //If voltage less than 2V
   {
      digitalWrite(B_SIDE, HIGH); //Gives 5V output to BGB timer
   }
   else 
   {
      digitalWrite(B_SIDE, LOW);   //Give no output on B side
       Serial.print(" B_SIDE:");
    Serial.println(B_SIDE);
      
   }

//Debug info to serial console
    Serial.print(" Voltage:");
    Serial.println(voltage);

    delay(1000);  //1 sec delay between measurements
}

And here is what I got from the serial monitor with nothing connected to the board apart from the usb

Voltage:2143.55
Voltage:2402.34
A_SIDE:11
B_SIDE:10
Voltage:2988.28
Voltage:2036.13
Voltage:2319.34
A_SIDE:11
B_SIDE:10
Voltage:2998.05
Voltage:1923.83
Voltage:2216.80
A_SIDE:11
B_SIDE:10
Voltage:2993.16
Voltage:1811.52
Voltage:2089.84
A_SIDE:11
B_SIDE:10
Voltage:2924.80
Voltage:1713.87
Voltage:1962.89
B_SIDE:10
Voltage:2822.27
Voltage:1948.24
Voltage:1708.98
Voltage:1738.28
Voltage:2163.09
Voltage:2426.76
A_SIDE:11
B_SIDE:10
Voltage:2778.32
Voltage:1962.89
Voltage:2275.39
A_SIDE:11
B_SIDE:10
Voltage:2895.51
Voltage:1831.05
Voltage:2119.14
A_SIDE:11
B_SIDE:10
Voltage:2866.21

A_SIDE and B_SIDE are both program constants, so there's no real need to keep printing them out.
OToH, telling which voltage is which is very difficult from your printout.
That is easily fixed.

   if(gasIsFlowing = true)

Needs ==, not =.

        Serial.print(" Voltage:");
    Serial.println(voltage);

You are printing the voltage in the function. It is redundant to print it here in loop() again.

   else
   {
      digitalWrite(A_SIDE, LOW);   //Give no output on a side
         Serial.print(" A_SIDE:");
    Serial.println(A_SIDE);
    
   }

I fail to understand why you are printing the pin number if the BGA_IN_A4 voltage is greater than 2. What does that tell you?

Paul to be honest, I have no idea what I am doing with this serial monitor. AWOl suggested I just have a mess around and see if I can get to grips with what I am doing. Put bits in here and there to see if I can work things out. I will be honest and admit that I am a bit lost with things at the minute but nothing worthwhile in life ever comes easy does it?
I will have another bit of a mess and see how things go.
I feel like I owe you an awol a few pints already lol :slight_smile:

I will be honest and admit that I am a bit lost with things at the minute but nothing worthwhile in life ever comes easy does it?

No, it doesn't. And it does get easier. Perhaps the thing to do it to post your code, line by line, with your understanding of what each line does. We can correct any misunderstandings, and explain anything you don't understand. For example:

float readVoltage (int pin)

Defines a function that take s pin number, and returns a float

{

The start of the function block

  long aRead = N_READINGS / 2;  //pre-round the result

Not sure what you are doing here. I would have initialized aRead to 0

  for(int i=0; i <10; i++)   //Takes 10 readings

The comment says it all.

    aRead += analogRead(pin);  //Reads phos in pin

Read from the pin, and add the reading to aRead.

  aRead = aRead / N_READINGS;        //Takes the average of 10 readings
  float voltage = (aRead * 5.0)/1024.0;   //Converts to digital
  return voltage*1000;    
  Serial.print(" Voltage:");
    Serial.println(voltage);  
}

Add your comments the rest of the way through...

By the way, the Voltage: nnnn.nn output that the last two line should print will never happen, since they are placed AFTER the return statement.

Thank you very much Paul. I would really appreciate it if you would do that for me. I will dismantle it line by line and go through what I think is happening

Not sure what you are doing here. I would have initialized aRead to 0

The comment makes it clear.
The code is about to average a number of readings; this line makes sure the average is rounded.