Arduino Uno and BMP388 barometric pressure sensor example

Another expensive visit to Aliexpress made me find this sensor listed by one of the vendors – it is a BMP388 by Bosch Sensortec, so lets crack on and try this out with an Arduino Uno again

On with the manufacturers blurb

BMP388 Information

The BMP388 is a very small, low-power and low-noise 24 bit absolute barometric pressure sensor. It enables accurate altitude tracking and is specifically suited for drone applications. The best-in-class TCO of the BMP388 between 0-65°C for accurate altitude measurement over a wide temperature range greatly enhances the drone flying experience by making accurate steering easier.

It is compatible for use with other Bosch sensors, including BMI088 for better performance, robustness and stability.

The BMP388 sensor offers outstanding design flexibility, providing a single package solution that is easy to integrate into other existing and upcoming devices such as smart homes, industrial products and wearables.

It is more accurate than its predecessors, covering a wide measurement range from 300 hPa to 1250 hPa. BMP388 exhibits an attractive price-performance ratio coupled with low power consumption. It is available in a compact 10-pin 2.0 x 2.0 x 0.75 mm³ LGA package with metal lid.

  • Operating voltage: 3.3V/5V
  • Communication interface: I2C/SPI
  • Barometric pressure operation range: 300~1250hPa
  • Barometric pressure absolute accuracy: ±0.40hPa (@900~1100hPa, 25~40℃)
  • Barometric pressure relative accuracy: ±0.08hPa (@900~1100hPa, 25~40℃)
  • Temperature coefficient offset: ±0.75Pa/K (@700~1100hPa, -20~65℃))
  • Temperature absolute accuracy: ±0.5℃ (0~65℃)
  • Possible resolution: 0.016Pa (high precision mode)
  • Possible sampling rate: 200Hz
  • Operating voltage: -40~85℃

If you purchase a module they will have a 3.3v regulator on board, you will also have the option of I2C or SPI, here is the module that I located.

Parts Required

I connected a sensor shield to an Arduino and then the sensor via connecting wire

Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
BMP38824-bit low noise BMP388 digital temperature atmospheric pressure sensor
Connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
sensor shieldExpansion IO Board Sensor Shield


I decided to use the sensor in I2C mode – I also decided to use 3.3v from the Arduino Uno but could have quite easily used 5v from the board

arduino and bmp388 layout

arduino and bmp388 layout

Code Example

I used the library from adafruit – 

This library can be installed via the library manager. This is the default example and I have removed some of the SPI code and code comments since I was using the sensor in I2C mode

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BMP3XX bmp; // I2C
void setup() {
  while (!Serial);
  Serial.println("BMP388 test");
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  // Set up oversampling and filter initialization
void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
  Serial.print("Temperature = ");
  Serial.println(" *C");
  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");
  Serial.print("Approx. Altitude = ");
  Serial.println(" m");



Open the serial monitor and you should see something like this

Temperature = 24.95 *C
Pressure = 1011.79 hPa
Approx. Altitude = 12.14 m

Temperature = 24.98 *C
Pressure = 1011.81 hPa
Approx. Altitude = 12.01 m

Temperature = 25.00 *C
Pressure = 1011.81 hPa
Approx. Altitude = 11.96 m






A nice little sensor but at just over $8 but one again there are cheaper sensors available which have the same functionality and for most projects have acceptable performance.


Arduino Uno and HY-SRF05 ultrasonic sensor example

The HY-SRF05 is an ultrasonic emitter/receiver used to measure distance with a precision of ~0.3cm. It sends out a 40 KHz square wave signal that reflects on objects in front of the sensor. This signal is then read back by the sensor and the duration of the received signal is reflected on the ECHO pin.


Supply voltage: 4.5V to 5.5V
Supply current: 10 to 40mA
Trigger pin format: 10 uS digital pulse
Sound frequency: 40 KHz
Echo pin output: 0V-VCC
Echo pin format: digital

How to use

Send a 10Us wide pulse (low to high) to the Trigger pin.
Monitor the ECHO pin.
When the ECHO pin goes HIGH, start a timer.
When the ECHO pin goes LOW, stop the timer and save the elapsed time.
Use the elapsed time in the following formula to get the distance in cm:

Distance (in cm) = (elapsed time * sound velocity (340 m/s)) / 100 / 2

We will see a code example later


Parts List

Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
HY-SRF05HY-SRF05 SRF05 Ultrasonic Ranging Module Ultrasonic Sensor
connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



arduino and HY-SRF05

arduino and HY-SRF05



VCC to +5V
GND to ground
TRIG to digital pin 12
ECHO to digital pin 13
const int TRIG_PIN = 12;
const int ECHO_PIN = 13;
void setup()
  // initialize serial communication:
void loop()
  long duration, distanceCm, distanceIn;
  digitalWrite(TRIG_PIN, LOW);
  digitalWrite(TRIG_PIN, HIGH);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN,HIGH);
  // convert the time into a distance
  distanceCm = duration / 29.1 / 2 ;
  distanceIn = duration / 74 / 2;
  if (distanceCm <= 0)
    Serial.println("Out of range");
    Serial.print("in: ");



