Wemos mini and US-026 Ultrasonic Detector example

In this article we look an ultrasonic module that works well with a Wemos Mini in that it will work with 3.3v.

The US-026 is an upgraded version of the HC-SR04, with a kind of high performance, low cost ultrasonic module. The module uses the CS100 , a high performance-cost ratio ultrasonic ranging chip.

It has high measurement accuracy and the measuring distance is farther than 6 meters. Good consistency, well stability.
It can realize 2-6m non-contact ranging. The working voltage is 3V-5.5V, working current is 5.3 mA and supporting GPIO communication mode.
US-026 has 4 Pin power supply and communication interface. It is single-side printed board. 4 pin is welded on the back side (the chip side).
Input a 10uS above high level to Trig pin, the system will emit eight 40KHZ ultrasonic impulse. The system detects the echo signal and output through Echo pin. Calculating the distance according the lasting time of high electrical level which exported by the ECHO pin.

1.This module has stable performance and accurate measurement distance.
2.Module high-precision, blind (2cm) ultra-close, stable range is the success of this product to the market a strong basis.
3.Using IO trigger ranging,to at least 10us of high-level signal.
4.The module automatically sends eight 40khz square wave, automatically detect whether there is signal return.
5.There is a signal return, through the IO output of a high, high duration is the time from the launch to the return of ultrasound.

 

Specifications:

Color:yellow
Working voltage: DC 3V-5.5V
Working current:5.3mA
Level output: High 5V
Level output: Bottom 0V
Sensing angle: not more than 15 degrees
Detection range: 2cm-600cm

 

Parts

Name Link
Wemos Mini WeMos D1 mini
US-026  ultrasonic sensor US-026 Ultrasonic Detector
Connecting area Cable Dupont Jumper Wire Dupont 30CM

Connection

The Ultrasonic sensor has four terminals – +3.3v, Trigger, Echo, and GND connected as follows

  • Connect the +3.3V pin to +3.3v on your Wemos Mini.
  • Connect Trigger to digital pin D7 on your Wemos Mini.
  • Connect Echo to digital pin D8 on your Wemos Mini.
  • Connect GND with GND on your Wemos Mini.

Code

const int pingPin = D7; // Trigger Pin of Ultrasonic Sensor
const int echoPin = D8; // Echo Pin of Ultrasonic Sensor
 
void setup()
{
Serial.begin(9600); // Starting Serial Terminal
}
 
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print(" in, ");
Serial.print(cm);
Serial.print(" cm");
Serial.println();
delay(100);
}
 
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
 
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

Output

Open the serial monitor and move an object to the sensor

2 in, 6 cm
2 in, 6 cm
2 in, 6 cm
3 in, 7 cm
2 in, 7 cm
3 in, 7 cm

Wemos Mini 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 a Wemos Mini

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

Name Link
Wemos Mini WeMos D1 mini
HDC2080 HDC2080 Temperature and Humidity Low Power Digital I2C Sensor
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
Base shield Double Socket Dual Base Shield for Wemos D1 Mini

Schematic/Connection

Wemos mini Sensor
3.3v Vcc
Gnd Gnd
SDA (D2) SDA
SCL (D1) SCL

 

 

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): 32.50 Humidity (%): 0.00
Temperature (C): 32.71 Humidity (%): 0.00
Temperature (C): 32.37 Humidity (%): 49.61
Temperature (C): 32.11 Humidity (%): 45.78
Temperature (C): 31.92 Humidity (%): 42.58
Temperature (C): 31.74 Humidity (%): 40.12
Temperature (C): 31.60 Humidity (%): 38.22
Temperature (C): 31.45 Humidity (%): 36.88
Temperature (C): 31.33 Humidity (%): 35.85
Temperature (C): 31.19 Humidity (%): 35.14
Temperature (C): 31.07 Humidity (%): 34.59
Temperature (C): 30.97 Humidity (%): 34.25

 

Links

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

Wemos Mini and LPS25H piezoresistive pressure sensor example

In this article we look at a pressure sensor – this time its the LPS25H and we will connect it to a Wemos Mini

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

 

Name Link
Wemos Mini WeMos D1 mini
LPS25H Diybigworld LPS25HTR ST CJMCU-25 Miniature high Precision Pressure Sensor Temperature Compensation
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
Base shield Double Socket Dual Base Shield for Wemos D1 Mini

