Categories

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

NameLink
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

Schematic/Connection

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 – https://github.com/adafruit/Adafruit_BMP3XX. 

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() {
  Serial.begin(115200);
  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
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  //bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
 
void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");
 
  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");
 
  Serial.print("Approx. Altitude = ");
  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");
 
  Serial.println();
  delay(2000);
}

 

Output

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

 

Links

 

 

Summary

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.

Share

Arduino and HDC2080 humidity and temperature sensor example

In this article we look at yet another humidity and temperature sensor from TI – this time its the HDC2080 which we will connect up to an Arduino Uno

Lets look at some of the technical information and data from TI

HDC2080 Information

The HDC2080 device is an integrated humidity and temperature sensor that provides high accuracy measurements with very low power consumption in a small DFN package. The capacitive-based sensor includes new integrated digital features and a heating element to dissipate condensation and moisture. The HDC2080 digital features include programmable interrupt thresholds to provide alerts and system wake-ups without requiring a microcontroller to be continuously monitoring the system. Combined with programmable sampling intervals, a low power consumption, and a support for a 1.8-V supply voltage, the HDC2080 is designed for battery-operated systems.

The HDC2080 provides high accuracy measurement capability for a wide range of environmental monitoring and Internet of Things (IoT) applications such as smart thermostats and smart home assistants. For designs where printed-circuit board (PCB) area is critical, a smaller CSP package option is available thru the HDC2010 with complete software compatibility with the HDC2080.

For applications with strict power-budget restrictions, Auto Measurement Mode enables the HDC2080 to automatically initiate temperature and humidity measurements. This feature allows users to configure a microcontroller into deep sleep mode because the HDC2080 is no longer dependent upon the microcontroller to initiate a measurement.

Programable temperature and humidity thresholds in the HDC2080 allow the device to send a hardware interrupt to wake up the microcontroller when necessary. In addition, the power consumption of the HDC2080 is significantly reduced, which helps to minimize self-heating and improve measurement accuracy.

The HDC2080 is factory-calibrated to 0.2°C temperature accuracy and 2% relative humidity accuracy.

Features

Relative humidity range: 0% to 100%
Humidity accuracy: ±2% (typical), ±3% (maximum)
Temperature accuracy: ±0.2°C (typical), ±0.4°C (maximum)
Sleep mode current: 50 nA (typical), 100 nA (maximum)
Average supply current (1 measurement/second)
300 nA: RH% only (11 bit)
550 nA: RH% (11 bit) + temperature (11 bit)

Temperature range:
Operating: –40°C to 85°C
Functional: –40°C to 125°C
Supply voltage range: 1.62 V to 3.6 V

 

Parts Required

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

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
HDC2080HDC2080 Temperature and Humidity Low Power Digital I2C 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

Schematic/Connection

This is a 3.3v rated sensor even though the pin says Vcc

arduino and hdc2080 breadboard

arduino and hdc2080_bb

Code Example

I used the library from https://github.com/tinkeringtech/HDC2080_breakout

This is the default example with a few cosmetic changes

#include <HDC2080.h>
 
#define ADDR 0x40
HDC2080 sensor(ADDR);
 
float temperature = 0, humidity = 0;
 
void setup() {
 
  Serial.begin(9600);
  Serial.println("TinkeringTech HDC2080 Test");
 
  // Initialize I2C communication
  sensor.begin();
 
  // Begin with a device reset
  sensor.reset();
 
  // Set up the comfort zone
  sensor.setHighTemp(48);         // High temperature of 28C
  sensor.setLowTemp(2);          // Low temperature of 22C
  sensor.setHighHumidity(95);     // High humidity of 55%
  sensor.setLowHumidity(10);      // Low humidity of 40%
 
  // Configure Measurements
  sensor.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  sensor.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  sensor.setTempRes(FOURTEEN_BIT);
  sensor.setHumidRes(FOURTEEN_BIT);
 
  //begin measuring
  sensor.triggerMeasurement();
}
 
