Home ESP8266 5 Wemos Mini shields with examples

5 Wemos Mini shields with examples

by iainhendry

In this article we look at five Wemos shields and will have examples of their usage. The Wemos mini is my favourite development board for the ESP8266 microcontroller. The shields we are looking at are the PIR Shield, Ambient light Shield, WS2812B RGB Shield, SHT30 Shield and the Matrix LED Shield.

So lets go.

PIR Shield example

An overview of a PIR

A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. A PIR-based motion detector is used to sense movement of people, animals, or other objects. They are commonly used in burglar alarms and automatically-activated lighting systems.

If you want to read more basics – https://en.wikipedia.org/wiki/Passive_infrared_sensor

The shield uses D3 so that will be unavailable for any other components or shields you may want to use, here is a picture of the shield

 

Code

Very simple stuff here, we will output via the serial monitor.

[codesyntax lang=”cpp”]

const int PIR = D3;
int PIRState = 0;

void setup() 
{
  Serial.begin(9600);
  pinMode(PIR, INPUT);
}

void loop() 
{
  PIRState = digitalRead(PIR);

  if (PIRState == HIGH) 
  {
    Serial.write("INTRUDER DETECTED\n");
  } 
  else 
  {
    Serial.write("NOWT GOING ON\n");
  }
  delay(1000);
}

[/codesyntax]

Output

Open the serial monitor and move your hand in front of the PIR and then move away

NOWT GOING ON
NOWT GOING ON
NOWT GOING ON
INTRUDER DETECTED
INTRUDER DETECTED
INTRUDER DETECTED

 

Ambient light Shield Example

This was another new shield for the Wemos called the Ambient light Shield , this time its based around the BH1750FVI digital Ambient Light Sensor

Lets look at some info about the sensor

The BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface.

This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone.

It is possible to detect wide range at High resolution. ( 1 – 65535 lx ).

Features

1) I2C bus Interface ( f / s Mode Support )
2) Spectral responsibility is approximately human eye response
3) Illuminance to Digital Converter
4) Wide range and High resolution. ( 1 – 65535 lx )
5) Low Current by power down function
6) 50Hz / 60Hz Light noise reject-function
7) 1.8V Logic input interface
8) No need for any external parts
9) It is possible to select 2 different I2C addresses
10) Adjustable measurement result for influence of optical window ( It is possible to detect min. 0.11 lx, max. 100000 lx by using this function. )
11) Small measurement variation (+/- 20%)

Being an I2C device it uses D1 and D2 on the Wemos mini

 

Code

You need to install the following library for this example :  https://github.com/claws/BH1750 

[codesyntax lang=”cpp”]

#include <Wire.h>
#include <BH1750.h>


BH1750 lightMeter(0x23);

void setup(){

  Serial.begin(9600);

  // Initialize the I2C bus
  Wire.begin();

  if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) 
  {
    Serial.println(F("BH1750 Advanced begin"));
  }
  else 
  {
    Serial.println(F("Error initialising BH1750"));
  }

}


void loop() 
{
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);
}

[/codesyntax]

 

Output

Open the serial monitor, cover the sensor, shine light on the sensor

Light: 29 lx
Light: 29 lx
Light: 22 lx
Light: 0 lx
Light: 0 lx
Light: 20 lx

SHT30 Shield Example

This time we look at the SHT30 shield from Wemos.

 

 

The new digital SHT3x humidity sensor series takes sensor technology to a new level. As the successor of the SHT2x series it is determined to set the next industry standard in humidity sensing.

The SHT3x humidity sensor series consists of a low-cost version with the SHT30 humidity sensor, a standard version with the SHT31 humidity sensor, and a high-end version with the SHT35 humidity sensor.

The SHT3x humidity sensor series combines multiple functions and various interfaces (I2C, analog voltage output) with a applications-friendly, very wide operating voltage range (2.15 to 5.5 V).

More information at sensiron

The sensor is an I2C device so uses D1 and D2

 

Code

Wemos have their own library so we will use that – https://github.com/wemos/WEMOS_SHT3x_Arduino_Library