Open the serial monitor and you will something like this depending how close the module is to an object

I was moving the sensor away from an object

4in, 10cm
3in, 9cm
4in, 10cm
4in, 10cm
4in, 10cm
4in, 10cm
4in, 12cm
4in, 12cm
4in, 12cm


ADXL337 accelerometer Arduino Uno example

In this article we connect an ADXL337 accelerometer to an Arduino Uno

The ADXL337 is a small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs. The product measures acceleration with a minimum full-scale range of ±3g. It can measure the static acceleration of gravity in tiltsensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.

The user selects the bandwidth of the accelerometer using the CX, CY, and CZ capacitors at the XOUT, YOUT, and ZOUTpins. Bandwidths can be selected to suit the application, with a range of 0.5 Hz to 1600 Hz for X and Y axes, and a range of 0.5 Hz to 550 Hz for the Z axis.


Parts List

Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
ADXL3373-axis ADXL337 GY-61 Replacement ADXL335 Module Analog Output Accelerometer
Connecting wireFree shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire


arduino and adxl337

arduino and adxl337



No libraries required – this is a sparkfun example

// Make sure these two variables are correct for your setup
int scale = 3; // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377
void setup()
  // Initialize serial communication at 115200 baud
// Read, scale, and print accelerometer data
void loop()
  // Get raw accelerometer data for each axis
  int rawX = analogRead(A0);
  int rawY = analogRead(A1);
  int rawZ = analogRead(A2);
  // Scale accelerometer ADC readings into common units
  // Scale map depends on if using a 5V or 3.3V microcontroller
  float scaledX, scaledY, scaledZ; // Scaled values for each axis
  scaledX = mapf(rawX, 0, 675, -scale, scale); // 3.3/5 * 1023 =~ 675
  scaledY = mapf(rawY, 0, 675, -scale, scale);
  scaledZ = mapf(rawZ, 0, 675, -scale, scale);
  // Print out raw X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.println(rawX);
  Serial.print("Y: "); Serial.println(rawY);
  Serial.print("Z: "); Serial.println(rawZ);
  // Print out scaled X,Y,Z accelerometer readings
  Serial.print("X: "); Serial.print(scaledX); Serial.println(" g");
  Serial.print("Y: "); Serial.print(scaledY); Serial.println(" g");
  Serial.print("Z: "); Serial.print(scaledZ); Serial.println(" g");
  delay(2000); // Minimum delay of 2 milliseconds between sensor reads (500 Hz)
// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max)
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;



Open the serial monitor and you will see something like this

X: 384
Y: 340
Z: 281

X: 0.41 g
Y: 0.02 g
Z: -0.50 g

X: 410
Y: 345
Z: 345

X: 0.64 g
Y: 0.07 g
Z: 0.07 g




Arduino Uno and HDC1080 humidity and temperature sensor

The HDC1080 is a digital humidity sensor with integrated temperature sensor that provides excellent measurement accuracy at very low power. The HDC1080 operates over a wide supply range, and is a low cost, low power alternative to competitive solutions in a wide range of common applications. The humidity and temperature sensors are factory calibrated.

Relative Humidity Accuracy ±2% (typical)
Temperature Accuracy ±0.2°C (typical)
Excellent Stability at High Humidity
14 Bit Measurement Resolution
100 nA Sleep Mode Current



This was connected an Arduino Uno

 Arduino connection Module connection



You will need to download the following library and install it from , this is the default example



#include <Wire.h>
#include "ClosedCube_HDC1080.h"
ClosedCube_HDC1080 hdc1080;
void setup()
Serial.println("ClosedCube HDC1080 Arduino Test");
// Default settings:
// - Heater off
// - 14 bit Temperature and Humidity Measurement Resolutions
Serial.print("Manufacturer ID=0x");
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
Serial.print("Device ID=0x");
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
void loop()
Serial.print("C, RH=");
void printSerialNumber() {
Serial.print("Device Serial Number=");
HDC1080_SerialNumber sernum = hdc1080.readSerialNumber();
char format[12];
sprintf(format, "%02X-%04X-%04X", sernum.serialFirst, sernum.serialMid, sernum.serialLast);





Open the serial monitor window and you should expect to see something like this

T=21.75C, RH=28.00%
T=21.60C, RH=28.21%
T=25.36C, RH=32.17%
T=27.87C, RH=43.27%
T=27.42C, RH=40.23%
T=26.90C, RH=32.15%
T=26.41C, RH=27.84%
T=26.00C, RH=25.77%
T=25.59C, RH=24.80%
T=25.15C, RH=24.43%
T=24.81C, RH=24.34%
T=24.45C, RH=24.47%
T=24.13C, RH=24.68%
T=23.82C, RH=24.89%
T=23.55C, RH=25.30%
T=23.26C, RH=25.72%
T=23.01C, RH=26.14%
T=22.71C, RH=26.64%
T=22.49C, RH=26.96%
T=22.28C, RH=27.27%



1PC 2.7 V to 5.5 V HDC1080 high precision temperature and humidity sensor humidity temperature module