Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vvzen
Last active June 4, 2018 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vvzen/afd14c138096d49fc47edfa89afce588 to your computer and use it in GitHub Desktop.
Save vvzen/afd14c138096d49fc47edfa89afce588 to your computer and use it in GitHub Desktop.
A simple watering system using a relay to activate a peristaltic pump
const int RELAY_PIN = 2;
unsigned long LONG_DELAY_MS = 43200000; // 12 hours expressed in milliseconds
unsigned int WATERING_TIME = 2000;
unsigned long startMillis;
void setup() {
pinMode(RELAY_PIN, OUTPUT);
startMillis = millis();
Serial.begin(9600);
digitalWrite(RELAY_PIN, LOW);
Serial.print("Long delay: ");
Serial.println(LONG_DELAY_MS);
}
void loop() {
if (millis() - startMillis > LONG_DELAY_MS){
digitalWrite(RELAY_PIN, HIGH);
Serial.println(millis());
Serial.println("---------");
Serial.println("watering!");
Serial.println("---------");
// reset the timer
startMillis = millis();
// wait the required time
delay(WATERING_TIME);
}
else {
digitalWrite(RELAY_PIN, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment