I just can't figure out how to properly display digitalWrite on my LCD in my sketch.
When the temperature goes in between min and max fan status disappaere from my display, no matter if it is LOW or HIGH(ON or OFF), but if it goes out of that range it shows normally.
How do I solve this, I searched for bool, but I get confused, how to implement it
#include <Wire.h>
#include "DHT.h"
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#define DHTPIN 8
#define DHTTYPE DHT22
DHT sensor(DHTPIN, DHTTYPE);
const int vent = 12; // ventilation relay pin
const int humy = 11; // humidifier relay pin
//values to turn off and on ventilation based on temperature (and RH which doesn't works for me too)
float maxTemp = 28.50;
float minTemp = 26.80;
float maxHumy = 55.00;
float minHumy = 53.00;
//values to turn off and on humidifier based on RH
float maxHumy1 = 48.00;
float minHumy1 = 45.00;
void setup() {
lcd.begin(16, 2);
sensor.begin();
digitalWrite(vent, HIGH);
pinMode(vent, OUTPUT);
digitalWrite(humy, HIGH);
pinMode(humy, OUTPUT);
}
void loop() {
lcd.clear();
float t = sensor.readTemperature(); //reading the temperature from the sensor
float h = sensor.readHumidity(); //reading the humidity from the sensor
h = map(h, 21.8, 91.2, 15.6, 77.6); //calibration I did to match my hygrometers
// Checking if the sensor is sending values or not
if (isnan(t) || isnan(h)) {
lcd.print("Failed");
return;
}
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.print(t);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.print(h);
lcd.print("%");
//control for ventilation
if (t >= maxTemp) {
digitalWrite(vent, LOW);
lcd.setCursor(9, 0);
lcd.print("V:On");
}
else if (t <= minTemp) {
digitalWrite(vent, HIGH);
lcd.setCursor(9, 0);
lcd.print("V:Off");
}
//controll for humidifier
if (h <= minHumy1) {
digitalWrite(humy, LOW);
lcd.setCursor(9, 1);
lcd.print("H:On");
}
else if (h >= maxHumy1) {
digitalWrite(humy, HIGH);
lcd.setCursor(9, 1);
lcd.print("H:Off");
}
}
double map(double x, double in_min, double in_max, double out_min, double out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}