Skip to content

Instantly share code, notes, and snippets.

@littledivy
Last active May 19, 2019 06:00
Show Gist options
  • Save littledivy/0424e70a37d84deaa8deea9417a08730 to your computer and use it in GitHub Desktop.
Save littledivy/0424e70a37d84deaa8deea9417a08730 to your computer and use it in GitHub Desktop.
Arduino Automatic Plant Watering System Code For Digital Pin
int digitalSensor = 2;
int pumpPin = 8; //relay pin
int sensorValue = 0;
long pumpDelay = 60L * 1000L * 30L;
long pumpingDuration = 60L * 1000L * 5L;
void setup() {
pinMode(digitalSensor, INPUT);
pinMode(pumpPin, OUTPUT);
digitalWrite(pumpPin, HIGH);
//Serial.begin(9600);
}
void loop() {
sensorValue = digitalRead(digitalSensor);
Serial.print("Moisture Value = " );
Serial.println(sensorValue);
if(sensorValue == HIGH){
digitalWrite(pumpPin,LOW);
//digitalWrite(LED_BUILTIN, HIGH);
delay(pumpingDuration);
digitalWrite(pumpPin, HIGH);
}
delay(pumpDelay); // 1hour
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment