Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
2
Indexable
Never
#include <LiquidCrystal.h>




int sensorPin = A8;
int waterSensorValue;
int valueInMillimeter = 0;
int red=13;
int blue=12;



int potenValue = 10;
int potenSensorValue;
int potenValueConverted = 0;

int waterMaxValue = 35;
int potenMaxValue = 30;

int waterDeterminer;
int potenDeterminer;
int difference;



void setup() {
  pinMode (red,OUTPUT);
  pinMode (blue,OUTPUT);
  Serial.begin(9600);
}



void loop() {



potenSensorValue = analogRead(potenValue);
waterSensorValue = analogRead(sensorPin);




valueInMillimeter = waterSensorValue / 10;
Serial.print("Water Value in mm: ");
Serial.print(valueInMillimeter);
Serial.print("\r\n");




potenValueConverted = potenSensorValue / 33;
Serial.print("Water Value Set-Point in mm: ");
Serial.println(potenValueConverted);
delay(5000);




waterDeterminer = waterMaxValue - valueInMillimeter;
potenDeterminer = potenMaxValue - potenValueConverted;
difference = potenDeterminer - waterDeterminer;



if (difference > 5)
  {

    
    Serial.println("Fan turned on!");
    digitalWrite (red,LOW);
    digitalWrite(blue,HIGH);
   Serial.print("\r\n");
    delay(50);
  }
else if (difference < -5)
  {
    digitalWrite (red,HIGH);
    digitalWrite(blue,LOW);}
  

    Serial.println("Pump turned on!");
    digitalWrite(30, LOW);
    digitalWrite(32, HIGH);
    Serial.print("\r\n");
    delay(50);
  }