Categories

Arduino and LPS25H piezoresistive pressure sensor example

In this article we look at a pressure sensor – this time its the LPS25H

The LPS25H is an ultra-compact absolute piezoresistive pressure sensor. It includes a monolithic sensing element and an IC interface able to take the information from the sensing element and to provide a digital signal to the external world.

The sensing element consists of a suspended membrane realized inside a single mono-silicon substrate. It is capable of detecting pressure and is manufactured using a dedicated process developed by ST.
The membrane is very small compared to the traditionally built silicon micromachined membranes. Membrane breakage is prevented by an intrinsic mechanical stopper.
The IC interface is manufactured using a standard CMOS process that allows a high level of integration to design a dedicated circuit which is trimmed to better match the sensing element characteristics.
The LPS25H is available in a cavity holed LGA package (HLGA). It is guaranteed to operate over a temperature range extending from -30 °C to +105 °C. The package is holed to allow external pressure to reach the sensing element.

Features

260 to 1260 mbar absolute pressure range
High-resolution mode: 1 Pa RMS
Low power consumption
Low-resolution mode: 4 μA
High-resolution mode: 25 μA
High overpressure capability: 20x full scale
Embedded temperature compensation
Embedded 24-bit ADC
Selectable ODR from 1 Hz to 25 Hz
SPI and I²C interfaces
Supply voltage: 1.7 to 3.6 V
High shock survivability: 10,000 g

 

Parts Required

 

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
LPS25HDiybigworld LPS25HTR ST CJMCU-25 Miniature high Precision Pressure Sensor Temperature Compensation
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

 

arduino and LPS25H

arduino and LPS25H

 

Code Example

This uses the library from https://github.com/pololu/lps-arduino

#include <Wire.h>
#include <LPS.h>
LPS ps;
void setup()
{
Serial.begin(9600);
Wire.begin();
if (!ps.init())
{
Serial.println("Failed to autodetect pressure sensor!");
while (1);
}
ps.enableDefault();
}
void loop()
{
float pressure = ps.readPressureMillibars();
float altitude = ps.pressureToAltitudeMeters(pressure);
float temperature = ps.readTemperatureC();
Serial.print("p: ");
Serial.print(pressure);
Serial.print(" mbar\ta: ");
Serial.print(altitude);
Serial.print(" m\tt: ");
Serial.print(temperature);
Serial.println(" deg C");
delay(100);
}

 

Output

Open the serial monitor and you should see something like this

p: 987.37 mbar a: 217.67 m t: 22.88 deg C
p: 987.19 mbar a: 219.24 m t: 23.07 deg C
p: 987.31 mbar a: 218.22 m t: 23.26 deg C
p: 986.94 mbar a: 221.34 m t: 23.45 deg C
p: 986.80 mbar a: 222.55 m t: 23.79 deg C
p: 986.75 mbar a: 222.95 m t: 23.95 deg C
p: 986.67 mbar a: 223.69 m t: 24.11 deg C
p: 986.59 mbar a: 224.32 m t: 24.40 deg C
p: 986.55 mbar a: 224.63 m t: 24.54 deg C
p: 986.43 mbar a: 225.68 m t: 24.68 deg C
p: 986.39 mbar a: 226.02 m t: 24.95 deg C
p: 986.51 mbar a: 225.01 m t: 25.07 deg C
p: 986.47 mbar a: 225.35 m t: 25.20 deg C

 

Links

https://www.st.com/resource/en/datasheet/lps25h.pdf

Share

Arduino and BH1745NUC Luminance and Colour Sensor example

In this article we look at a BH1745NUC Luminance and Colour Sensor and connect it to an Arduino

The BH1745NUC is digital color sensor IC with I²C bus interface. This IC senses Red, Green and Blue light (RGB) and converts them to digital values. The high sensitivity, wide dynamic range and excellent Ircut characteristics makes this IC the most suitable to obtain the illuminance and color temperature of ambient light for adjusting LCD backlight of TV, mobile phone and tablet PC. It is possible to detect very wide range light intensity. (0.005 – 40k lx)

