Altitude Monitoring with BMP280 Using ESP32 and Node-RED
The BME280 I2C module has great significance in measuring altitude application using ESP32 with Node-RED.
Things used in this project
Story
This Blogtut will show you how you can measure read the temperature, pressure, and altitude (using precise values) and with the help of wireless communication (WiFi) with new device ESP32. We can create the wireless sensor network as well as send the parameters online by using inbuilt BLE(Bluetooth Low Energy) and WIFI in it.
Hardware RequiredI2C cable
SoftwareArduino IDE
Node-RED
IOT PlatformMQTT
JSON
For Installation of ESP32 device, newbies can follow the blog post
If you are not familiar with Node-RED installation and using MQTT node in Node-RED, I suggest to check out the previous blogtut in which I have shared all the detailed information for Getting Started with Node-RED services.
About BMP280 I2C moduleThe BMP280 IC package manufactured by BOSCH Sensortec operates on lower Noise. With EMC robustness, High Accuracy it performs greatly in various application like:
- Atmospheric Pressure and Temperature monitoring system
- Intruder Alarming via Pressure Precision
- Intruder Alarm
- Altitude measurement
- Vertical Velocity Sink
BMP280 I2C module is a digital pressure sensor 300–1100hPa(hectopascals) or mbar(millibar) uses the modular breakout board with advance I2C speed of 3.4Mbit/sec with the resolution 0.01hPa.
Code- Initialize the Wire.h file called as I2C Library especially use in Arduino IDE
#include <Wire.h>
- Initialize the I2C registers of sensor module which is specified to work with 2 wire protocol.
#define Addr 0x76
- Begin the I2C transmission and Initialize the baud rate as per the requirements for serial communication.
Wire.begin(21,22);
Serial.begin(115200);
setup_wifi(); //We will be using simple Wifi.h library
- Request for 8 bytes of Data which we want to read from the sensor through I2C connection for reading the Temperature Coefficient and Pressure Coefficients
for (int i = 0; i < 8; i++)
{
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Select data register
Wire.write((247 + i));
// Stop I2C Transmission
Wire.endTransmission();
// Request 1 byte of data
Wire.requestFrom(Addr, 1);
// Read 1 byte of data
if (Wire.available() == 1)
{
data[i] = Wire.read();
}
}
- If bytes are available then use the mentioned below formula will help to convert the data bytes and display desired values
// Convert pressure and temperature data to 19-bits
long adc_p = (((long)(data[0] & 0xFF) * 65536) + ((long)(data[1] & 0xFF) * 256) + (long)(data[2] & 0xF0)) / 16;
long adc_t = (((long)(data[3] & 0xFF) * 65536) + ((long)(data[4] & 0xFF) * 256) + (long)(data[5] & 0xF0)) / 16;
// Temperature offset calculations
double var1 = (((double)adc_t) / 16384.0 — ((double)dig_T1) / 1024.0) * ((double)dig_T2);
double var2 = ((((double)adc_t) / 131072.0 — ((double)dig_T1) / 8192.0) *(((double)adc_t) / 131072.0 — ((double)dig_T1) / 8192.0)) * ((double)dig_T3);
double t_fine = (long)(var1 + var2);
// Pressure offset calculations
var1 = ((double)t_fine / 2.0) — 64000.0;
var2 = var1 * var1 * ((double)dig_P6) / 32768.0;
var2 = var2 + var1 * ((double)dig_P5) * 2.0;
var2 = (var2 / 4.0) + (((double)dig_P4) * 65536.0);
var1 = (((double) dig_P3) * var1 * var1 / 524288.0 + ((double) dig_P2) * var1) / 524288.0;
var1 = (1.0 + var1 / 32768.0) * ((double)dig_P1);
double p = 1048576.0 — (double)adc_p;
p = (p — (var2 / 4096.0)) * 6250.0 / var1;
var1 = ((double) dig_P9) * p * p / 2147483648.0;
var2 = p * ((double) dig_P8) / 32768.0;
- Manipulate the Temperature and Pressure parameters as per the requirement through Sensitivity and resolution settings given in the datasheet
double cTemp = (var1 + var2) / 5120.0;
double fTemp = cTemp * 1.8 + 32;
double pressure = (p + (var1 + var2 + ((double)dig_P7)) / 16.0) / 100;
- Using Serial.print you will be able to read the sensor data in the serial monitor screen.
Serial.print(“Altitude : “);
Serial.print(height);
Serial.println(“ m”);
Serial.print(“Altitude in Feet : “);
Serial.println(h);
Serial.print(“Pressure : “);
Serial.print(pressure);
Serial.println(“ hPa”);
Serial.print(“Temperature in Celsius : “);
Serial.print(cTemp);
Serial.println(“ C”);
Serial.print(“Temperature in Fahrenheit : “);
Serial.print(fTemp);
Serial.println(“ F”);
BMP280 Application
While working on BMP280 sensor I was able to test the pressure and temperature.
But!!! Besides that, I have used one graph Image and formulae which help me to understand and find out the Altitude parameters (in meters) using this sensor as well as using some basic Standard Units Conversion method. I have converted the parameters to work with Feet units also
Measuring heights of Civil Infrastructure
There are many core application when it comes to monitoring Civil Projects construction to measure the height with precise parameters.
Measuring Altitude between Earth and Aeroplane in Air Atmosphere
This Application plays the most important role to monitor the Altitude for AeroSpace vehicles. As we haven’t worked in depth but yes mentioned below code will definitely help you to understand the basic physics concept, which can direct you to advanced field application also.
One of the best Device to use as a gateway receiver to make your sensor communicate wireless with the internet using Wifi. Besides that using Ultra Low Power we can use special BLE protocol with this sensor which will help to create the private network between sensor and smartphone and display the parameters using Sensor Application. We are using WiFi Library and Pubsub client using Arduino IDE
Node-REDAfter unlocking one the application for measuring the altitude using Arduino, let’s detect the parameters with Node-RED dashboard — (Line Graphs and Bar Graphs).
For installation of Node-RED and to install the different nodes in node red in windows operating and to use MQTT please go through the previous blogtut.
In this project, We will be using MQTT, JSON, Function nodes in Node-RED dashboard which is already mentioned in Axial Monitoring with Node-RED Service. The MQTT connection has been created with the help of PUB-SUB client in Arduino.
But Function node is the best way to parse the data from the sensor and with help of Split node you can individually use the data to send it to online platform easily in JSON format or parsed according to requirements. We will be working more advanced with JSON format in next blogtut till then we have already used a basic example to display the whole object through JSON and function node connection which is further connected to message payload by
- After Drag and Drop double click on function node
- Write the small piece of code to parse the data in JSON Object
p = JSON.parse(msg.payload);node.log(typeof p);msg.payload = p;return msg;
沒有留言:
張貼留言