Last active
May 18, 2017 09:21
-
-
Save didasy/5e06c9c190ef346f2ba661024eb5236a to your computer and use it in GitHub Desktop.
MPX5700AP to PSI for Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| float getPressure(int raw) { | |
| // raw 0-1023, get from analogRead(); | |
| // 0.004887586 is from 5v/1023 | |
| // General info: | |
| // range of voltage reading is 0V-5v | |
| // the sensor outputs 0V or +ZPO to (0v or ZPO)+4.5V, while the range is 4.587v - 4.7v - 4.813v | |
| // each KPa is 6.4mV or 0.0064V | |
| float voltage = raw * 0.004887586; | |
| // Initializing pressure variable as float | |
| float pressure = 0.0; | |
| // 0.184v to 0.409 ZPO, we choose the middle one | |
| float zeroPressureOffset = 0.2965; | |
| // 0-4.6v reads 0-700KPa, the rest is 100KPa over 0.3V | |
| if (voltage < 4.6) { | |
| // pressure = voltage * 700.0/4.6; it raises 700KPA over 4.6 volt | |
| // with compensation: pressure = (voltage - zeroPressureOffset) * 700.0/4.6; | |
| // without compensation: pressure = voltage * 152.173913; | |
| pressure = (voltage - zeroPressureOffset) * 152.173913; | |
| } else { | |
| pressure = 700.0 + (voltage-4.6) * (100.0 / 0.3); | |
| // last piece raises 100KPa over 0.3 Volt. | |
| // can be optimized to p = c1 + v * c2 | |
| } | |
| return pressure * 0.145037738; // convert KPa to PSI | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment