Advertisement
gabbyshimoni

getPressureAndSpeed-MPXV7002DP

Mar 5th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. int sensorPin = A0;  
  2. int sensorValue = 0;
  3. float Vout=0;
  4. float P=0;
  5. void setup() {
  6.  
  7.   // declare the ledPin as an OUTPUT:
  8.    Serial.begin(9600);
  9. }
  10.  
  11. void loop() {
  12.     int i=0;
  13.     int sum=0;
  14.     int offset=0;
  15.     Serial.println("init...");
  16.     for(i=0;i<10;i++)
  17.     {
  18.          sensorValue = analogRead(sensorPin)-512;
  19.          sum+=sensorValue;
  20.     }
  21.     offset=sum/10.0;
  22.     Serial.println("Ok");
  23.     while(1)
  24.     {
  25.        sensorValue = analogRead(sensorPin)-offset;
  26.        Vout=(5*sensorValue)/1024.0;
  27.        P=(Vout-2.5)*1000; // Pascal          
  28.        Serial.print("dP=" );                      
  29.        Serial.print(P*1000);
  30.        Serial.print("[Pa]");
  31.        Serial.print("   V=" );                      
  32.        Serial.print(sqrt(abs(2*9.81*P/12.26)));
  33.        Serial.println("[m/sec]");
  34.        delay(1000);  
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement