Pressure Sensor Analog Reading with Arduino

This project demonstrates how to read analog values from a pressure sensor connected to an Arduino board. The analog values correspond to the pressure sensed by the sensor and are displayed on the Serial Monitor for monitoring and analysis.

How It Works

Barometric sensors such as the BMP180, BMP280 and BME280 use a MEMS piezoresistive element: a tiny silicon diaphragm whose resistance changes as atmospheric pressure flexes it. The chip digitises that internally and exposes calibrated readings over I²C, so no analog conditioning is needed.

These parts are genuinely precise. A BMP280 resolves pressure to about ±0.12 hPa, which corresponds to roughly a one-metre change in altitude — enough to detect moving between floors of a building. Pressure and altitude are related through the barometric formula, which the libraries implement for you.

The catch is that altitude derived from pressure is only as good as your sea-level reference. Weather systems shift sea-level pressure by tens of hectopascals, so an altitude calculated with the standard 1013.25 hPa constant can be tens of metres out. For relative measurements — how far up did I move — it is excellent; for absolute altitude it needs a current local reference.

All three parts speak I²C, which on the Arduino Uno means A4 (SDA) and A5 (SCL). Addresses are typically 0x76 or 0x77 depending on how the SDO pin is tied.

Components Needed

  • Arduino Uno
  • Barometric Pressure Sensor module
  • Arduino Uno
  • USB cable for programming and power
  • Arduino Uno

Wiring to the Arduino Uno

Connect SDA and SCL to A4 (SDA) and A5 (SCL), with VCC and GND to the supply rails. The BMP280 die is a 3.3 V part. Most breakout boards include a regulator and level shifting so they tolerate 5 V, but bare modules do not — check for a regulator before connecting 5 V, or power from the 3V3 pin to be safe.

I²C needs pull-up resistors on both lines. Nearly all breakout boards fit them, but chaining several modules stacks those pull-ups in parallel and can over-load the bus — remove the extras if communication becomes unreliable.

Shield the sensor from draughts and direct sun. The BME280's humidity and temperature channels in particular respond to airflow, and a sensor in sunlight reads several degrees high.

Module pinArduino Uno pinFunction
SDAA4I²C data
SCLA5I²C clock
VCC3V3 (see notes)Supply — the bare chip is 3.3 V
GNDGNDCommon ground

Example Code

Reading pressure, temperature and relative altitude from a BMP280. Upload it with the board set to Arduino Uno and open the Serial Monitor at 9600 baud.

Reading pressure, temperature and relative altitude from a BMP280
#include <Wire.h>
#include <Adafruit_BMP280.h>

Adafruit_BMP280 bmp;
float referencePressure = 1013.25;   // hPa — replace with your local value

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!bmp.begin(0x76)) {            // try 0x77 if this fails
    Serial.println("BMP280 not found — check wiring and address");
    while (1) delay(1000);
  }

  // Capture the starting pressure so altitude is measured relative to here
  delay(100);
  referencePressure = bmp.readPressure() / 100.0;
  Serial.print("Reference set to ");
  Serial.print(referencePressure, 2);
  Serial.println(" hPa");
}

void loop() {
  float hPa  = bmp.readPressure() / 100.0;
  float degC = bmp.readTemperature();
  float rel  = bmp.readAltitude(referencePressure);

  Serial.print("Pressure: "); Serial.print(hPa, 2);  Serial.print(" hPa   ");
  Serial.print("Temp: ");     Serial.print(degC, 1); Serial.print(" C   ");
  Serial.print("Rel height: ");Serial.print(rel, 1); Serial.println(" m");
  delay(1000);
}

Applications

A barometric pressure sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Weather stations and short-term forecasting from pressure trends
  • Altitude hold and height estimation on drones and model rockets
  • Floor detection in indoor navigation
  • Detecting whether a sealed enclosure has lost its seal
  • Compensating other sensors whose readings vary with air density

Working with the Arduino Uno

The Arduino Uno is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Uno runs at 5 V, so most hobby sensor modules connect directly with no level shifting.

With only 2 KB of SRAM, avoid large buffers and prefer the F() macro for constant strings.

The single hardware UART is shared with the USB connection, so heavy Serial printing competes with uploads.

Arduino Uno characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A5 (six channels)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • The sensor is not found — try the other address (0x76 versus 0x77), and run an I²C scanner to see what is actually on the bus.
  • Altitude drifts over hours while the sensor sits still — that is real weather changing the pressure, not a fault.
  • Temperature reads 2–3 °C high — the chip self-heats, and on combined modules the regulator adds more. Offset it, or read less often.
  • Readings are unstable — an unshielded sensor near a fan or window responds to every gust. Enclose it with a small vent.
  • Nothing works on a Mega after copying Uno wiring — I²C is on D20/D21 here, not A4/A5.
  • Code written for an ESP board gives odd analog values — the Arduino Uno uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Uno I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Uno

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Uno specifically:

The Uno’s shield ecosystem is its real advantage. Once the circuit works on a breadboard, a prototyping shield turns it into something permanent that still stacks with a data-logging or Ethernet shield without rewiring.

Logging to an SD card via a shield is the natural next step, since the Uno has no onboard storage and no network. Timestamp each reading with a DS3231 real-time clock so the log survives power cuts with correct times.

Because SRAM is limited to 2 KB, keep logged strings short and write them out immediately rather than buffering. Building a long String in memory is the most common cause of an Uno sketch that runs for hours and then freezes.

Notes and Practical Limits

The BMP280 measures pressure and temperature; the BME280 adds humidity for a small extra cost and is usually the better buy for weather work. They share the same library and address scheme, so the code barely changes.

For relative altitude, capture a reference at startup as the sketch does. That removes the weather-dependence entirely and gives genuinely useful centimetre-to-metre resolution.