Specifications:

VCC Voltage Range: 2.3V to 3.6V
Maximum Sensitivity: 0.005Lx/step
Current Consumption: 130μA (Typ)
Standby Mode Current: 0.8μA (Typ)
Operating Temperature Range: -40°C to +85°C

Features

The High Sensitivity and Wide Dynamic Range (0.005 – 40k lx)
Supports Low Transmittance (Dark) Window
Correspond to I²C Bus Interface
Low Current by Power Down Function
Rejecting 50Hz/60Hz Light Noise
Correspond to 1.8V Logic Interface
Programmable Interrupt Function
It is possible to select 2 type of I²C bus slave address (ADDR =’L’: “0111000”, ADDR =’H’: “0111001”)

Here is a typical module that I used

 

 

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
BH1745NUCBH1745NUC Digital Color Sensor RGB Detecting Sensor Light Module
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

Be careful as I used a CJMCU-1745 – the sensor is rated at 2.3V to 3.6V. So use the 3.3v out

 

ArduinoSensor
3.3vVIN
GndGnd
SDASDA
SCLSCL

Code Example

 

This is a controleverything example – they have code examples for various platforms

#include <Wire.h>
 
// I2C address of the BH1745NUC
#define Addr 0x38
 
void setup()
{
    // Initialise I2C communication as MASTER
    Wire.begin();
    // Initialise serial communication, set baud rate = 9600
    Serial.begin(9600);
 
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select mode control register1
    Wire.write(0x41);
    // Set RGBC measurement time 160 msec
    Wire.write(0x00);
    // Stop I2C Transmission
    Wire.endTransmission();
 
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select mode control register2
    Wire.write(0x42);
    // Set measurement mode is active, gain = 1x
    Wire.write(0x90);
    // Stop I2C Transmission
    Wire.endTransmission();
 
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Select mode control register3
    Wire.write(0x44);
    // Set default value
    Wire.write(0x02);
    // Stop I2C Transmission
    Wire.endTransmission();
    delay(300);
}
 
void loop()
{
    unsigned int data[8];
    for(int i = 0; i < 8; i++)
    {
        // Start I2C Transmission
        Wire.beginTransmission(Addr);
        // Select data register
        Wire.write((80+i));
        // Stop I2C Transmission
        Wire.endTransmission();
 
        // Request 1 byte of data from the device
        Wire.requestFrom(Addr, 1);
 
        // Read 8 bytes of data
        // Red lsb, Red msb, Green lsb, Green msb, Blue lsb, Blue msb
        // cData lsb, cData msb
        if(Wire.available() == 1)
        {
            data[i] = Wire.read();
        }
        delay(300);
    }
 
    // Convert the data
    int red = ((data[1] & 0xFF) * 256) + (data[0] & 0xFF);
    int green = ((data[3] & 0xFF) * 256) + (data[2] & 0xFF);
    int blue = ((data[5] & 0xFF) * 256) + (data[4] & 0xFF);
    int cData = ((data[7] & 0xFF) * 256) + (data[6] & 0xFF);
 
    // Output data to serial monitor
    Serial.print("Red Color luminance  : ");
    Serial.println(red);
    Serial.print("Green Color luminance : ");
    Serial.println(green);
    Serial.print("Blue Color luminance : ");
    Serial.println(blue);
    Serial.print("Clear Data Color luminance : ");
    Serial.println(cData);
}

 

Output

Open the serial monitor and you should see something like the following

Red Color luminance : 46
Green Color luminance : 54
Blue Color luminance : 25
Clear Data Color luminance : 7
Red Color luminance : 44
Green Color luminance : 54
Blue Color luminance : 25
Clear Data Color luminance : 8
Red Color luminance : 45
Green Color luminance : 48
Blue Color luminance : 21
Clear Data Color luminance : 9

Place different colored objects beside the sensor and check the values

Share

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