Advertisement
misiekii123

dzien_otwarty_2025

Apr 4th, 2025
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_Sensor.h>
  3. #include <Adafruit_BMP280.h>
  4. #include <DHT.h>
  5.  
  6. #define DHTPIN 4
  7. #define DHTTYPE DHT11
  8.  
  9. DHT dht(DHTPIN, DHTTYPE);
  10. Adafruit_BMP280 bmp;
  11.  
  12. void setup() {
  13.   Serial.begin(9600);
  14.  
  15.   dht.begin();
  16.  
  17.   if (!bmp.begin()) {
  18.     Serial.println("Nie można znaleźć czujnika BMP280!");
  19.     while (1);
  20.   }
  21. }
  22.  
  23. void loop() {
  24.   float temperaturaDHT = dht.readTemperature();
  25.   float wilgotnosc = dht.readHumidity();
  26.  
  27.   if (isnan(temperaturaDHT) || isnan(wilgotnosc)) {
  28.     Serial.println("Błąd odczytu z DHT11");
  29.   } else {
  30.     Serial.print("DHT11 -> Temp: ");
  31.     Serial.print(temperaturaDHT);
  32.     Serial.print(" °C, Wilgotność: ");
  33.     Serial.print(wilgotnosc);
  34.     Serial.println(" %");
  35.   }
  36.  
  37.   float temperaturaBMP = bmp.readTemperature();
  38.   float cisnienie = bmp.readPressure() / 100.0F; // hPa
  39.  
  40.   Serial.print("BMP280 -> Temp: ");
  41.   Serial.print(temperaturaBMP);
  42.   Serial.print(" °C, Ciśnienie: ");
  43.   Serial.print(cisnienie);
  44.   Serial.println(" hPa");
  45.  
  46.   Serial.println("----------------------------");
  47.   delay(2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement