De Bosch BME280 is een digitale omgevingssensor die temperatuur, relatieve luchtvochtigheid en barometrische druk meet. Hij communiceert meestal via I2C met microcontrollers. Gebruik hem voor weer- en luchtkwaliteitsprojecten door de data-interface van de sensor aan te sluiten op je Arduino/ESP32.
| Pin | Signaal | Beschrijving |
|---|---|---|
VIN |
power | Module power input, typically 3.3–5V for the BME280 breakout. |
GND |
ground | Ground reference for power and I2C signals. |
SCL |
SCL | I2C clock line from the microcontroller to the BME280. |
SDA |
SDA | I2C data line between the microcontroller and the BME280. |
| Van | Naar | Draad |
|---|---|---|
board:5V |
x1:VIN |
red |
board:GND |
x1:GND |
black |
board:SCL |
x1:SCL |
green |
board:SDA |
x1:SDA |
blue |
Dit voorbeeld is geschreven en compile-gecheckt voor de arduino-uno. Codey Online past het voor je aan naar elk ander ondersteund board.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("BME280 sensor example");
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor at 0x76. Check wiring.");
while (1) {
delay(10);
}
}
Serial.println("BME280 initialized successfully.");
}
void loop() {
float temperature = bme.readTemperature();
float humidity = bme.readHumidity();
float pressure = bme.readPressure() / 100.0F;
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" hPa");
Serial.println("---");
delay(2000);
}
Beschrijf wat je wilt bouwen. Codey Online schrijft de code, tekent het aansluitschema, compileert het en flasht je board rechtstreeks vanuit de browser.
Gratis starten