Arduino temperature, humidity and pressure sketch

I wanted to have a temperature and humidity and pressure measurement in the shack. There was a load of information on the net. I went for and BMP280 sensor and added a DHT11 sensor. Adapted the software a bit and there we go.

This time no pics, no schematic just the sketch.

 

//https://create.arduino.cc/projecthub/Noshirt/arduino-weather-station-v1-0-bmp280-050e01
// Expanded with DHT11 humidity sensor and adapted LCD display by PA3CSG june 2020

#include <LiquidCrystal.h> //Library for the LCD screen
#include <BMP280.h> // Library for the BMP280 sensor
#include <SimpleDHT.h>

BMP280 bmp; //Initialize your sensor

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); /*Initialize your LCD, make sure you wired it correctly */

#define P0 1013.25 //Standard atmospheric pressure
#define contrast 9 //9 and 10 are the pins where you wire the matching LCD pins
#define brightness 10 //for contrast and brightness regulation

double T = 0; //Starting temperature value
double P = 0; //Starting pressure value
char measure = 0;

// Initialize humidity sensor.
const int pinDHT11 = 8;
SimpleDHT11 dht11;

void collectData() {
measure = bmp.startMeasurment();
if (measure != 0) {
delay(measure);
measure = bmp.getTemperatureAndPressure(T, P);
if (measure != 0) {
P = P + 17; // ‘+17’ is a correction for the sensor error
T = T – 0.8; // like said above

// Read sensor data and store results
// in temperature/humidity variables
byte temperature = 0;
byte humidity = 0;
dht11.read(pinDHT11, &temperature, &humidity, NULL);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” Temperature: “);
lcd.setCursor(5,1);
lcd.print(T);
lcd.setCursor(10,1);
lcd.print((char)223);
lcd.print(” C”);
delay (3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” Pressure: “);
lcd.setCursor(4,1);
lcd.print(P);
lcd.setCursor(9,1);
lcd.print(” hPa “);
delay (3000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” Humidity:”);
lcd.setCursor(5,1);
Serial.print(humidity);
lcd.print(humidity);
lcd.setCursor(9,1);
lcd.print(“%”);
delay (3000);
}
else
lcd.print(“Error.”);
}
else
lcd.print(“Error.”);
}

void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(contrast, OUTPUT);
pinMode(brightness, OUTPUT);
analogWrite(contrast, 100); // ‘100’ and ‘255’ are the contrast and brightness
analogWrite(brightness, 255); // values I suggest, but you can change them as
if (!bmp.begin()) { // you prefer
delay(1000);
lcd.print(“Init. failed.”);
lcd.setCursor(0, 1);
delay(1000);
lcd.print(“Check wiring.”);
while (1);
}
else
lcd.print(“Init. OK.”);

bmp.setOversampling(4);
delay(2000);
collectData();
}

void loop() {
collectData();

}