Water Depth Sensor MS5540C Arduino Tutorial
Water Depth Sensor MS5540C Arduino Tutorial
s
ic
on
Description:
tr
This is an amazing digital pressure sensor from Intersema has wide range
applications.The MS5540C pressure sensor measures Absolute water or air
ec
pressure. It also measure temperature at the same time. So you can use it for
measuring water depth in sea or water level in tank. It can be also be used with
different fluids measurements such as oil. You might use it also with air for
El
The MS5540C carries a metal protection cap filled with silicone gel for
e
enhanced protection against water and humidity. The properties of this gel
ensure function of the sensor even when in direct water contact. The MS5540C
r
is qualified referring to the ISO Standard 2281 and can withstand a pressure of
tu
100 m in salt water. Nevertheless the user should avoid drying of hard
materials like for example salt particles on the silicone gel surface. In this case
it is better to rinse with clean water afterwards.
Fu
The sensor measure water depth with very good accuracy of 0.1 mbar (1 cm
water level). Please read note 3 below for linear range and accuracy. The
pressure module have wide range applications ranging from liquid level
measurements in tanks, water depth and temperature in diving, snorkeling and
ROV.
w w w . f u t - e l c t r o n i c s . c o m Page 1
The pressure sensor is factory calibrated and future electronics Egypt has
extensively tested the sensor and prepared a tutorial (check below) showing
how to read factory calibration coefficients and use it to measure both
pressure and temperature in an accurate manner.
Features:
s
• Pressure Linear range (air Applications): 10 to 1100 mbar
ic
• Under water depth: 10m (Please read note 3 below)
• Resolution 0.1 mbar (1 cm water)
on
• 16 Bit ADC
• SPI serial interface
• 1 system clock line (32.768 kHz)
•
•
Temperature range -40..+85°C
Low voltage (2.2 to 3.6V)
tr
ec
• Low power (Standby current:0.1uA)
• Small size 6.2 x 6.4 mm
Important Notes:
El
1- When using the pressure sensor for underwater applications, user MUST
isolate all the metal contacts (For example using melted wax), the only part
e
that is left exposed to water is the sensor surface (the white gel surface should
not be covered or touched).
r
2- Special care has to be taken to not mechanically damage the gel. Damaged
tu
gel could lead to air entrapment and consequently to unstable sensor signal.
Do not test the sensor by pressing the surface with your finger or any hard
metal
Fu
3- The sensor can withstand up to 100 meter under water, however the linear
range for factory calibrated coefficients stored on the sensor ROM adjusted for
linear range of about 7m. If you want more linear range you may calibrate your
own factors and use each group of factors for each range.
w w w . f u t - e l c t r o n i c s . c o m Page 2
Water Depth Sensor connection to Arduino and Code
Sensor Arduino
s
DIN (MOSI) -----------> pin (11)
ic
DOUT (MISO) ---------> pin (12)
on
MCLK ---------------> pin (9)
Arduino code:
tr
ec
#include <SPI.h>
int clock = 9;
El
{
e
SPI.setDataMode(SPI_MODE0);
r
SPI.transfer(0x15);
tu
SPI.transfer(0x55);
SPI.transfer(0x40);
Fu
void setup() {
Serial.begin(9600);
w w w . f u t - e l c t r o n i c s . c o m Page 3
SPI.setBitOrder(MSBFIRST);
pinMode(clock, OUTPUT);
delay(100);
s
ic
void loop()
on
TCCR1B = (TCCR1B & 0xF8) | 1 ; //generates the MCKL signal
tr
resetsensor();//resets the sensor - caution: afterwards mode = SPI_MODE0!
ec
//Calibration word 1
w w w . f u t - e l c t r o n i c s . c o m Page 4
unsigned int word2 = 0;
byte word22 = 0;
SPI.transfer(0x1D);
SPI.transfer(0x60);
SPI.setDataMode(SPI_MODE1);
s
word2 = SPI.transfer(0x00);
ic
word2 = word2 <<8;
word22 = SPI.transfer(0x00);
on
word2 = word2 | word22;
byte word33 = 0;
El
SPI.transfer(0x1D);
SPI.transfer(0x90);
e
SPI.setDataMode(SPI_MODE1);
word3 = SPI.transfer(0x00);
r
word33 = SPI.transfer(0x00);
w w w . f u t - e l c t r o n i c s . c o m Page 5
byte word44 = 0;
SPI.transfer(0x1D);
SPI.transfer(0xA0);
SPI.setDataMode(SPI_MODE1);
word4 = SPI.transfer(0x00);
s
word4 = word4 <<8;
ic
word44 = SPI.transfer(0x00);
on
long c1 = word1 << 1;
tr
long c2 = ((word3 & 0x3F) >> 6) | ((word4 & 0x3F));
//Temperature:
r
unsigned int D2 = 0;
Fu
w w w . f u t - e l c t r o n i c s . c o m Page 6
tempMSB = tempMSB << 8; //shift first byte
s
ic
//Pressure:
on
unsigned int presLSB =0; //last byte of value
unsigned int D1 = 0;
tr
SPI.transfer(0x0F); //send first byte of command to get pressure value
D1 = presMSB | presLSB;
r
w w w . f u t - e l c t r o n i c s . c o m Page 7
Serial.print("pressure = ");
Serial.print(PCOMP);
Serial.println(" mbar");
s
const float TEMPCOMP = (200 + (dT2*(c6+100) >>11))/10;
ic
Serial.print("temperature = ");
Serial.print(TEMPCOMP);
on
Serial.println(" °C");
Serial.println("************************************");
delay(1000);
tr
ec
}
El
r e
tu
Fu
w w w . f u t - e l c t r o n i c s . c o m Page 8