ESP8266 WiFi – Temperatuur Luchtvochtigheid Barometer BME280 (ArduinoIDE)
Op deze pagina vind je een voorbeeld om via de ESP-01 module een BME280 temperatuur, luchtvochtigheid en barometer sensor te gebruiken via de GPIO pinnen met de ArduinoIDE.
Hardware
Informatie (ENG)
Description:
The BME280 Breakout Board is the easy way to measure pressure and humidity, and without taking up a lot of room. It gives you easy to solder 0.1″ headers, runs I2C or SPI, takes measurements at less than 1mA and idles less than 5uA (yes, microamps!).
The BME280 can be used to take pressure, humidity, and temperature readings. Use the data to get relative altitude changes, or absolute altitude if the locally reported barometric pressure is known.
Specificaties:
Temp: -40C to 85C
Humidity: 0 – 100% RH, =-3% from 20-80%
Pressure: 30,000Pa to 110,000Pa, relative accuracy of 12Pa, absolute accuracy of 100Pa
Altitude: 0 to 30,000 ft (9.2 km), relative accuracy of 3.3 ft (1 m) at sea level, 6.6 (2 m) at 30,000 ft.
Typical application:
– Enhancement of GPS navigation (e.g. time-to-first-fix improvement,dead-reckoning,slope detection)
– Indoor navigation (floor detection,elevator detection)
– Outdoor navigation,leisure and sports applications
– Weather forecast
– Health care application (e.g. sirometry)
– Vertical velocity indication (e.g. risk/sink speed)
Schema
Pinout
Pin: | Functie: |
---|---|
1 | +5V (VCC) |
2 | GND |
3 | SCL Serial Clock (line) |
4 | SCA Serial Clock (data) |
5 | CSB (Chip Select) |
6 | SDO (Serial Data Out) |
Aansluiten:
Script met I2C bibliotheek
Wat heb je nodig?
1) Firmware flashen met ArduinoIDE
2) BME280 arduino bibliotheek
Standaard worden de SDA en SCL connecties gebruikt op de arduino bij deze module bibliotheek:
1 2 3 4 5 6 7 |
Connecting the BME280 Sensor: Sensor -> Board ----------------------------- Vin (Voltage In) -> 3.3V Gnd (Ground) -> Gnd SDA (Serial Data) -> A4 on Uno/Pro-Mini, 20 on Mega2560/Due, 2 Leonardo/Pro-Micro SCK (Serial Clock) -> A5 on Uno/Pro-Mini, 21 on Mega2560/Due, 3 Leonardo/Pro-Micro |
Maar de op de ESP-01 is het GPIO 0 en GPIO 2, dat kan je regelen door de standaard:
Wire.begin();
aan te passen in:
1 |
Wire.begin(0,2); //sda 0 , scl 2 > ESP-01 |
Het script leest de Temperatuur, Luchtvochtigheid en Luchtdruk uit:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <BME280I2C.h> #include <Wire.h> #define SERIAL_BAUD 9600 BME280I2C bme; // Default : forced mode, standby time = 1000 ms // Oversampling = pressure ×1, temperature ×1, humidity ×1, filter off, float pres, temp, hum; void setup(){ Serial.begin(SERIAL_BAUD); while(!Serial) {} // Wait Wire.begin(0,2); //sda 0 , scl 2 > ESP-01 while(!bme.begin()) { Serial.println("Could not find BME280 sensor!"); delay(1000); } } void loop() { BME280::TempUnit tempUnit(BME280::TempUnit_Celsius); BME280::PresUnit presUnit(BME280::PresUnit_Pa); bme.read(pres, temp, hum, tempUnit, presUnit); Serial.print("\tTemp: "); Serial.print(temp); Serial.print("C"); Serial.print("\tHum: "); Serial.print(hum); Serial.print("% RH"); Serial.print("\tPres: "); Serial.print(pres); Serial.println(" Pa"); delay(1000); } |
Het resultaat
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Temp: 24.50C Hum: 32.08% RH Pres: 100314.98 Pa Temp: 24.45C Hum: 32.15% RH Pres: 100317.16 Pa Temp: 24.45C Hum: 32.16% RH Pres: 100312.70 Pa Temp: 24.44C Hum: 32.15% RH Pres: 100315.46 Pa Temp: 24.44C Hum: 32.17% RH Pres: 100313.67 Pa Temp: 24.45C Hum: 32.21% RH Pres: 100312.70 Pa Temp: 24.43C Hum: 32.30% RH Pres: 100311.98 Pa Temp: 24.43C Hum: 32.47% RH Pres: 100314.63 Pa Temp: 24.42C Hum: 32.59% RH Pres: 100307.70 Pa Temp: 24.43C Hum: 32.60% RH Pres: 100314.63 Pa Temp: 24.42C Hum: 32.54% RH Pres: 100309.48 Pa Temp: 24.42C Hum: 32.49% RH Pres: 100331.39 Pa Temp: 24.42C Hum: 32.44% RH Pres: 100305.06 Pa Temp: 24.42C Hum: 32.54% RH Pres: 100312.11 Pa Temp: 24.41C Hum: 32.55% RH Pres: 100311.27 Pa Temp: 24.42C Hum: 32.54% RH Pres: 100310.33 Pa Temp: 24.41C Hum: 32.55% RH Pres: 100311.27 Pa Temp: 24.42C Hum: 32.53% RH Pres: 100310.33 Pa Temp: 24.44C Hum: 32.52% RH Pres: 100312.83 Pa Temp: 24.43C Hum: 32.47% RH Pres: 100308.54 Pa |