Blog
Want to Master Air Pressure, Pressure & Level Control? This Module Works!
Introduction
This is an intelligent sensing device integrating an AD sampling chip and a barometric pressure sensor, featuring dual detection functions of air pressure and liquid level. With the precise signal processing of high-performance AD sampling chips, it not only supports the stable collection of air pressure data but also reliably detects the liquid level status of various containers. It has the advantages of stable performance and high sensitivity, and is suitable for the sensing requirements of multiple scenarios such as industrial monitoring and warehouse management. It is an integrated sensing solution that takes into account both accuracy and practicality.
Working Principle
Physical Quantity Signal Acquisition
The module integrates a built-in MEMS piezoresistive sensor and is equipped with sealed pipeline interfaces suitable for air pressure and liquid level measurement, enabling separate signal acquisition for three types of parameters.
Air Pressure and Liquid Pressure Measurement
The sensor incorporates four strain resistors arranged in a Wheatstone bridge configuration. When gas or liquid pressure acts on the sensor’s pressure – bearing surface, the resistors undergo slight deformation proportional to the pressure magnitude, which in turn changes their resistance values. The bridge circuit can capture these subtle resistance variations and convert the pressure physical quantity into an initial electrical signal.
Liquid Level Measurement
It adopts the pneumatic indirect measurement principle. The module is connected to the pipeline of the measured container via a 2.5mm hose to form a closed air path. When the liquid level changes, it squeezes the gas inside the closed air path, causing a corresponding change in air path pressure. After capturing this pressure change, the sensor can reversely calculate the liquid level height by combining preset parameters such as liquid density. For example, when the liquid level in a water tank rises, the air path pressure increases, and the module judges the liquid level rise accordingly.
Characteristics
1.3-in-1 Integrated Design
Breaking the functional limitations of traditional single-function sensors, a single module can perform air pressure monitoring, liquid pressure detection, and liquid level height measurement. It is compatible with various scenarios such as gas pipelines, small liquid storage tanks, and water circulation systems, significantly reducing hardware procurement costs and circuit layout complexity.
2.Plug and Play
The pin definitions are concise and clear (VCC/GND/OUT/SCK), and it is directly compatible with the 3.3V/5V power supply and analog input interfaces of mainstream controllers such as Arduino Uno/Nano, eliminating the need for complex peripheral circuits. Complete wiring diagrams and test codes are provided, allowing beginners to complete data reading and debugging within 10 minutes.
3.Industrial-Grade Precision & Stability
Equipped with a high-precision AD sampling chip and a 5kΩ resistive bridge sensor, it covers a low-pressure range of 0–40 kPa for pressure measurement and control, featuring high data resolution, zero drift, and strong anti-interference capability. With an operating temperature range of -40℃ to 80℃, it can adapt to most harsh indoor and outdoor environments and meet the requirements of long-term continuous monitoring.
4.Miniaturized & Easy to Install
With a compact size of only 19×18mm, the module comes with 2mm mounting holes and supports quick connection to pipelines via 2.5mm hoses. It can be easily embedded into tight spaces such as small equipment enclosures, robot chassis, and smart home modules, enabling flexible and hassle-free installation.
Pinout
| PIN | FUNCTION DESCRIPTION |
|---|---|
| VCC | Positive Pole |
| GND | Negative Pole |
| OUT | Data Output |
| SCK | Clock Signal |
Introduction of AD
The HX710 adopts the patented integrated circuit technology of Haixin Technology, and is a 24-bit A/D converter chip specially designed for high-precision electronic scales. Compared with other chips of the same type, it boasts the advantages of high integration, fast response speed and strong anti-interference capability. It reduces the overall cost of electronic scales while improving their performance and reliability.
All control signals are driven by pins, eliminating the need for programming the internal registers of the chip. The MCU only requires 2 I/O ports to achieve full control of the ADC, including power-off control. The power-on auto-reset function simplifies the boot initialization process.
Feature
- DVDD-AVDD Voltage Difference Measurement (HX710B)
- On-Chip Clock Oscillator Requires No External Components
- Power-On Auto-Reset Circuit
- Simple Digital Control and Serial Communication: All controls are pin-driven, with no programming required for the internal registers of the chip.
- Power Consumption: Typical Operating Current: 1.2mA, Power-Off Current: < 1µA
- Operating Voltage Range: 2.6V ~ 5.5V
- Operating Temperature Range: -40℃ ~ +85℃
HX710 Schematic
Pin Definitions
HX710A VS HX710B
| Character | HX710A | HX710B | The advantages of B |
|---|---|---|---|
| Main Uses | Weighing scale | Pressure sensor | More suitable for pressure measurement |
| Gain Margin | Fixed at 128 times | Programmable 32/64/128 times | More flexible and adaptable to different sensors |
| Data Rate | Fixed 10/80Hz | Programmable 10/40/80Hz | It can be adjusted according to the application |
| Clock Source | Internal clocking | An external clock is optional | Better anti-interference performance |
| Price | Slightly more affordable | A bit pricey | Little to no difference |
| Application | Electronic scales, kitchen scales | Pressure transmitter, level gauge |
The Pressure Sensor Detects the Level of Liquid
This system adopts the hydrostatic pressure principle, converting water level height into air pressure changes via sealed hoses. A pressure sensor measures the pressure difference, and the water level height is finally calculated using physical formulas. Despite its simple principle, factors such as temperature compensation, sealing performance, and installation position must be considered to achieve accurate measurements.
Requirement:Air pressure sensor、Arduino、OLED、Hose
Notes:All interfaces are strictly sealed.
Arduino Code
#include
#include
#include
// OLED Configuration
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Manual HX710 reading (no external library)
#define HX710_SCK 3
#define HX710_DOUT 2
// Calibration parameters
float calibration_factor = 1.0; // Needs adjustment via calibration
long zero_offset = 0;
const float SENSOR_MAX_PRESSURE = 40000.0; // 40KPa
const long MAX_24BIT = 16777215L; // 24-bit max value
// Water level calculation parameters
const float WATER_DENSITY = 1000.0; // kg/m³
const float GRAVITY = 9.80665; // m/s²
// Manual HX710 read function
long readHX710() {
long count = 0;
unsigned char data[3] = {0};
// Wait for data ready
while (digitalRead(HX710_DOUT) == HIGH) {
delay(1);
}
// Read 24-bit data
for (int i = 0; i < 24; i++) {
digitalWrite(HX710_SCK, HIGH);
delayMicroseconds(1);
if (i < 24) {
count = count << 1;
digitalWrite(HX710_SCK, LOW);
delayMicroseconds(1);
if (digitalRead(HX710_DOUT)) {
count++;
}
}
}
// 25th pulse to select next channel and gain
digitalWrite(HX710_SCK, HIGH);
delayMicroseconds(1);
digitalWrite(HX710_SCK, LOW);
delayMicroseconds(1);
// Convert to signed value
if (count & 0x800000) {
count |= 0xFF000000;
}
return count;
}
// Get averaged reading
long getAverageReading(int times) {
long sum = 0;
for (int i = 0; i < times; i++) {
sum += readHX710();
delay(5);
}
return sum / times;
}
void setup() {
Serial.begin(9600);
// Initialize HX710 pins
pinMode(HX710_SCK, OUTPUT);
pinMode(HX710_DOUT, INPUT);
digitalWrite(HX710_SCK, LOW);
// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("OLED initialization failed!"));
while (1);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(F("Water Level Monitor v1.0"));
display.println(F("Initializing..."));
display.display();
delay(2000);
// Warm up sensor
delay(100);
// Zero-point calibration
display.clearDisplay();
display.setCursor(0, 0);
display.println(F("Zero Calibration"));
display.println(F("Ensure tube is dry"));
display.println(F("Starting in 10s..."));
display.display();
delay(10000);
zero_offset = getAverageReading(20);
display.clearDisplay();
display.setCursor(0, 0);
display.println(F("Calibration complete!"));
display.println("Zero point: " + String(zero_offset));
display.display();
delay(2000);
Serial.println("System ready");
Serial.println("Zero offset: " + String(zero_offset));
}
void loop() {
static unsigned long lastUpdate = 0;
if (millis() - lastUpdate >= 1000) { // Update every second
long raw = getAverageReading(5);
float calibrated_value = (raw - zero_offset) * calibration_factor;
// Convert to pressure (Pa)
float pressure_pa = calibrated_value * (SENSOR_MAX_PRESSURE / MAX_24BIT);
// Convert to water level (cm), filter negative values
float water_level_cm = 0;
if (pressure_pa > 0) {
float height_m = pressure_pa / (WATER_DENSITY * GRAVITY);
water_level_cm = height_m * 100.0;
}
// Serial output
Serial.print("Raw: ");
Serial.print(raw);
Serial.print(" | Calibrated: ");
Serial.print(calibrated_value);
Serial.print(" | Pressure: ");
Serial.print(pressure_pa, 1);
Serial.print(" Pa | Water Level: ");
Serial.print(water_level_cm, 1);
Serial.println(" cm");
// OLED display
updateDisplay(water_level_cm, pressure_pa, raw);
lastUpdate = millis();
}
}
void updateDisplay(float level_cm, float pressure_pa, long raw_value) {
display.clearDisplay();
// Title
display.setTextSize(1);
display.setCursor(0, 0);
display.println(F("=== Water Level ==="));
// Water level (large font)
display.setTextSize(2);
display.setCursor(0, 15);
display.print(level_cm, 1);
display.setTextSize(1);
display.println(F(" cm"));
// Pressure value
display.setTextSize(1);
display.setCursor(0, 35);
display.print(F("Pressure: "));
display.print(pressure_pa, 0);
display.println(F(" Pa"));
// Raw value
display.setCursor(0, 45);
display.print(F("Raw: "));
display.print(raw_value);
// Water level indicator bar
int barHeight = constrain(map(level_cm, 0, 400, 0, 40), 0, 40); // 0-400cm maps to 0-40 pixels
display.fillRect(100, 24, 20, 40 - barHeight, SSD1306_BLACK); // Clear upper part
display.fillRect(100, 64 - barHeight, 20, barHeight, SSD1306_WHITE); // Fill water level
display.drawRect(100, 24, 20, 40, SSD1306_WHITE); // Outline
// Scale marks
for (int i = 0; i <= 4; i++) {
int y = 64 - (i * 10);
display.drawFastHLine(95, y, 5, SSD1306_WHITE);
}
display.display();
}
// Serial calibration commands
void serialEvent() {
if (Serial.available()) {
char cmd = Serial.read();
switch (cmd) {
case 'z': // Zero calibration
zero_offset = getAverageReading(20);
Serial.println("Zero calibration complete: " + String(zero_offset));
break;
case 'c': // Set calibration factor
Serial.println("Enter calibration factor: ");
while (!Serial.available());
calibration_factor = Serial.parseFloat();
Serial.println("Calibration factor set to: " + String(calibration_factor));
break;
case 'h': // Help
Serial.println(F("Available commands:"));
Serial.println(F("z - Zero calibration"));
Serial.println(F("c - Set calibration factor"));
Serial.println(F("h - Help"));
break;
}
}
}