Currently I am coding a hs22 with one lcd, one button, and one relay attached
I would like to be able to select between 3 operating modes
Basiclly
75% 85% 95% RH
so far here is my code
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
#include "DHT.h"
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
#define RELAY 3
#define DHTPIN 12
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int buttonPin = 2;
int buttonState = 0;
int tgtRH = 85;
void setup() {
pinMode(RELAY,OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(RELAY,HIGH);
Serial.begin(9600);
lcd.begin(16, 2);
dht.begin();
}
void loop() {
//DHT Code
buttonState = digitalRead(buttonPin);
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.println(" *F");
lcd.setCursor(0, 0);
lcd.print("T ");
lcd.print(f);
lcd.print(" H ");
lcd.print(h);
//DHT Code Ends
lcd.setCursor(0, 1);
//ButtonCode Starts
//Relay Code Ends
lcd.print(millis()/1000);
}
I need some help coding in the button if statements please
if button pressed and 75% RH then switch to 85, if button pressed again & 85 then 95, if 95 then 75
and then have the relay activate if the value (h) is 5% below target and shut off when it reaches the target