void loop() {
 
  Serial.print("Temperature (C): ");
  Serial.print(sensor.readTemp());
  Serial.print("\t\tHumidity (%): ");
  Serial.println(sensor.readHumidity());
 
  // Wait 1 second for the next reading
  delay(2000);
 
}

 

Output

Open the serial monitor and you should see something like this

Temperature (C): 25.14 Humidity (%): 52.86
Temperature (C): 25.12 Humidity (%): 52.89
Temperature (C): 25.11 Humidity (%): 52.95
Temperature (C): 25.10 Humidity (%): 52.96
Temperature (C): 25.17 Humidity (%): 53.18

I do get some erratic readings at times, values like the following. I haven’t investigated this fully – I did try and increase and decrease the delay between readings with no luck.

Temperature (C): -40.00 Humidity (%): 0.00

 

Links

https://www.ti.com/lit/gpn/hdc2080

 

Summary

A nice little sensor but at just over $8 there are cheaper sensors available which have the same functionality, the library and code may need some work to work more reliably.

Share

Arduino and MAX4466 electret module example

In this article we look at an electret microphone which uses a MAX4466 op amp – you can buy these max4466 modules

Lets look at what Maxim say about the MAX4466

The MAX4465–MAX4469 are micropower op amps optimized for use as microphone preamplifiers. They provide the ideal combination of an optimized gain bandwidth product vs. supply current, and low-voltage operation in an ultra-small package. The MAX4465/MAX4467/MAX4469 are unity-gain stable and deliver a 200kHz gain bandwidth from only 24µA of supply current. The MAX4466/MAX4468 are decompensated for a minimum stable gain of +5V/V and provide a 600kHz gain bandwidth product. In addition these amplifiers feature rail-to-rail outputs, high AVOL, plus excellent power-supply rejection and common-mode rejection ratios for operation in noisy environments.

The MAX4467/MAX4468 include a complete shutdown mode. In shutdown, the amplifiers’ supply current is reduced to 5nA and the bias current to the external microphone is cut off for ultimate power savings. The single MAX4465/MAX4466 are offered in the ultra-small 5-pin SC70 package, while the single with shutdown MAX4467/MAX4468 and dual MAX4469 are available in the space-saving 8-pin SOT23 package.

Features

  • +2.4V to +5.5V Supply Voltage Operation
  • Versions with 5nA Complete Shutdown Available (MAX4467/MAX4468)
  • Excellent Power-Supply Rejection Ratio: 112dB
  • Excellent Common-Mode Rejection Ratio: 126dB
  • High AVOL: 125dB (RL = 100kΩ)
  • Rail-to-Rail Outputs
  • Low 24µA Quiescent Supply Current
  • Gain Bandwidth Product:
    • 200kHz (MAX4465/MAX4467/MAX4469)
    • 600kHz AV ≥ 5 (MAX4466/MAX4468)
  • Available in Space-Saving Packages
    • 5-Pin SC70 (MAX4465/MAX4466)
    • 8-Pin SOT23 (MAX4467/MAX4468/MAX4469)

 

Connection

 

Arduino UnoMAX4466 module
5vVcc
GndGnd
A0OUT

 

 

arduino and max4466

arduino and max4466

Parts List

Here are the parts I used

Part nameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
MAX4466 moduleGY-MAX4466 electret microphone amplifier MAX4466 adjustable amplifier module
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cablefor Arduino

 

Code

This is actually an adafruit example which uses sampling – you could also simply read the analog value in. This is better

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
 
void setup()
{
   Serial.begin(9600);
}
 
 
void loop()
{
   unsigned long startMillis= millis();  // Start of sample window
   unsigned int peakToPeak = 0;   // peak-to-peak level
 
   unsigned int signalMax = 0;
   unsigned int signalMin = 1024;
 
   // collect data for 50 mS
   while (millis() - startMillis < sampleWindow)
   {
      sample = analogRead(A0);
      if (sample < 1024)  // toss out spurious readings
      {
         if (sample > signalMax)
         {
            signalMax = sample;  // save just the max levels
         }
         else if (sample < signalMin)
         {
            signalMin = sample;  // save just the min levels
         }
      }
   }
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   double volts = (peakToPeak * 5.0) / 1024;  // convert to volts
 
   Serial.println(volts);
}

 

