Project showcase
Create a Diving Computer with an MS5803–01BA Pressure Sensor

Create a Diving Computer with an MS5803–01BA Pressure Sensor

Now we can check out the depth of the sea level by using a pressure sensor (MS5803–01 BA) connected to an Arduino, and display sensor data.

  • 1,202 views
  • 2 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

Now we can check out the depth of the sea level by using the pressure sensor (MS5803–01 BA) connected with Arduino and display the sensor data in Node-RED dashboard.

In this blogtut, we will find out the best way to find out the depth of sea level as well as test out the pressure using MS5803–01BA sensor the sensor is easy to connect with ESP32, Xbee, and many other communication devices.

Hardware

MS5803–01 BA Pressure Sensor

Arduino Uno

Arduino Shield

Software Platforms

Node-RED

Arduino IDE

About Pressure Sensor

The ROHS compliant MS5803–01BA pressure sensor shares the precise parameters of operational pressure range from 1kPa to 130kPa and which uses the high resolution of about 10cm. We can receive the 24-bits precise variation using MS5803–01BA sensor.

Application of Pressure Sensor

Being a newbie to this sensor we have figure out the way to receive the sensor data by using the modular I2C breakout board. We were able to find out the pressure as well as temperature and with the help of the earlier blogtut we will be able to find out the distance between the object and the earth using specified formulae and process called as altitude measurement

But being good robust designs and for underwater process system, we recommend to use this sensor to find out the depth of sea from earth surface to the core easily. These sensors can majorly be used in submarines for various other application to monitor as well as controlling the actuators. With the help of various communication devices, you will be able to operate the sensor data at longer miles also.

I2C Code

  • Initialize the Wire.h file called as I2C Library especially use in Arduino IDE
#include <Wire.h>
  • Initialize the I2C registers of sensor module which is specified to work with 2 wire protocol.
#define Addr 0x77
  • Begin the I2C transmission and Initialize the baud rate as per the requirements for serial communication.
