No negative values

Hi: How can I modify the code below so that when 'Serial.print (Nread)' (see code below, near bottom) is negative, then it will simply just show zero parts per billion instead (ppb)? I have an NO2 sensor and when gas concentrations are very low, it sometimes gives a negative reading.

Thanks

const float R0 = 59324;

int Tinput = A5;
int Hinput = A4;
int Ninput = A1;
int Cinput = A3;
void setup()
{
Serial.begin(9600);
}
void loop()
{
float T0 = (analogRead(Tinput));
float H0 = (analogRead(Hinput));
float N0 = (analogRead(Ninput));
float C0 = (analogRead(Cinput));
delay(10);
float T1 = (analogRead(Tinput));
float H1 = (analogRead(Hinput));
float N1 = (analogRead(Ninput));
float C1 = (analogRead(Cinput));
delay(10);
float T2 = (analogRead(Tinput));
float H2 = (analogRead(Hinput));
float N2 = (analogRead(Ninput));
float C2 = (analogRead(Cinput));
delay(10);
float T3 = (analogRead(Tinput));
float H3 = (analogRead(Hinput));
float N3 = (analogRead(Ninput));
float C3 = (analogRead(Cinput));
delay(10);
float T4 = (analogRead(Tinput));
float H4 = (analogRead(Hinput));
float N4 = (analogRead(Ninput));
float C4 = (analogRead(Cinput));
float Tavg = ((T0+T1+T2+T3+T4)/5);
float Tread = (((Tavg5.0)/1023)-0.53375)/(9.33/1000) - 7.34 ; //7.34 is an offset determined by unplugging all the other sensors
float Havg = ((H0+H1+H2+H3+H4)/5);
float Hread = ((Hm
5000Havg)/1023000)+Hc;
float Navg = ((N0+N1+N2+N3+N4)/5);
float Nread = (170687550/(R0
Navg))-(166850/R0)-18.22;
float Cavg = (C0+C1+C2+C3+C4)/5;
float Cread = (4.0Cavg2000)/1023;
//
Serial.print(Tread);
Serial.print("deg C, ");
Serial.print(Hread);
Serial.print(" %, ");
Serial.print(Nread);
Serial.print(" ppb, ");
Serial.print(Cread);
Serial.println(" ppm");
delay(960);
}

if (Nread < 0) {
   Nread = 0;
}

…R

Robin2:

if (Nread < 0) {

Nread = 0;
}




...R

Alternately,

max(0, Nread);

If you want to limit both ends:

constrain(Nread, 0, <high_limit>);

thanks

Or yet another way with a conditional expression:

Serial.print(Nread < 0.0 ? 0.0 : Nread);

The correct divisor is 1024.

To compute an average, you do not need to store each value then add them up when you are finished. You can store a running total and do the division at the end.