RPI-1031 tilt sensor and Wemos Mini example

In this article we look at a tilt sensor – this time its the RPI-1031 and we will connect it to a Wemos

The RPI-1031 tilt sensor is capable of sensing a change in orientation in four different directions: forward, back, left or right</p

This tilt sensor can be used to detect multiple orientations. Inside the sensor are infrared emitters which are either reflected or not, depending on the orientation of the sensor. By reading the output of the various pins you can easily determine the orientation of the sensor and your project.

Being a tilt sensor this is just a metal ball that rolls around inside the case. The ball is always up against one side even when it is flat.

The sensor needs power and ground, you can then connect the 2 digital pins. These 2 digital pins will output LOW/LOW, LOW/HIGH, HIGH/LOW and HIGH/HIGH depending on the wall it is touching.

Parts Required


Name Link
Wemos Mini D1 mini – ESP8266
RPI-1031 RPI-1031 Angle Sensor 4DOF Attitude HM Module 4 Direction For Arduino
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
sensor shield Expansion IO Board Sensor Shield


Wemos Sensor
3v3 Vcc
Gnd Gnd
D5 S1
D6 S2



Code Example

The code for this sensor is really basic, it just checks the 2 pins, to see what side is being touched – The simple function simply takes the 2 digital outputs and returns 0,1,2 or 3 depending on the side.

