Serial Monitor and sd card values are not the same

Hello ,

I am trying to write data to sd card. But the sd card values and the serial monitor values are not matching!
Can anyone tell me the reason?

Thank you!

Maybe because you call getPressure() twice, once for Serial and once of SD?

Might be better to read once and store in a variable and write the variable to both SD and Serial.

(deleted)

You call getPressure() once for the serial output and once for the write to the SD card. If the two values are inside the measurement error range they should be taken as equal.

If you want to have identical values, call getPressure() just once, store it in a variable and write that to the serial interface and the SD card.

int solenoidPin = 4;You gave the pin a nice name.
Why don't you use it?

There are only two places in the code where the valve is turned off with digitalWrite(4,LOW).

First Instance

if ( solstate == true && doneitonce == true && timerRunning == true && millis() - initialTime >= openTime)
  {
    Serial.print("\tenteredloop\t");
    Serial.print(solstate);
    digitalWrite(4, LOW);
    solstate = false;
    Serial.print("OFF  ");
    Serial.println(solstate);
    timerRunning = false;  
  }

Second Instance

if ( solstate == true && millis() - startTime >= interval)
        {
          digitalWrite(4, LOW);
          solstate = false;
          peakcounter = 0;
        }

The second instance is activated before the first. The second instance is nested within this conditional which is wrongly written. Try fixing this and see if the valve doesn't stay open for the 5 seconds.

 //if (doneitonce = true && solstate == false)
 if (doneitonce == true && solstate == false)

If that doesn't fix it, then try change the condition on the valve shut off to accommodate the initial timer

if (timerRunning== false && solstate == true && millis() - startTime >= interval)
        {
          digitalWrite(4, LOW);
          solstate = false;
          peakcounter = 0;
        }

Some of your cocditions are over specified and make the logic confusing. For example this could be simplified

//if ( solstate == true && doneitonce == true && timerRunning == true && millis() - initialTime >= openTime)
if (timerRunning == true && millis() - initialTime >= openTime)

Did you do this?

If that doesn’t fix it, then try change the condition on the valve shut off to accommodate the initial timer

Code: [Select]
if (timerRunning== false && solstate == true && millis() - startTime >= interval)
{
digitalWrite(4, LOW);
solstate = false;
peakcounter = 0;
}

Please post your code.

if ( timerRunning == true && millis() - initialTime >= openTime)
if (doneitonce == true && solstate == false)

Isn't camelCase great? Why did you abandon it part way through writing the code?

doneitonce is way harder to read and decipher than doneItOnce. It is NO easier to type.

Please stick with camelCase.

It opens for 5.75 sec and then stays open!

I don't understand that statement.

Does it open for 5.75 seconds in the initial sequence, and then close? Do you see the serial print "OFF 0"?
Then when it reopens again it does not close after interval = 500ms.

What else do your serial prints tell you?

You've been through this before. You should add more serial prints to your code until you can see all the states and logical conditions to understand why you don't enter a conditional statement.