MPL3115A2 pressure sensor and ESP8266

The MPL3115A2 is a compact, piezoresistive, absolute pressure sensor with an I2C digital interface. MPL3115A2 has a wide operating range of 20 kPa to 110 kPa, a range that covers all surface elevations on earth. The MEMS is temperature compensated utilizing an on-chip temperature sensor. The pressure and temperature data is fed into a high resolution ADC to provide fully compensated and digitized outputs for pressure in Pascals and temperature in °C.

The compensated pressure output can then be converted to altitude, utilizing the formula stated in Section 9.1.3 “Pressure/altitude” provided in meters.The internal processing in MPL3115A2 removes compensation and unit conversion load from the system MCU, simplifying system design

 

Schematics/Layout

 

 

Code

Again we use a library and again its an adafruit one – https://github.com/adafruit/Adafruit_MPL3115A2_Library

#include <Wire.h>
#include <Adafruit_MPL3115A2.h>
 
// Power by connecting Vin to 3-5V, GND to GND
// Uses I2C - connect SCL to the SCL pin, SDA to SDA pin
// See the Wire tutorial for pinouts for each Arduino
// http://arduino.cc/en/reference/wire
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
 
void setup() {
  Serial.begin(9600);
  Serial.println("Adafruit_MPL3115A2 test!");
}
 
void loop() {
  if (! baro.begin()) {
    Serial.println("Couldnt find sensor");
    return;
  }
 
  float pascals = baro.getPressure();
  // Our weather page presents pressure in Inches (Hg)
  // Use http://www.onlineconversion.com/pressure.htm for other units
  Serial.print(pascals/3377); Serial.println(" Inches (Hg)");
 
  float altm = baro.getAltitude();
  Serial.print(altm); Serial.println(" meters");
 
  float tempC = baro.getTemperature();
  Serial.print(tempC); Serial.println("*C");
 
  delay(250);
}

 

Output

Open the serial monitor – here are my results

29.77 Inches (Hg)
64.81 meters
20.69*C
29.77 Inches (Hg)
64.62 meters
20.69*C
29.77 Inches (Hg)
64.56 meters
20.69*C

 

Links

https://www.nxp.com/docs/en/data-sheet/MPL3115A2.pdf

MPL3115A2 I2C Intelligent Temperature Pressure Altitude Sensor V2.0 For Arduino

The Wemos PIR shield

A new wemos shield and this time its based on a  passive infrared sensor

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. They are commonly called simply “PIR”, or sometimes “PID”, for “passive infrared detector”.

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

The PIR is an AS312

Code

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

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);
}

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
INTRUDER DETECTED
INTRUDER DETECTED
NOWT GOING ON
NOWT GOING ON
NOWT GOING ON
INTRUDER DETECTED
INTRUDER DETECTED

 

 

Links

https://datasheet.lcsc.com/szlcsc/Nanyang-Senba-Optical-Elec-AS312_C90465.pdf

 

Goouuu-S1 ESP8266 RGB led examples

In a previous post we looked at the Goouuu-S1 ESP8266 , on the board you will have seen that there is an RGB led

The board uses the following pins for the LED

int redpin = 12; // select the pin for the red LED

int bluepin = 14; // select the pin for the blue LED

int greenpin =13; // select the pin for the green LED

Code Examples

int redpin = 12; // select the pin for the red LED
int bluepin = 14; // select the pin for the blue LED
int greenpin =13; // select the pin for the green LED
 
int val=0;
 
void setup () 
{
  pinMode (redpin, OUTPUT);
  pinMode (bluepin, OUTPUT);
  pinMode (greenpin, OUTPUT);
  Serial.begin (9600);
}
 
void loop () 
{
  for (val=255; val>0; val--)
  {
    analogWrite (redpin, val);
    analogWrite (bluepin, 255-val);
    analogWrite (greenpin, 128-val);
    delay (50);
  }
  for (val = 0; val <255; val++)
  {
    analogWrite (redpin, val);
    analogWrite (bluepin, 255-val);
    analogWrite (greenpin, 128-val);
    delay (50);
  }
  Serial.println (val, DEC);
}

 

And another example

 

int redpin = 12; // select the pin for the red LED
int bluepin = 14; // select the pin for the blue LED
int greenpin =13; // select the pin for the green LED
 
int val=0;
 
void setup () 
{
  pinMode (redpin, OUTPUT);
  pinMode (bluepin, OUTPUT);
  pinMode (greenpin, OUTPUT);
  Serial.begin (9600);
}
 
void loop () 
{
  LEDOff();
  REDOn();
  LEDOff();
  GREENOn();
  LEDOff();
  BLUEOn();
}
 
void LEDOff()
{  
  digitalWrite(redpin,HIGH);
  digitalWrite(greenpin, HIGH);
  digitalWrite(bluepin, HIGH);
  delay (500);
}
 
void REDOn()
{
  digitalWrite(redpin,LOW);
  digitalWrite(greenpin, HIGH);
  digitalWrite(bluepin, HIGH);
  delay (500);
}
 
void GREENOn()
{
  digitalWrite(redpin,HIGH);
  digitalWrite(greenpin, LOW);
  digitalWrite(bluepin, HIGH);
  delay (500);
}
 
void BLUEOn()
{
  digitalWrite(redpin,HIGH);
  digitalWrite(greenpin, HIGH);
  digitalWrite(bluepin, LOW);
  delay (500);
}

 

ESP8266 and 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

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 any external parts
9) Light source dependency is little. ( ex. Incandescent Lamp. Fluorescent Lamp. Halogen Lamp. White LED. Sun Light )
10) It is possible to select 2 type of I2C slave-address.
11) Adjustable measurement result for influence of optical window ( It is possible to detect min. 0.11 lx, max. 100000 lx by using this function. )
12) Small measurement variation (+/- 20%)
13) The influence of infrared is very small.

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 

#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);
}

 

Output

Open the serial monitor, cover the sensor, shine light on the sensor and so on to see the readings change, you can see where I covered it completely reading 0 lx

Light: 29 lx
Light: 29 lx
Light: 22 lx
Light: 0 lx
Light: 0 lx
Light: 20 lx
Light: 18 lx
Light: 28 lx
Light: 27 lx

 

Link