Follow Us

Arduino and BME environmental sensor example

In this article we will connect a BME680 sensor to an Arduino

BME680 is an integrated environmental sensor developed specifically for mobile applications and wearables where size and low power consumption are key requirements. Expanding Bosch Sensortec’s existing family of environmental sensors, the BME680 integrates for the first time high-linearity and high-accuracy gas, pressure, humidity and temperature sensors. The gas sensor within the BME680 can detect a broad range of gases to measure air quality for personal well being.

Gases that can be detected by the BME680 include Volatile Organic Compounds (VOC) from paints (such as formaldehyde), lacquers, paint strippers, cleaning supplies, furnishings, office equipment, glues, adhesives and alcohol.

Parameter Technical data
Package dimensions 8-Pin LGA with metal
3.0 x 3.0 x 0.93 mm³
Operation range (full accuracy) Pressure: 300…1100 hPa
Humidity 0…100%
Temperature: -40…85°C
Supply voltage VDDIO
Supply voltage VDD
1.2 … 3.6 V
1.71 … 3.6 V
Interface I²C and SPI
Average current consumption
(1Hz data refresh rate)
2.1 µA at 1 Hz humidity and temperature
3.1 µA at 1 Hz pressure and temperature
3.7 µA at 1 Hz humidity, pressure and temperature 0.09‒12 mA for p/h/T/gas depending on operation mode
Average current consumption in sleep mode 0.15 μA
Gas sensor
Response time (τ 33-63%)
Sensor-to-sensor deviation
Power consumption
Output data processing
< 1 s (for new sensors)
+/- 15% +/- 15
< 0.1 mA in ultra-low power mode
direct output of IAQ: Index for Air Quality
Humidity sensor
Response time (τ0-63%)
Accuracy tolerance
8 s
± 3 % relative humidity
≤ 1.5 % relative humidity
Pressure sensor
RMS Noise
Sensitivity Error
Temperature coefficient offset
0.12 Pa (equiv. to 1.7 cm)
± 0.25 % (equiv. to 1 m at 400 m height change)
±1.3 Pa/K (equiv. to ±10.9 cm at 1°C temperature change)


Parts List

Name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
BME680 BME680 Sensor Module Temperature and Humidity Air Pressure Air Quality IAQ MCU680 Module
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire


We use the I2C connection for the sensor

arduino and bme680

arduino and bme680



You will need to import the adafruit sensor and bme680 libraries – you can add these using the library manager

My particular sensor used address 0x76, the default is 0x77 so you may have to change this line from if (!bme.begin(0x76)) to if (!bme.begin())


