// This project controls the operation of a heater in a steam humidifier
// deppending on the level of water in the tank.
// red = 20% full
// red & green = 40% full
// green = 60% full
// green & yellow = 80% full
// yellow = 100% full
// The pushbuttons are the respective levels of water in the tank
//while the red LED is the relay that will close the contacts of the heater
// https://wokwi.com/projects/341235931096810068
const int redButtonPin = 2;
const int greenButtonPin = 3;
const int yellowButtonPin = 4;
const int relay = 12;
void setup() {
// declare the output and input pins:
pinMode(redButtonPin, INPUT);
pinMode(greenButtonPin, INPUT);
pinMode(yellowButtonPin, INPUT);
pinMode(relay, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
//declare variables and reading the values on the input pins:
int redPin = digitalRead(redButtonPin);
int greenPin = digitalRead(greenButtonPin);
int yellowPin = digitalRead(yellowButtonPin);
// control the output when red is HIGH:
if (redPin == HIGH)
digitalWrite(relay, LOW);
else if (redPin && greenPin == HIGH)
digitalWrite(relay, LOW);
// control the output when green is HIGH:
if (greenPin == HIGH && redPin == LOW) {
digitalWrite(relay, HIGH);
}
// control the output when yellow is HIGH, i.e @ 100% full
if (yellowPin == HIGH) {
digitalWrite(relay, HIGH);
}
if (redPin == HIGH && greenPin == HIGH)
digitalWrite(relay, LOW);
if (redPin == LOW && greenPin == LOW && yellowPin == LOW)
digitalWrite(relay, LOW);
}