int tilt_s1 = 2;
int tilt_s2 = 3;
void setup(){
pinMode(tilt_s1, INPUT);
pinMode(tilt_s2, INPUT);
void loop(){
int position = getTiltPosition();
delay(200); //only here to slow down the serial output
int getTiltPosition(){
int s1 = digitalRead(tilt_s1);
int s2 = digitalRead(tilt_s2);
return (s1 << 1) | s2; //bitwise math to combine the values



Open the serial monitor and you should see something like this, I was moving the sensor around.

Not the most intuitive readings admittedly and it seems to work










SHTC1 digital humidity sensor and ESP8266 example

In this article we look at another digital humidity sensor – this time its the SHTC1 and we will connect it to a Wemos Mini

The SHTC1 is a digital humidity sensor designed especially for high-volume consumer electronics applications. This humidity sensor is strictly designed to overcome conventional limits for size, power consumption, and price-performance ratio, in order to fulfill the current and future requirements of the consumer electronics market.

Sensirion’s CMOSens® technology offers a complete sensor system on a single chip, consisting of a capacitive humidity sensor, a band-gap temperature sensor, analog and digital signal processing, A/D converter, calibration data memory, and a digital communication interface supporting I2C fast mode. The ultra-small, 2 × 2 × 0.75 mm3 DFN package enables applications to be placed in even the most limited of spaces. The sensor covers a humidity measurement range of 0 to 100 %RH and a temperature measurement range of –30°C to 100°C with a typical accuracy of ±3 %RH and ±0.3°C.

The operating voltage of 1.8 V and an energy budget below 1 µJ per measurement make the SHTC1 suitable for mobile or wireless applications running on the lowest power budgets. With the industry-proven quality and reliability of Sensirion’s humidity sensors and constant accuracy over a large measurement range, the SHTC1 humidity sensor offers an unprecedented price-performance ratio. Tape and reel packaging together with suitability for standard SMD assembly processes make the SHTC1 predestined for high-volume applications.


Interface I²C
Supply voltage 1.8 V
Power consumption 2µW (at 1 reading per second in low power mode)
Measuring range (RH) 0 – 100% relative humidity
Measuring range (T) -30 to +100°C (-22 to +212°F)
Response time (RH) 8s (tau63%)

Parts Required


Name Link
ESP8266 (Wemos Mini) D1 mini – ESP8266
SHTC1 SHTC1 digital temperature and humidity sensor
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
sensor shield Expansion IO Board Sensor Shield


Wemos Sensor
3.3v Vcc
Gnd Gnd


Code Example

This uses the library from https://github.com/Sensirion/arduino-sht

#include <Wire.h>
#include "SHTSensor.h"
SHTSensor sht;
// To use a specific sensor instead of probing the bus use this command:
// SHTSensor sht(SHTSensor::SHT3X);
void setup() {
// put your setup code here, to run once:
delay(1000); // let serial console settle
if (sht.init()) {
Serial.print("init(): success\n");
} else {
Serial.print("init(): failed\n");
sht.setAccuracy(SHTSensor::SHT_ACCURACY_MEDIUM); // only supported by SHT3x
void loop() {
// put your main code here, to run repeatedly:
if (sht.readSample()) {
Serial.print(" RH: ");
Serial.print(sht.getHumidity(), 2);
Serial.print(" T: ");
Serial.print(sht.getTemperature(), 2);
} else {
Serial.print("Error in readSample()\n");



Open the serial monitor and you should see something like this

init(): success
RH: 43.97
T: 20.05
RH: 43.99
T: 20.01
RH: 44.01
T: 20.00








ESP8266 and LPS22HB absolute pressure sensor example

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

Once again lets look at this sensor from the manufacturers perspective


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.


  • 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

Around $5 for the module

Name Link
Wemos Mini D1 mini – ESP8266 by WeMos
LPS22HB Semoic Lps22Hb Pressure Resistance Pressure Sensor Module for High Intensity Industrial Control
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



esp8266 and LPS22HB
esp8266 and LPS22HB


Code Example

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

This is the default example which works fine

  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.println("IoThings LPS22HB Arduino Test");
	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(" mbar, T=");


Open the serial monitor and you should see something like this – I put my finger on the sensor, hence the value is rising

P=983.26 mbar, T=27.88C
P=983.22 mbar, T=28.27C
P=983.24 mbar, T=28.60C
P=983.24 mbar, T=28.93C
P=983.27 mbar, T=29.23C
P=983.24 mbar, T=29.50C
P=983.24 mbar, T=29.71C
P=983.25 mbar, T=29.89C
P=983.26 mbar, T=30.05C
P=983.25 mbar, T=30.21C
P=983.23 mbar, T=30.34C

I wanted to check the pressure out so I visited the following website – https://www.worldweatheronline.com . There are several others.

They stated that the pressure was – Pressure: 992 mb

So not to bad





ESP8266 and BMA400 acceleration sensor example

In this article we look at another acceleration sensor – this time its the BMA400

Lets take a look at the sensor and its features


The BMA400 is the first real ultra-low power acceleration sensor without compromising on performance. Featuring 12-bit digital resolution, continuous measurement and a defined selectable bandwidth combined with ultra-low power the BMA400 allows low-noise measurement of accelerations in three perpendicular axes. The BMA400 thus senses tilt, orientation, tab/double tab, and enables plug ’n’ play step counting with activity recognition especially suited for wearable devices, which need a long-lasting battery lifetime.

Thanks to the continuous measurement principle and always-defined bandwidth, the BMA400 is the ideal solution for smart home applications such as smart indoor climate systems and smart home security systems. In the latter, the BMA400 can distinguish between real alarm situations like broken glass and false signals coming from random vibrations. Thereby, the new acceleration sensor avoids false alarms.


Parameter Technical data
Measurement range ±2 g, ±4 g, ±8 g, ±16 g
Digital resolution 12 bit
Output Data Rate (ODR) 12.5 Hz to 800 Hz
Low path filter bandwidth Selectable 0.48xODR or 0.24xODR
Current consumption (independent from ODR due to continuous measurement) Max. performance: 14.5 μA
Typical use case: 5.8 μA
Low power use case: 3.5μA
Noise density Max. performance: 180 μg/√Hz (Z: x 1.45)
Typical use case: 300 μg/√Hz (Z: x 1.45)
Low power: 415 μg/√Hz (Z: x 1.45)
Ultra low power / Auto-wake-up mode 800 nA @ 25 Hz ODR
Embedded features
  • Step counter (< 4 μA overall)
  • Activity recognition (walking, running, standing still)
  • Activity change
  • Orientation
  • Tab/Double tab (< 8 μA overall)
  • General interrupt 1 and 2 (programmable via thresholds, timer, logical AND/OR operations)
  • 1 kB FIFO
Offset ±80 mg
TCO ±1 mg/K
Interface SPI & I²C & 2 Interrupt pins
Supply voltage 1.71 V up to 3.6 V

Parts Required


Name Link
Wemos Mini D1 mini – ESP8266 by WeMos
BMA400 BMA400 Acceleration Sensor
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire



esp8266 and BMA400
esp8266 and BMA400


Code Example

This uses the library from https://github.com/Seeed-Studio/Grove_3Axis_Digital_Accelerometer_BMA400

No need to change the default code example – it worked just fine

#include "BMA400.h"
float x = 0, y = 0, z = 0;
int16_t temp = 0;
void setup(void)
    Serial.println("BMA400 Raw Data");
            Serial.println("BMA400 is connected");
        else Serial.println("BMA400 is not connected");
void loop(void)
    bma400.getAcceleration(&x, &y, &z);
    temp = bma400.getTemperature();



Open the serial monitor and you should see something like this when you move the sensor about