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

  1. Log some readings in your Arduino serial terminal. The should be in the format: "time(ms) , pressure reading"
  2. Un-plug the USB cable
  3. Select all the values from your serial terminal and copy
  4. Paste them into a Notepad
  5. Click file>save as
  6. Type in your file name then change the extension to ".csv" (very important) and save it
  7. 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)
  8. 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 :)