Monday, 17 April 2017

Using the MPX7002DP Differential Pressure Sensor with an Arduino Uno

Recently I started to design an open source medical device for use by doctors and medical professionals to treat various respiratory disorders.  The post is here:

Multi-functional Medical Device

As part of that I bought a differential pressure sensor breakout board which uses the MPX7002DP differential pressure sensor made by NXP.  The datasheet for the sensor is here:

MPX7002DP Datasheet

The sensor itself can be bought from various online electronics vendors including:

Farnell Electronic Components - Part Number 2080499

RS Components - Part Number 719-1197

The pressure sensor breakout board itself looks like this:

Connecting this to a microcontroller development board like the arduino uno is very simple.  The underside of the PCB contains silk screen which gives the information:

The only thing I don't particularly like about this breakout board is that the wires are not colour coded.  It makes it awkward to wire the breakout board up!  If there are different signals on the wires then use different colours!

Here is the Connection Diagram for those who prefer pictures:
For people who prefer text:

GND connects to GND on the Arduino Uno
+5V connects to +5V on the Arduino Uno
Analog connects to A0 on the Arduino (Or any analogue pin as required)

Here is a picture of my setup - Ignore the Liquid Crystal Display:

Once the connections have been made it's time to write the code which will read the pressure sensor into the arduino.  Reading the datasheet for the sensor gives the designer the information needed to use this sensor:

Lets discuss what the operating characteristics tell us:

  • The pressure range is from -2 kPa (Vacuum) to +2 kPa (Positive Pressure).  So we need to convert the Raw ADC output to account for that.  1023 bits divided by 4000 Pa is the conversion factor assuming the sensor is accurate and no other noise creeps in.
  • The sensitivity is 1 Volt / pA - so we can check our measurement data if needed.
  • The response time is 20 ms - that means there needs to be a 20 ms delay between each sensor read.

The code has to do several things and to make things easier lets draw a quick flow diagram:
From the diagram it should be pretty simple to write up some code to get this working - The code I wrote is below:

 // MPX7002DP Test Code  
 // A.Lang - 2017  
 // This code exercises the MPX7002DP  
 // Pressure sensor connected to A0  
 int sensorPin = A0;  // select the input pin for the Pressure Sensor  
 int sensorValue = 0;  // variable to store the Raw Data value coming from the sensor  
 float outputValue = 0; // variable to store converted kPa value   
 void setup() {  
  // start serial port at 9600 bps and wait for port to open:  
  while (!Serial) {  
   ; // wait for serial port to connect. Needed for native USB port only  
  pinMode(sensorPin, INPUT);  // Pressure sensor is on Analogue pin 0  
 void loop() {  
  // read the value from the sensor:  
  sensorValue = analogRead(sensorPin);  
  // map the Raw data to kPa  
  outputValue = map(sensorValue, 0, 1023, -2000, 2000);  
  // print the results to the serial monitor:  
  Serial.print("sensor = " );  
  Serial.print("\toutput = ");  
  // wait 100 milliseconds before the next loop  
  // for the analog-to-digital converter and  
  // pressure sensor to settle after the last reading:  

It should be fairly self-explanatory.

  • The sensor output will be connected to analogue pin A0.  The actual data will be stored as an integer value in a variable called sensorPin.
  • The raw converted analogue data will be stored in an integer variable called sensorValue.
  • The converted output data in kPa will be stored in a float variable called outputData.
  • In the Setup Function the serial communications are initialised and the sensorPin variable is declared as an input.
  • In loop function the sensor data is read in from the analogue pin and mapped to a kPa value.
  • The data is then sent to the serial terminal so it can be reviewed.
  • A delay of one hundred milli-seconds is introduced to allow the system to settle.
  • Then the whole process repeats for ever!

Here is a video of the circuit in action.

The output of the sensor was actually very sensitive, more so than I anticipated and will work well for the application.  The next thing to do is to output the serial data directly to an external program so that it can be graphed which provides a much more visual and useful display.  After that the serial communications can be converted to bluetooth and then the data can be sent to a mobile phone or again to a PC but the system can be made battery powered and therefore truly wire free!

Take care people - Langster!