I changed the baud rate in Serial.begin, I couldn’t get the example to work. Not sure why . there is also an example which use this and the OLED shield in the github repo, worth looking at

[codesyntax lang=”cpp”]

#include <WEMOS_SHT3X.h>

SHT3X sht30(0x45);

void setup() 
{
  Serial.begin(9600);
}

void loop() {

  if(sht30.get()==0){
    Serial.print("Temperature in Celsius : ");
    Serial.println(sht30.cTemp);
    Serial.print("Temperature in Fahrenheit : ");
    Serial.println(sht30.fTemp);
    Serial.print("Relative Humidity : ");
    Serial.println(sht30.humidity);
    Serial.println();
  }
  else
  {
    Serial.println("Error!");
  }
  delay(1000);

}

[/codesyntax]

 

Output

Open the serial monitor and you should see something like this

Temperature in Celsius : 30.47
Temperature in Fahrenheit : 86.84
Relative Humidity : 40.68

Temperature in Celsius : 31.28
Temperature in Fahrenheit : 88.31
Relative Humidity : 53.50

Temperature in Celsius : 31.73
Temperature in Fahrenheit : 89.12
Relative Humidity : 61.84

 

WS2812B RGB Shield example

In this example we connect a Wemos Ws2812B RGB shield to a Wemos mini

 

ws2812b

The WS2812 is an intelligent control LED light source that the control circuit and RGB chip are integrated in a package of 5050 components. It internal include intelligent digital port data latch and signal reshaping amplification drive circuit.

Also include a precision internal oscillator and a 12V voltage programmable constant current control part, effectively ensuring the pixel point light color height consistent.

The data transfer protocol use single NZR communication mode. After the pixel power-on reset, the DIN port receive data from controller, the first pixel collect initial 24 bit data then sent to the internal data latch, the other data which reshaping by the internal signal reshaping amplification circuit sent to the next cascade pixel through the DO port.

After transmission for each pixel,the signal to reduce 24 bit. pixel adopt auto reshaping transmit technology, making the pixel cascade number is not limited the signal transmission, only depend on the speed of signal transmission.

LED with low driving voltage, environmental protection and energy saving, high brightness, scattering angle is large, good consistency, low power, long life and other advantages. The control chip integrated in LED above becoming more simple circuit, small volume, convenient installation.

 

Code

You will need to add the Adafruit Neopixel library to your Arduino IDE – https://github.com/adafruit/Adafruit_NeoPixel

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN D2

//the Wemos WS2812B RGB shield has 1 LED connected to pin 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);


void setup() 
{
  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() 
{
  setColor(255,0,0,1000); //red
  setColor(0,255,0,1000); //green
  setColor(0,0,255,1000); //blue
}

//simple function which takes values for the red, green and blue led and also
//a delay
void setColor(int redValue, int greenValue, int blueValue, int delayValue)
{
  pixels.setPixelColor(0, pixels.Color(redValue, greenValue, blueValue)); 
  pixels.show();
  delay(delayValue);
}

[/codesyntax]

 

 

MATRIX LED Shield example

this is called the MATRIX LED Shield – You can find out more at https://wiki.wemos.cc/products:d1_mini_shields:matrix_led_shield

The board uses a TM1640, as you can see there are 8×8 LEDs with 8 levels of intensity. The shield will also use the D5 an D7 pins of your wemos mini, so these won’t be available for any other projects

Code

This requires the library from https://github.com/wemos/WEMOS_Matrix_LED_Shield_Arduino_Library

[codesyntax lang=”cpp”]

#include <WEMOS_Matrix_LED.h>

MLED mled(5); //set intensity=5

void setup()
{

}

void loop() {

  for(int y=0;y<8;y++)
  {
    for(int x=0;x<8;x++)
    {
        mled.dot(x,y); // draw dot
        mled.display();
        delay(200);      
    }  
  }
}

[/codesyntax]

 

Links

1pcs WS2812B RGB SHIELD for WeMos D1 mini

SHT30 Shield for D1 Mini

Matrix LED Shield V1.0.0 For WEMOS D1 Mini

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More