Categories

Create a simple barometer using an ESP8266 and a MS5611 sensor

In this particular example we are going to simply display temperature, pressure and altitude readings from a MS5611 sensor on an OLED display. We will be using various Wemos MIni shields and an MS5611 sensor

Here is a little about the MS5611

This barometric pressure sensor is optimized for altimeters and variometers with an altitude resolution of 10 cm. The sensor module includes a high linearity pressure sensor and an ultra-low power 24 bit ΔΣ ADC with internal factory calibrated coefficients. It provides a precise digital 24 Bit pressure and temperature value and different operation modes that allow the user to optimize for conversion speed and current consumption. A high resolution temperature output allows the implementation of an altimeter/thermometer function without any additional sensor. The MS5611-01BA can be interfaced to virtually any microcontroller. The communication protocol is simple, without the need of programming internal registers in the device.

This is the module we used which makes it easy to use the sensor

 

Parts List

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x MS5611 sensor (GY-63)

I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then connect the Ms5611 sensor to the Wemos Mini using cables.

Wemos  Ms5611
3v3 Vcc
Gnd Gnd
SDA SDA
SCL SCL

 

Code

Various libraries required – you can install these via the library manager, here are links to them

https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library 

https://github.com/jarzebski/Arduino-MS5611 library

If you can’t be bothered typing all of this in you can download the sketch from barometer

 

Output

Here you can see the output and my setup

 

 

Links

 

Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos

Double Socket Dual Base Shield for WeMos D1 Mini NodeMCU ESP8266 Diy PCB D1 Expansion board

64X48 IIC I2C LCD OLED LED Dispaly Shield for Arduino Compatible WeMos D1 Mini

GY-63 MS5611-01BA03 Precision MS5611 Atmospheric Pressure Sensor Module Height Sensor Module

Build a luxmeter with an ESP8266 and an OPT3001 sensor

In this particular example we are going to simply display visible light measurements from a OPT3001 sensor on an OLED display. We will be using various Wemos MIni shields and an OPT3001 sensor

Here is a little about the OPT3001

The OPT3001 is a sensor that measures the intensity of visible light. The spectral response of the sensor tightly matches the photopic response of the human eye and includes significant infrared rejection.

The OPT3001 is a single-chip lux meter, measuring the intensity of light as visible by the human eye. The precision spectral response and strong IR rejection of the device enables the OPT3001 to accurately meter the intensity of light as seen by the human eye regardless of light source. The strong IR rejection also aids in maintaining high accuracy when industrial design calls for mounting the sensor under dark glass for aesthetics. The OPT3001 is designed for systems that create light-based experiences for humans, and an ideal preferred replacement for photodiodes, photoresistors, or other ambient light sensors with less human eye matching and IR rejection.

Parts List

1 x Wemos Mini
1 x Wemos Dual Base
1 x OLED Shield
1 x OPT3001 board

I connect the Wemos Mini to the dual base and then put the OLED shield along side this, I then connect the OPT3001 sensor to the Wemos Mini using cables.

Wemos  CJMCU-3001
3v3 Vcc
Gnd Gnd
SDA SDA
SCL SCL

 

Code

Various libraries required – you can install these via the library manager, here are links to them

https://github.com/sparkfun/SparkFun_Micro_OLED_Arduino_Library 

https://github.com/closedcube/ClosedCube_OPT3001_Arduino

If you can’t be bothere dtyping all of this in you can download the sketch from luxmeter 

#include <Wire.h>  // Include Wire if you're using I2C
#include <SFE_MicroOLED.h>  // Include the SFE_MicroOLED library
#include <ClosedCube_OPT3001.h>
#define OPT3001_ADDRESS 0x44
#define PIN_RESET 255 //
#define DC_JUMPER 0 // I2C Addres: 0 - 0x3C, 1 - 0x3D
MicroOLED oled(PIN_RESET, DC_JUMPER);
ClosedCube_OPT3001 opt3001;
void setup()
{
Serial.begin(9600);
oled.begin();
oled.clear(ALL);
oled.display();
opt3001.begin(OPT3001_ADDRESS);
Serial.print("OPT3001 Manufacturer ID");
Serial.println(opt3001.readManufacturerID());
Serial.print("OPT3001 Device ID");
Serial.println(opt3001.readDeviceID());
configureSensor();
printResult("High-Limit", opt3001.readHighLimit());
printResult("Low-Limit", opt3001.readLowLimit());
Serial.println("----");
}
void loop()
{
OPT3001 result = opt3001.readResult();
printResult("OPT3001", result);
delay(500);
}
void configureSensor() {
OPT3001_Config newConfig;
newConfig.RangeNumber = B1100;
newConfig.ConvertionTime = B0;
newConfig.Latch = B1;
newConfig.ModeOfConversionOperation = B11;
OPT3001_ErrorCode errorConfig = opt3001.writeConfig(newConfig);
if (errorConfig != NO_ERROR)
printError("OPT3001 configuration", errorConfig);
else {
OPT3001_Config sensorConfig = opt3001.readConfig();
Serial.println("OPT3001 Current Config:");
Serial.println("------------------------------");
Serial.print("Conversion ready (R):");
Serial.println(sensorConfig.ConversionReady,HEX);
Serial.print("Conversion time (R/W):");
Serial.println(sensorConfig.ConvertionTime, HEX);
Serial.print("Fault count field (R/W):");
Serial.println(sensorConfig.FaultCount, HEX);
Serial.print("Flag high field (R-only):");
Serial.println(sensorConfig.FlagHigh, HEX);
Serial.print("Flag low field (R-only):");
Serial.println(sensorConfig.FlagLow, HEX);
Serial.print("Latch field (R/W):");
Serial.println(sensorConfig.Latch, HEX);
Serial.print("Mask exponent field (R/W):");
Serial.println(sensorConfig.MaskExponent, HEX);
Serial.print("Mode of conversion operation (R/W):");
Serial.println(sensorConfig.ModeOfConversionOperation, HEX);
Serial.print("Polarity field (R/W):");
Serial.println(sensorConfig.Polarity, HEX);
Serial.print("Overflow flag (R-only):");
Serial.println(sensorConfig.OverflowFlag, HEX);
Serial.print("Range number (R/W):");
Serial.println(sensorConfig.RangeNumber, HEX);
Serial.println("------------------------------");
}
}
void printResult(String text, OPT3001 result)
{
if (result.error == NO_ERROR)
{
Serial.print(text);
Serial.print(": ");
Serial.print(result.lux);
Serial.println(" lux");
oled.clear(PAGE);
oled.setFontType(0); // set font type 0, please see declaration in SFE_MicroOLED.cpp
oled.setCursor(1, 3);
oled.print("Lux: ");
oled.setCursor(1, 12);
oled.print(result.lux);
oled.print(" lux\t");
oled.display();
}
else
{
printError(text,result.error);
}
}
void printError(String text, OPT3001_ErrorCode error) {
Serial.print(text);
Serial.print(": [ERROR] Code #");
Serial.println(error);
}

 