Links

 

 

Share

Arduino and OPEN-SMART Round Film Force Sensitive Resistor

In this article we look at an FSR from Open Smart – here is the information I have found on this module

FSRs are basically a resistor that changes its resistive value (in ohms Ω) depending on how much it is pressed.
The FSR is made of 2 layers separated by a spacer. The more one presses, the more of those Active Element dots touch the semiconductor and that makes the resistance go down.

Suggest you to connect it series with a 1k ohm resistor, so that you can detect the voltage so that you can calculate its resistance.

Features:
– No load resistance: >1000kOhm
– Load resistance: <1kOhm @50N
– Working Voltage VCC: 5.5 VDC(MAX)
– Working Current: 5 mA(MAX)
– Pressure Scale: 0-50N
– Response time:  < 10ms
– Recovery Time:  < 40ms
– Sensing area diameter: 9mm
– Total length: 40mm

 

Connection

 

Arduino UnoOpen Smart FSR
5vVcc
GndGnd
A0SIG

 

Parts List

Here are the parts I used

Part nameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
Open Smart FSRFilm Force Sensitive Resistor 50N / 5kg FSR Sensor Module for Arduino
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire Dupont cablefor Arduino

 

Code

There are 2 code examples – I have republished them here

Example 1

#define FSR_PIN A0//SIG of FSR sensor module connect to A0 of Arduino
#define DIVIDER_RES 10 //the resistance of the resistor connect with the FSR resistor in series.
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
 
}
 
// the loop routine runs over and over again forever:
void loop() {
 
  int sensorValue = analogRead(FSR_PIN);
  float val = sensorValue;
  float res = DIVIDER_RES*1023.00/val-DIVIDER_RES;
  //print out the value you read:
  Serial.println(sensorValue);
  Serial.print(res);
  Serial.println("KOhm");
  judgeForce(res);
  delay(600);        // delay in between reads for stability
}
 
void judgeForce(float res)
{
  if(res > 1200) Serial.println("Nothing on the FSR");
  else if(res > 300) Serial.println("Did you have breakfast? Your strength is too small.");
  else if(res > 50) Serial.println("Your strength can be bigger...");
  else if(res > 15) Serial.println("Man, your strength is big!");
  else Serial.println("You are most strong in the world!");
}

Example 2

#define S0 3 //S0 of the LED Bar module connect to D3 of Arduino
#define S1 4 
#define S2 5
#define S3 6
#define S4 7
#define S5 8
#define S6 9
#define S7 10
const int leds[] = {S0, S1, S2, S3, S4, S5, S6, S7};
 
#define FSR_PIN A0 //SIG of FSR sensor module connect to A0 of Arduino
 
#define MAX_SENSORVALUE 150
#define MAX_LIGHT_LEVEL 8
// the setup routine runs once when you press reset:
void setup() {
 
  for(uint8_t i=0;i < 8; i++){
   pinMode(leds[i], OUTPUT);
 }
 for(uint8_t i=0;i < 8; i++)
  {
    ledOff(i);
  }
}
 
// the loop routine runs over and over again forever:
void loop() {
  int sensorValue = analogRead(FSR_PIN); //the greater the pressure in the sensing area, the higher the output voltage,
                                          //and larger the sensorValue.
  int level = map(sensorValue, 0, MAX_SENSORVALUE, 0, MAX_LIGHT_LEVEL); //convert the sensor value to the light level
  levelOn(level);
}
 
//------------------------------------
void ledOn(uint8_t Sx)
{
  digitalWrite(leds[Sx], LOW);
}
void ledOff(uint8_t Sx)
{
  digitalWrite(leds[Sx], HIGH);
}
 
void levelOn(uint8_t level)
{
  if(level > 8) level = 8;
  for(uint8_t i = 0; i < level;i ++)
  {
    ledOn(i);
  }
  for(uint8_t i = level; i < 8;i ++)
  {
    ledOff(i);
  }
}
//-------------------------------------------

 

Links

FP9-40

 

Share