Guide to Using the Bar02 with an Arduino
Introduction
The Bar02 pressure sensor is a pressure sensor designed to be used underwater at pressures up to 2 bar, or around 10 meters depth in water. It communicates via I2C and comes with a 4-pin DF-13 connector that is compatible with the Pixhawk autopilot, the Level Converter and other microcontrollers.
Example Code
This example uses the BlueRobotics MS5837 Library with the connected sensor. The example reads the sensor and prints the resulting values to the serial terminal.
Please remember to use a logic level converter, such as this one, to convert Arduino 5V levels to 3.3V!
If you’ve never used Arduino before, we suggest checking out some tutorials!#include <Wire.h> #include "MS5837.h" MS5837 sensor; void setup() { Serial.begin(9600); Serial.println("Starting"); Wire.begin(); sensor.setModel(MS5837::MS5837_02BA); sensor.init(); sensor.setFluidDensity(997); // kg/m^3 (997 freshwater, 1029 for seawater) } void loop() { sensor.read(); Serial.print("Pressure: "); Serial.print(sensor.pressure()); Serial.println(" mbar"); Serial.print("Temperature: "); Serial.print(sensor.temperature()); Serial.println(" deg C"); Serial.print("Depth: "); Serial.print(sensor.depth()); Serial.println(" m"); Serial.print("Altitude: "); Serial.print(sensor.altitude()); Serial.println(" m above mean sea level"); delay(1000); }