Categories

Arduino and LPS22HB absolute pressure sensor example

In this article we look at another absolute pressure sensor – this time its the LPS22HB

The LPS22HB is an ultra-compact piezoresistive absolute pressure sensor which functions as a digital output barometer. The device comprises a sensing element and an IC interface which communicates through I2C or SPI from the sensing element to the application.

The sensing element, which detects absolute pressure, consists of a suspended membrane manufactured using a dedicated process developed by ST.
The LPS22HB is available in a full-mold, holed LGA package (HLGA). It is guaranteed to operate over a temperature range extending from -40 °C to +85 °C. The package is holed to allow external pressure to reach the sensing element.

Features

  • 260 to 1260 hPa absolute pressure range
  • Current consumption down to 3 μA
  • High overpressure capability: 20x full-scale
  • Embedded temperature compensation
  • 24-bit pressure data output
  • 16-bit temperature data output
  • ODR from 1 Hz to 75 Hz
  • SPI and I²C interfaces
  • Embedded FIFO
  • Interrupt functions: Data Ready, FIFO flags, pressure thresholds
  • Supply voltage: 1.7 to 3.6 V
  • High shock survivability: 22,000 g

 

Parts Required

 

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
LPS22HBSemoic Lps22Hb Pressure Resistance Pressure Sensor Module for High Intensity Industrial Control
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 LPS22HB

arduino and LPS22HB

 

Code Example

This uses the library from hhttps://github.com/adrien3d/IO_LPS22HB

/***************************************************************************
This is a library for the LPS22HB Absolute Digital Barometer
Designed to work with all kinds of LPS22HB Breakout Boards
These sensors use I2C, 2 pins are required to interface, as this :
VDD to 3.3V DC
SCL to A5
SDA to A4
GND to common groud
Written by Adrien Chapelet for IoThings
***************************************************************************/
#include <Wire.h>
#include "IO_LPS22HB.h"
IO_LPS22HB lps22hb;
void setup()
{
Serial.begin(9600);
Serial.println("IoThings LPS22HB Arduino Test");
lps22hb.begin(0x5D);
byte who_am_i = lps22hb.whoAmI();
Serial.print("Who Am I? 0x");
Serial.print(who_am_i, HEX);
Serial.println(" (expected: 0xB1)");
if (who_am_i != LPS22HB_WHO_AM_I_VALUE) {
Serial.println("Error while retrieving WHO_AM_I byte...");
while (true) {
// loop forever
}
}
}
void loop()
{
Serial.print("P=");
Serial.print(lps22hb.readPressure());
Serial.print(" mbar, T=");
Serial.print(lps22hb.readTemperature());
Serial.println("C");
delay(300);
}

 

Output

Open the serial monitor and you should see something like this

IoThings LPS22HB Arduino Test
Who Am I? 0xB1 (expected: 0xB1)
P=982.52 mbar, T=18.21C
P=982.56 mbar, T=18.25C
P=982.51 mbar, T=18.26C
P=982.52 mbar, T=18.27C
P=982.54 mbar, T=18.27C
P=982.55 mbar, T=18.27C
P=982.51 mbar, T=18.26C
P=982.55 mbar, T=18.26C
P=982.55 mbar, T=18.26C

 

Links

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

 

 

Share

Arduino and BMM150 digital geomagnetic sensor example

In this article we look at a digital geomagnetic sensor – this time its the BMM150

BMM150 is a low power and low noise 3-axis digital geomagnetic sensor to be used in compass applications. The 12-pin wafer level chip scale package (WLCSP) with a footprint of 1.56 x 1.56 mm² and 0.60 mm height provides highest design flexibility to the developer of mobile devices. Applications like virtual reality or gaming on mobile devices such as mobile phones, tablet PCs or portable media players require 9-axis inertial sensing including magnetic heading information. Due to the stable performance over a large temperature range, the BMM150 is also especially suited for supporting drones in accurate heading.

BMM150 can be used with an inertial measurement unit (IMU) consisting of a 3-axis accelerometer and a 3-axis gyroscope like Bosch Sensortec’s BMI055.

 

Features

ParameterTechnical data
PackageCSWLP- (12 pin)
1.56×1.56×0.6 mm³
0.4 mm diagonal ball pitch
Temperature range-40°C … +85°C
Digital interfacesI²C and SPI
(2 interrupt pins)
Resolution0.3μT
Supply voltageVDD: 1.62V to 3.6V
VDDIO: 1.2V to 3.6V
Zero-B offset±50μT
Non-linearity<1% FS
Magnetic range typ.±1300μT (x,y-axis)
±2500μT (z-axis)
Average current consumption170 μA (low power preset)
500 μA (normal mode)
InterruptsNew data, magnetic threshold high / low

Parts Required

 

NameLink
Arduino UnoUNO R3 CH340G/ATmega328P, compatible for Arduino UNO
BMM150BMM150 Geomagnetic Sensor Breakout Board
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 BMM150

arduino and BMM150

 

Code Example

This uses the library from https://github.com/Seeed-Studio/Grove_3_Axis_Compass_V2.0_BMM150

#include <Arduino.h>
#include <Wire.h>
// libraries
#include "bmm150.h"
#include "bmm150_defs.h"
BMM150 bmm = BMM150();
void setup()
{
Serial.begin(9600);
if(bmm.initialize() == BMM150_E_ID_NOT_CONFORM) {
Serial.println("Chip ID can not read!");
while(1);
} else {
Serial.println("Initialize done!");
}
}
void loop()
{
bmm150_mag_data value;
bmm.read_mag_data();
value.x = bmm.raw_mag_data.raw_datax;
value.y = bmm.raw_mag_data.raw_datay;
value.z = bmm.raw_mag_data.raw_dataz;
float xyHeading = atan2(value.x, value.y);
float zxHeading = atan2(value.z, value.x);
float heading = xyHeading;
if(heading < 0)
heading += 2*PI;
if(heading > 2*PI)
heading -= 2*PI;
float headingDegrees = heading * 180/M_PI;
float xyHeadingDegrees = xyHeading * 180 / M_PI;
float zxHeadingDegrees = zxHeading * 180 / M_PI;
Serial.print("Heading: ");
Serial.println(headingDegrees);
delay(100);
}

 

Output

Open the serial monitor and you should see something like this – the results would have been more interesting if I moved the sensor but I was checking the stability

Heading: 261.09
Heading: 262.21
Heading: 261.05
Heading: 260.50
Heading: 260.42
Heading: 260.13
Heading: 260.81
Heading: 259.46

 

Links

https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMM150-DS001.pdf

https://github.com/BoschSensortec/BMM150-Sensor-API

 

Share

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