void setup(){  
// Initialise I2C communication as MASTER
Wire.begin();  
// Initialise Serial Communication, set baud rate = 9600  
Serial.begin(9600);
  • Request for 3 bytes of Data which we want to read from the sensor through I2C connection for pressure and temperature
if(Wire.available() == 3)  {     
data[0] = Wire.read();     
data[1] = Wire.read();     
data[2] = Wire.read();  
}
  • If 3 bytes of data is available then use the mentioned below formula will help to convert the data bytes and display desired values
unsigned long ptemp = ((data[0] * 65536.0) + (data[1] * 256.0) + data[2]);
  • Manipulate the parameters as per the requirement of precision settings which is given in datasheet
unsigned long dT = temp - ((Coff[4] * 256));
temp = 2000 + (dT * (Coff[5] / pow(2, 23)));
// Offset and Sensitivity calculation
unsigned long long off = Coff[1] * 65536 + (Coff[3] * dT) / 128;    
unsigned long long sens = Coff[0] * 32768 + (Coff[2] * dT) / 256;
// Convert the final data  
ptemp = (((ptemp * sens) / 2097152) - off);
ptemp /= 32768.0;float pressure = ptemp / 100.0;
float ctemp = temp / 100.0;
float fTemp = ctemp * 1.8 + 32.0;
  • Using Serial.print you will be able to read the sensor data in the serial monitor screen.
// Output data to serial monitor  
Serial.print("Temperature in Celsius : ");  
Serial.print(ctemp);  Serial.println(" C");  
Serial.print("Temperature in Fahrenheit : ");  
Serial.print(fTemp);  Serial.println(" F");  
Serial.print("Pressure : ");  
Serial.print(pressure);  
Serial.println(" mbar");   
delay(500);

Node-RED

With the help of Node-RED you will be able to display the sensor data in dashboard format which is already been mentioned in previous blogtuts.

The newbies can check out the tutorial for Node-RED installation here.

Code

https://github.com/varul29/Node-Red_Tutorial

https://github.com/varul29/MS5803-01BA/blob/master/Arduino/MS5803_01BA.ino

Credits

  • Control everything
  • Node-RED

Code

MS5803-01BA_ArduinoC/C++
#include <Wire.h>

// MS5803_01BA I2C address is 0x77(119)
#define Addr 0x77

unsigned long Coff[6], Ti = 0, offi = 0, sensi = 0;
unsigned int data[3];
void setup()
{
  // Initialise I2C communication as MASTER
  Wire.begin();
  // Initialise Serial Communication, set baud rate = 9600
  Serial.begin(9600);

  // Read cofficients values stored in EPROM of the device
  for(int i = 0; i < 6; i++)
  {
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select data register
    Wire.write(0xA2 + (2 * i));
    // Stop I2C Transmission
    Wire.endTransmission();
  
    // Request 2 bytes of data
    Wire.requestFrom(Addr, 2);
      
    // Read 2 bytes of data
    // Coff msb, Coff lsb
    if(Wire.available() == 2)
    {
      data[0] = Wire.read();
      data[1] = Wire.read();
    }  
      
    // Convert the data
    Coff[i] = ((data[0] * 256) + data[1]);
  }
  delay(300);
}

void loop() 
{
  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Send reset command 
  Wire.write(0x1E);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(500);
  
  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Refresh pressure with the OSR = 256 
  Wire.write(0x40);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(500);
  
  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select data register 
  Wire.write(0x00);
  // Stop I2C Transmission
  Wire.endTransmission();
  
  // Request 3 bytes of data
  Wire.requestFrom(Addr, 3);

  // Read 3 bytes of data
  // ptemp_msb1, ptemp_msb, ptemp_lsb
  if(Wire.available() == 3)
  {
     data[0] = Wire.read();
     data[1] = Wire.read();
     data[2] = Wire.read();
  }   
  
  // Convert the data 
  unsigned long ptemp = ((data[0] * 65536.0) + (data[1] * 256.0) + data[2]);
 
  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Refresh temperature with the OSR = 256 
  Wire.write(0x50);
  // Stop I2C Transmission
  Wire.endTransmission();
  delay(500);
  
  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Select data register
  Wire.write(0x00);
  // Stop I2C Transmission
  Wire.endTransmission();
  
  // Request 3 bytes of data
  Wire.requestFrom(Addr, 3);

  // Read 3 bytes of data
  // temp_msb1, temp_msb, temp_lsb
  if(Wire.available() == 3)
  {
     data[0] = Wire.read();
     data[1] = Wire.read();
     data[2] = Wire.read();
  }
  
  // Convert the data
  unsigned long temp = ((data[0] * 65536.0) + (data[1] * 256.0) + data[2]);
  
  // Pressure and Temperature Calculations
  // 1st order temperature and pressure compensation
  // Difference between actual and reference temperature
  unsigned long dT = temp - ((Coff[4] * 256));
  temp = 2000 + (dT * (Coff[5] / pow(2, 23)));

  // Offset and Sensitivity calculation
  unsigned long long off = Coff[1] * 65536 + (Coff[3] * dT) / 128;
  unsigned long long sens = Coff[0] * 32768 + (Coff[2] * dT) / 256;

  // 2nd order temperature and pressure compensation
  if(temp < 2000)
  {
    Ti = (dT * dT) / (pow(2,31));
    offi = 5 * ((pow((temp - 2000), 2))) / 2;
    sensi = offi / 2; 
    if(temp < - 1500)
    {
       offi = offi + 7 * ((pow((temp + 1500), 2)));      
       sensi = sensi + 11 * ((pow((temp + 1500), 2))) / 2;
    }
  }
  else if(temp >= 2000)
  {
     Ti = 0;
     offi = 0;
     sensi = 0;
  }
  
  // Adjust temp, off, sens based on 2nd order compensation   
  temp -= Ti;
  off -= offi;
  sens -= sensi;

  // Convert the final data
  ptemp = (((ptemp * sens) / 2097152) - off);
  ptemp /= 32768.0;
  float pressure = ptemp / 100.0;
  float ctemp = temp / 100.0;
  float fTemp = ctemp * 1.8 + 32.0;

  // Output data to serial monitor
  Serial.print("Temperature in Celsius : ");
  Serial.print(ctemp);
  Serial.println(" C");
  Serial.print("Temperature in Fahrenheit : ");
  Serial.print(fTemp);
  Serial.println(" F");
  Serial.print("Pressure : ");
  Serial.print(pressure);
  Serial.println(" mbar"); 
  delay(500); 
}

Comments

Similar projects you might like

Arduino BME280 Sensor How To

by Dragos Iosub

  • 594 views
  • 0 comments
  • 2 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 77,839 views
  • 13 comments
  • 23 respects

MQ-4 Natural Gas Sensor Experiment Based on Arduino

Project tutorial by Andrew85

  • 2,906 views
  • 1 comment
  • 7 respects

Smoke Detection using MQ-2 Gas Sensor

by Aritro Mukherjee

  • 295,000 views
  • 49 comments
  • 189 respects

Using the YL-39 + YL-69 Soil Humidity Sensor with Arduino

Project tutorial by Sorin Trimbitas

  • 32,145 views
  • 6 comments
  • 20 respects

Parking Sensor with Arduino

Project showcase by Team VINICIUS LOPES

  • 21,154 views
  • 4 comments
  • 29 respects
Add projectSign up / Login