Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://www.youtube.com/@LeventeDaradici/videos
- #include <DHT.h>
- #include <LCD_I2C.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define DHTPIN 7
- #define ONE_WIRE_BUS 8
- #define DHTTYPE DHT11
- LCD_I2C lcd(0x27, 16, 2);
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- boolean AmGasitDHT11, AmGasitDS18B20 = false;
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- Serial.begin(9600);
- lcd.begin();
- lcd.backlight();
- Serial.println("Detectare senzor");
- lcd.setCursor(0, 0);
- lcd.print("DETECTARE DHT11");
- delay(500);
- lcd.setCursor(0, 1);
- lcd.print("DETECTARE DS18B20");
- delay(500);
- dht.begin();
- pinMode(13, OUTPUT);
- sensors.begin();
- }
- void loop()
- {
- delay(1000);
- digitalWrite(13,LOW);
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- float f = dht.readTemperature(true);
- if (isnan(h) || isnan(t) || isnan(f))
- {
- Serial.println("Nu am gasit senzor DHT11!");
- AmGasitDHT11 = false;
- lcd.setCursor(0, 0);
- lcd.print(" ");
- lcd.setCursor(2, 0);
- lcd.print("LIPSA DHT11!");
- } else
- {
- lcd.setCursor(0, 0);
- lcd.print(" ");
- lcd.setCursor(0, 0);
- lcd.print("DHT11");
- AmGasitDHT11 = true;
- float hif = dht.computeHeatIndex(f, h);
- float hic = dht.computeHeatIndex(t, h, false);
- Serial.print("DHT11 Temperatura: ");
- Serial.print(t,1);
- Serial.println(F("°C "));
- Serial.print("DHT11 Umiditate: ");
- Serial.print(h,0);
- Serial.println("%");
- lcd.setCursor(6, 0);
- lcd.print(t,1);
- lcd.setCursor(10,0);
- lcd.print((char)223);
- lcd.setCursor(11,0);
- lcd.print("C");
- lcd.setCursor(13, 0);
- lcd.print(h,0);
- lcd.setCursor(15,0);
- lcd.print("%");
- }
- delay(1000);
- digitalWrite(13,HIGH);
- sensors.requestTemperatures();
- float tempC = sensors.getTempCByIndex(0);
- if(tempC != DEVICE_DISCONNECTED_C)
- {
- Serial.print("DS18B20 Temperatura ");
- Serial.println(tempC);
- lcd.setCursor(0, 1);
- lcd.print(" ");
- lcd.setCursor(0,1);
- lcd.print("DS18B20");
- lcd.setCursor(10,1);
- lcd.print(tempC,2);
- lcd.setCursor(14,1);
- lcd.print((char)223);
- lcd.setCursor(15,1);
- lcd.print("C");
- } else
- {
- Serial.println("Nu am gasit senzor DS18B20");
- lcd.setCursor(0,1);
- lcd.print(" ");
- lcd.setCursor(1,1);
- lcd.print("LIPSA DS18B20");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement