How to Read MPX5010 Differential Pressure Sensor With Arduino

by Darren Lewis in Circuits > Arduino

30267 Views, 16 Favorites, 0 Comments

How to Read MPX5010 Differential Pressure Sensor With Arduino

MPX5010.JPG

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)

Connect Circuit

LM35-Temperature_bb-1.png
image0.jpeg

See super easy connection image

Connect Up Pressure Sensor

image1 (2).jpeg
image2.jpeg
image3 (1).jpeg

  • 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

Upload Code

MPX5010 Arduino code.JPG
Arduino serial terminal.JPG

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

Extract Sensor Values to Excel

Arduino serial terminal.JPG
notepad.JPG
csv.JPG
excel.JPG

  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".

Extra Nerdy Bit

graph.JPG
datasheet graph.JPG

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 :)