Skip to Content
This is the Beta version of our new Learning Paths approach. Please email feedback.

Pressure Sensor

This project reads values from a BMP280 sensor and displays the readings on the serial monitor. This sketch measures the pressure and derives the altitude based on that and prints both values on the serial monitor.

Components
ComponentPurpose
Arduino NanoThis will be the microcontroller
BMP280This will be the pressure sensor
Circuit Diagram
nano_pressure_lcd_fritzing
Connections

BMP280

Nano PinBMP280 Pin
A4SDA
A5SCL
5VVCC
GNDGND
Code
pressure_sensor.ino
/* Project: BMP Sensor Project Description: This sketch reads values from a BMP sensor and prints the data to the serial monitor. Author: STEMVentor Educonsulting This code is copyrighted. Please do not reuse or share for any purpose other than for learning with subscribed STEMVentor programs. This code is for educational purposes only and is not for production use. */ // LIBRARIES // BMP pressure sensor library // One change to the .h file of BMP280 library file may be required // if the default address of the BMP sensor (which uses I2C communication) // is different from what is in the default code. // In this case it need to be set to 0x76 which was the address of our BMP sensor. // All I2C components have an address, the default is usually 0x27 // If that doesn't work, see this:https://playground.arduino.cc/Main/I2cScanner/ // Install these libraries using the IDE library manager. #include <Adafruit_Sensor.h> #include <Adafruit_BMP280.h> // PIN DEFINITIONS // GLOBAL VARIABLES // INITIALIZE OBJECTS Adafruit_BMP280 bmp; /* LOCAL FUNCTIONS */ void readBMPSensorValues(){ // library function to read temperatured in degree celcius float temperature_value = bmp.readTemperature(); Serial.println("Temperature: " + temperature_value + "deg C"); // library function to read pressure in hPa float pressure_value = bmp.readPressure(); Serial.println("Pressure: " + pressure_value + "hPa"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal // library function to read altitude float altitude_value = bmp.readAltitude(1004); //1004 is Mumbai's avg sea level pressure Serial.println("Altitude: " + altitude_value + "m"); } void BMPSensorSetup() { if (bmp.begin()){ //starts the bmp Serial.println("BMP180 initialized successfully."); } else{ Serial.println("BMP180 initialization failed."); } } /* SETUP CODE: runs once when the board starts up or resets */ void setup() { // Start the serial communication with baud rate suitable for your components. Serial.begin(9600); BMPSensorSetup(); Serial.println("The BMP Sensor is ready!"); } /* MAIN LOOP: runs repeatedly at a very high frequency (1000s of times a second) */ void loop() { readBMPSensorValues(); delay(15*1000); }