Schematic/Connection

 

Wemos mini Sensor
3.3v Vcc
Gnd Gnd
SDA (D2) SDA
SCL (D1) SCL

 

 

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: 1016.05 mbar a: -23.26 m t: 26.85 deg C
p: 1016.04 mbar a: -23.22 m t: 26.89 deg C
p: 1016.04 mbar a: -23.21 m t: 26.93 deg C
p: 1016.05 mbar a: -23.32 m t: 27.00 deg C
p: 1015.99 mbar a: -22.80 m t: 27.03 deg C
p: 1016.05 mbar a: -23.26 m t: 27.08 deg C
p: 1016.01 mbar a: -22.98 m t: 27.15 deg C
p: 1016.02 mbar a: -23.06 m t: 27.18 deg C
p: 1015.95 mbar a: -22.49 m t: 27.21 deg C

 

Links

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

Wemos Mini and LIS3MDL magnetic field sensor example

In this article we look at another sensor – this time its the LIS3MDL which is a 3-axis MEMS magnetic field sensor, digital output, I2C, SPI, low power mode, high performance

This is the sensor that I used

The LIS3MDL has user-selectable full scales of ±4/±8/±12/±16 gauss.
The self-test capability allows the user to check the functioning of the sensor in the final application.
The device may be configured to generate interrupt signals for magnetic field detection.
The LIS3MDL includes an I2C serial bus interface that supports standard and fast mode (100 kHz and 400 kHz) and SPI serial standard interface.
The LIS3MDL is available in a small thin plastic land grid array package (LGA) and is guaranteed to operate over an extended temperature range of -40 °C to +85 °C.

Features

  • Wide supply voltage, 1.9 V to 3.6 V
  • Independent IO supply (1.8 V)
  • ±4/±8/±12/±16 gauss selectable magnetic full scales
  • Continuous and single-conversion modes
  • 16-bit data output
  • Interrupt generator
  • Self-test
  • I2C/SPI digital output interface
  • Power-down mode / low-power mode

As an added bonus here is the schematic for one of these modules

Parts Required

 

Name Link
Wemos Mini WeMos D1 mini
LIS3MDL Taidacent LIS3MDL High Precision 3 Axis Magnetometer Sensor Compass Module Tilt Compensated Compass Replacement HMC5883L
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
Base shield Double Socket Dual Base Shield for Wemos D1 Mini

Schematic/Connection

 

Wemos mini Sensor
3.3v Vcc
Gnd Gnd
SDA (D2) SDA
SCL (D1) SCL

 

Code Example

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

 

/*
The sensor outputs provided by the library are the raw 16-bit values
obtained by concatenating the 8-bit high and low magnetometer data registers.
They can be converted to units of gauss using the
conversion factors specified in the datasheet for your particular
device and full scale setting (gain).
 
Example: An LIS3MDL gives a magnetometer X axis reading of 1292 with its
default full scale setting of +/- 4 gauss. The GN specification
in the LIS3MDL datasheet (page 8) states a conversion factor of 6842
LSB/gauss (where LSB means least significant bit) at this FS setting, so the raw
reading of 1292 corresponds to 1292 / 6842 = 0.1888 gauss.
*/
 
#include <Wire.h>
#include <LIS3MDL.h>
 
LIS3MDL mag;
 
char report[80];
 
void setup()
{
  Serial.begin(9600);
  Wire.begin();
 
  if (!mag.init())
  {
    Serial.println("Failed to detect and initialize magnetometer!");
    while (1);
  }
 
  mag.enableDefault();
}
 
void loop()
{
  mag.read();
 
  snprintf(report, sizeof(report), "M: %6d %6d %6d",
    mag.m.x, mag.m.y, mag.m.z);
  Serial.println(report);
 
  delay(100);
}

 

 

Output

Open the serial monitor , move the sensor around and you should readings like this

M: -1639 3336 7493
M: -1839 2769 7615
M: -1374 2834 7749
M: -356 2968 7769
M: -104 2425 7931
M: 53 1223 7841
M: -90 157 7370
M: -488 -1027 6358
M: -1011 -1540 5230
M: -1255 -1699 4822
M: -1417 -1714 4831
M: -1209 -1363 5964
M: -682 -301 7271

 

Links

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