Output

Here you can see the output and my setup

 

 

Links

 

Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos

Double Socket Dual Base Shield for WeMos D1 Mini NodeMCU ESP8266 Diy PCB D1 Expansion board

64X48 IIC I2C LCD OLED LED Dispaly Shield for Arduino Compatible WeMos D1 Mini

OPT3001 CJMCU-3001 ambient light sensor eye like measurement light intensity single chip illumination meter

Arduino traffic light example

This was a a simple board that I bought which basically consists of a red, yellow and green LED on a board, rather than buying seperate components and using a breadboard this is a reasonably low cost solution.

 

Code

In the example we use Pin 5 , 6 and 7 for the green, yellow and red LEDs

 

byte pinLedRed = 7;
byte pinLedYellow = 6;
byte pinLedGreen = 5;
 
void setup()
{
    // Initialize the pins as output pins
    pinMode(pinLedRed, OUTPUT);
    pinMode(pinLedYellow, OUTPUT);
    pinMode(pinLedGreen, OUTPUT);
}
 
void loop()
{
 
    //Red signal
    digitalWrite(pinLedRed, HIGH); // RED on
    delay(5000); // 5 secs
 
    //Yellow + Red
    digitalWrite(pinLedYellow, HIGH); // YELLOW on
    delay(1000); // 1 sec
 
    //Green signal
    digitalWrite(pinLedRed, LOW); // RED  off
    digitalWrite(pinLedYellow, LOW); // YELLOW off
    digitalWrite(pinLedGreen, HIGH); // GREEN  on
    delay(5000); // 5 secs
 
    //Yellow signal
    digitalWrite(pinLedGreen, LOW); // GREEN  off
    digitalWrite(pinLedYellow, HIGH); // YELLOW  on
    delay(1000);
    digitalWrite(pinLedYellow, LOW); // YELLOW  off
 
}

 

Link

The traffic light board only costs about $1

LED traffic lights light-emitting module / digital signal output Traffic light module / electronic building blocks

Roll the dice codebug example

A simple dice game on a codebug

Go to http://www.codebug.org.uk/create/ and paste the code in, the good thing is this also generates a Python and blockly example

Code

var delay;
var pressed;
var count;
 
 
codebug_direction('U');
codebug_sleepafter(1);
io_configure(0, IO_DIGITAL_INPUT);
io_configure(1, IO_DIGITAL_INPUT);
io_configure(2, IO_DIGITAL_INPUT);
io_configure(3, IO_DIGITAL_INPUT);
io_configure(4, IO_DIGITAL_INPUT);
io_configure(5, IO_DIGITAL_INPUT);
io_configure(6, IO_DIGITAL_INPUT);
io_configure(7, IO_DIGITAL_INPUT);
io_configure_pullup(0, 0);
io_configure_pullup(2, 0);
io_configure_pullup(3, 0);
io_configure_pullup(4, 0);
io_configure_pullup(5, 0);
 
 
delay = 60;
pressed = 0;
count = 1;
while (true) {
  if (io_get_input('A') == 1) {
    pressed = 1;
    fivebyfivedisplay.clear();
    fivebyfivedisplay.update();
    while (io_get_input('A') == 1) {
      count = count + 1;
    }
    count = count % 6;
  }
  if (1 == pressed) {
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1, 1, 1, 1]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 1, 1, 1, 1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 1, 1, 1]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 1, 1, 1, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 1, 0], [0, 1, 0, 0, 1], [1, 0, 0, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]]));
    fivebyfivedisplay.update();
    sleep(delay);
    if (0 == count) {
      count = 6;
    }
    if (1 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]));
      fivebyfivedisplay.update();
    } else if (2 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[0, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 0]]));
      fivebyfivedisplay.update();
    } else if (3 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    } else if (4 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    } else if (5 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    } else if (6 == count) {
      fivebyfivedisplay.sprite_render(0, 0, sprite_build([[1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 0, 0, 0, 1]]));
      fivebyfivedisplay.update();
    }
    pressed = 0;
  }
}

 

To test this out , simply upload the example – following the instructions on the website. Press the A button to roll the dice

ESP8266 AT Instruction Set