#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C
void setup() {
  while (!Serial);
  Serial.println(F("BME680 test"));
  if (!bme.begin(0x76)) 
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  // Set up oversampling and filter initialization
  bme.setGasHeater(320, 150); // 320*C for 150 ms
void loop() 
  if (! bme.performReading()) 
    Serial.println("Failed to perform reading :(");
  Serial.print("Temperature = ");
  Serial.println(" *C");
  Serial.print("Pressure = ");
  Serial.print(bme.pressure / 100.0);
  Serial.println(" hPa");
  Serial.print("Humidity = ");
  Serial.println(" %");
  Serial.print("Gas = ");
  Serial.print(bme.gas_resistance / 1000.0);
  Serial.println(" KOhms");
  Serial.print("Approx. Altitude = ");
  Serial.println(" m");



Open the serial monitor and you will see something like this

BME680 test
Temperature = 21.52 *C
Pressure = 971.46 hPa
Humidity = 42.24 %
Gas = 0.00 KOhms
Approx. Altitude = 353.89 m

Temperature = 22.38 *C
Pressure = 971.44 hPa
Humidity = 42.71 %
Gas = 144.27 KOhms
Approx. Altitude = 354.06 m

Temperature = 24.83 *C
Pressure = 971.46 hPa
Humidity = 43.88 %
Gas = 139.47 KOhms
Approx. Altitude = 353.72 m


Arduino and MCP3424 A/D converter example

Arduino and MCP3424 A/D converter example, lets look at the device.

The MCP3424 is a four channel low-noise, high accuracy delta-sigma A/D converter with differential inputs and up to 18 bits of resolution. The on-board precision 2.048V reference voltage enables an input range of ±2.048V differentially. The device uses a two-wire I2C™ compatible serial interface and operates from a single power supply ranging from 2.7V to 5.5V.

The MCP3424 device performs conversions at rates of 3.75, 15, 60 or 240 samples per second depending on user controllable configuration bit settings using the two-wire I2C™ compatible serial interface. The I2C™ address is user configurable with two address selection pins. This device has an onboard programmable gain amplifier (PGA). User can select the PGA gain of x1, x2, x4, or x8 before the analog-to-digital conversion takes place. This allows the MCP3424 device to convert a smaller input signal with high resolution. The device has two conversion modes: (a) Continuous mode and (b) One-Shot mode.

In One-Shot mode, the device enters a low current standby mode automatically after one conversion. This reduces current consumption greatly during idle periods. The MCP3424 device can be used for various high accuracy analog-to-digital data conversion applications where ease of use, low power consumption and small footprint are major considerations.

    • 18-bit resolution
    • 4-channel differential input operation
    • Differential input operation
    • On-board voltage reference with 15 ppm/°C drift
    • On-board PGA, gains of 1, 2, 4, 8
    • Programmable data rate options
      • 3.75 SPS (18 bits)
      • 15 SPS (16 bits)
      • 60 SPS (14 bits)
      • 240 SPS (12 bits)
    • INL 10 ppm of FSR max
    • Low current consumption, 135 µA at 3V
    • One-shot or continuous conversion options
    • Supports I2C™ serial interface with user configurable addresses
    • Extended temperature range: -40°C to +125°C


Parts List

Part Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
MCP3424 module MCP3424 Digital I2C ADC-4 Channel Conversion Module
Connecting cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



You need to install the following library –

#include <Wire.h>
#include <MCP3424.h>
void setup() 
    adc.creg[CH1].bits = { GAINx1, SR18B, CONTINUOUS, CH1, 1 };
double value;
static char * errmsg[] = {"", "underflow", "overflow", "i2c", "in progress", "timeout"};
void loop() 
    ConvStatus err =, value);
    if (err == R_OK) 
      Serial.println(value, DEC); 
      Serial.print("conversion error: ");
    asm volatile ("nop");


Open the serial monitor – the low reading was ground and the higher reading was 3.3v



LIS3DSH accelerometer sensor and Arduino example

In this example we connect a LIS3DSH sensor to an Arduino. Lets look at the sensor

The LIS3DSH is an ultra-low-power high-performance three-axis linear accelerometer belonging to the “nano” family with an embedded state machine that can be programmed to implement autonomous applications.

The LIS3DSH has dynamically selectable full scales of ±2g/±4g/±6g/±8g/±16g and is capable of measuring accelerations with output data rates from 3.125 Hz to 1.6 kHz. The self-test capability allows the user to check the functioning of the sensor in the final application. The device can be configured to generate interrupt signals activated by user-defined motion patterns.

The LIS3DSH has an integrated first-in, first-out (FIFO) buffer allowing the user to store data in order to limit intervention by the host processor. The LIS3DSH is available in a small thin plastic land grid array package (LGA) and is guaranteed to operate over an extended temperature range from -40 °C to +85 °C.

Key Features

  • Wide supply voltage, 1.71 V to 3.6 V
  • Independent IOs supply (1.8 V) and supply voltage compatible
  • Ultra-low power consumption
  • ±2g/±4g/±6g/±8g/±16g dynamically selectable full scale
  • I2C/SPI digital output interface
  • 16-bit data output
  • Programmable embedded state machines
  • Embedded temperature sensor
  • Embedded self-test
  • Embedded FIFO
  • 10000 g high shock survivability


