Introduction: How to Read MPX5010 Differential Pressure Sensor With Arduino
The way I have written the code is such that it can be easily changed to suit a different pressure sensor. Just change the following const variables in the code based on the values from the data sheet for any pressure sensor:
- "sensorOffset" value in mV
- "sensitivity" value in mV/mmH2O
Once i got this pressure sensor, I looked around online to try and find an example code to extract the pressure readings from this sensor into real units of pressure, KPa or cmH2O. I found one sample code for this exact sensor, after running it I noticed the readings were not matching up with what they should be on the datasheet, so I decided to write my own calculation and my own code... it look ages but it works, hurray!! So I thought I would share it with the world so other people won't have to go through the same pain.
Enjoy!!
Supplies
You'll need:
- An MPX5010 pressure sensor (of course)
- An Arduino, Uno or any other
- Some silicon hose (to connect from the pressure sensor to the pressure tap)
- Small cable ties (for securing the silicon hose)
- Small 2mm tube brass or plastic (I used the tube from a WD40 can)
- Some insulation tape (only needed if your silicon hose is too big for your WD40 tube)
Step 1: Connect Circuit
See super easy connection image
Step 2: Connect Up Pressure Sensor
- Connect up your silicon hose to the pressure sensor port, use cable tie if you need it to make a good seal
- Drill a 2mm hole in the pipe you want to sense the air pressure
- Push the WD40 tube into the hole, it should be a really tight fit. Use a little bit of super glue to complete the seal
- Slide your silicon hose over the WD40 tube (I had to wrap insulation tape around the tube to get it to fit). Then add a small cable tie
Step 3: Upload Code
Upload my code to your Arduino, then click on the serial terminal to view the numbers (the button with the magnifier glass symbol in the top right of the screen).
You should see the time in miliseconds, then a ',' then the pressure value.
You have the option in the code of calculating the number in kPa or cmH2O, just comment out the line you don't need.
Add a "delay(500);" if you want to slow down the readings to make them easier to ready on the terminal.
The way I have written the code is such that it can be easily changed to suit a different pressure sensor. Just change the following const variables in the code based on the values from the data sheet for any pressure sensor:
- "sensorOffset" value in mV
- "sensitivity" value in mV/mmH2O
Step 4: Extract Sensor Values to Excel
- Log some readings in your Arduino serial terminal. The should be in the format: "time(ms) , pressure reading"
- Un-plug the USB cable
- Select all the values from your serial terminal and copy
- Paste them into a Notepad
- Click file>save as
- Type in your file name then change the extension to ".csv" (very important) and save it
- Open your file explorer and you should see your file with the Excel logo on it (that means you have correctly made the .csv file)
- Double click on your new .csv file and it will open in Excel and it should have automatically sorted your values into two separate columns and got rid of the comma (that's why .csv files are great!)
Then you can go ahead and make graphs of pressure over time or what ever you want.
BTW: CSV stands for "comma-separated values".
Step 5: Extra Nerdy Bit
Well done for making it this far! This means you have passed the nerd test and as a reward I will tell you some techy details.
So I mentioned at the beginning about a sample code I found for this exact sensor that gave me the wrong values. To check it I used their equation to take calculate a few points on the response graph (attached) from the datasheet and I found that these didn't match up with the graph. So I created my own calculation and I cross referenced it with the graph on the datasheet to prove that it works in theory, then I data-logged readings with both codes and over laid the graphs, which I have attached.
On the attached graphs, the blue line is the example code I found and the red line is my code. The problem is reasonably obvious when looking at the graph because the web example code does not measure 0 at ambient which it should do because we are measuring differential pressure.
Ok so it wan't overly techy after all, sorry to disappoint but hope you enjoyed it anyway :)
8 Comments
Question 8 days ago
Hi Darren,
I am using a similar differential pressure sensor from NXP(MPX2100D) :
When no pressure was applied to any of the sides of the sensor, the sensor should give zero or near zero values for pressure difference but instead, it is giving random values every time. Here is the Arduino Code :
Could you please help me in resolving this issue?
Question 3 years ago
It not clearly define why you use only one hole of pressure u are using where is other
Answer 12 months ago
A differential pressure sensor has 2 barb connectors (holes), it measures the difference in pressure between these 2. If you leave one disconnected then it will simply measure pressure relative to atmosphere, if you connect to the wrong barb then it will just read negative pressure. Alternatively you can buy what’s called a gauge pressure sensor will will only have one barb connection as that is designed to read relative to ambient only. Usually the part numbers from NXP have “DP” for differential pressure and “GP” for gauge pressure.
Reply 7 months ago
So if I connect to the "wrong barb" could I measure vacumm?
Reply 7 months ago
It's been a long time since I have touched these sensors and I don't have one to test so I'm not 100% sure, but I think if you connect to the wrong barb the readings will be reversed, meaning that a positive pressure will make negative numbers on your Arduino. A lot of these pressure sensors will measure a tiny amount of "vacuum" (if that's what you want) which you can see in the graph of figure 4 of step 5 where the "typical" line crosses the y axis before reaching 0, so if your sensor reads in the middle of it's tollerance you will read a little bit of vacuum pressure. But any more detail than that I can't remember sorry.
Question 12 months ago on Introduction
Will this program work with 2 higher pressure sensors?
I need a setup for measuring pressure differential across a filter.
Answer 12 months ago
My program will work with a different sensor but you will need to adapt the code accordingly. As long as it’s a sensor from NXP then all you will need to do is change the “offset” and “sensitivity” values in the code (make sure you use the correct units), I’ve explained this in the description for this Instructables. Is it possible to read multiple NXP sensors using the came code as well.
Reply 12 months ago
You assume I know how to do that. lol
I would like to find someone to help me set up a engine monitor setup with display.