Parts List

Part Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
LIS3DSH module CJMCU- LIS3DSH High-resolution Three-axis Accelerometer Triaxial Accelerometer Module LIS3DH
Connecting Wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



An easy device to connect – remember its 3.3v

Arduino and LIS3DSH

Arduino and LIS3DSH



You need to download and install the library

#include <Wire.h>
#include <LIS3DSH.h>
LIS3DSH accel;
void setup() 
void loop() 
  int16_t x, y, z;
  int8_t temperature;
  accel.readAccel(&x, &y, &z);
  Serial.print("Accel ");
  Serial.print("X: ");
  Serial.print(" Y: ");
  Serial.print(" Z: ");
  Serial.print(" T: ");



Open the serial monitor and you should see something like this – move the module around

Accel X: -16041 Y: 25096 Z: 30902 T: -5
Accel X: -4264 Y: -3219 Z: -4920 T: -5
Accel X: -3665 Y: -24195 Z: -6582 T: -5
Accel X: -2387 Y: 29273 Z: 25093 T: -5
Accel X: -10046 Y: 18720 Z: 15595 T: -5
Accel X: -19708 Y: -2226 Z: 5157 T: -6
Accel X: -13490 Y: -2875 Z: -2190 T: -6
Accel X: -10057 Y: 11695 Z: 22556 T: -6
Accel X: 1924 Y: 27351 Z: 16082 T: -5
Accel X: -4231 Y: 18639 Z: 14947 T: -5
Accel X: -17774 Y: -2564 Z: 6430 T: -5
Accel X: -13527 Y: -7457 Z: 5894 T: -5
Accel X: -20130 Y: -15443 Z: 10049 T: -5
Accel X: 3386 Y: -1488 Z: 17183 T: -5
Accel X: -2989 Y: 15951 Z: 9403 T: -6
Accel X: -15118 Y: 9226 Z: 6249 T: -6





Arduino and PCF8575 I/O expander examples

This 16-bit I/O expander for the two-line bidirectional bus (I2C) is designed for 2.5-V to 5.5-V VCC operation.

The PCF8575 device provides general-purpose remote I/O expansion for most microcontroller families by way of the I2C interface [serial clock (SCL), serial data (SDA)].

The device features a 16-bit quasi-bidirectional input/output (I/O) port (P07–P00, P17–P10), including latched outputs with high-current drive capability for directly driving LEDs. Each quasi-bidirectional I/O can be used as an input or output without the use of a data-direction control signal. At power on, the I/Os are high. In this mode, only a current source to VCC is active.


  • I2C to Parallel-Port Expander
  • Open-Drain Interrupt Output
  • Low Standby-Current Consumption of 10 µA Max
  • Compatible With Most Microcontrollers
  • 400-kHz Fast I2C Bus
  • Address by Three Hardware Address Pins for Use of up to Eight Devices
  • Latched Outputs With High-Current Drive Capability for Directly Driving LEDs



This example shows only one LED

Arduino and PCF8575

Arduino and PCF8575


Parts List

Part Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
Dupont cable Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
PCF8575 PCF8575 IIC I2C I/O Extension Shield Module 16 bit SMBus I/O


Code examples

Output – switch LED on and off

#include <Wire.h>
// Set I2C address
int address = 0x20;
void setup()
  // Set all ports as output
void loop()
  // Set port P0 on
  // Set port P0 off
// Function for writing two Bytes to the I2C expander device
void pf575_write(uint16_t data) 


Output – switch LEDs on and off

#include <Wire.h>
byte address = 0x20;   // address of PCF8575
void setup()
   Wire.begin();       // join i2c bus as master
void loop()
  unsigned char x;
  unsigned char y;
  for (x=0, y=255; (x+y)==255; x++, y--)
      Wire.beginTransmission(address);   // send the address and the write cmnd
      Wire.write(x);                      // pack the first byte
      Wire.write(y);                      // pack the second byte
      Wire.endTransmission();            // send the data