Last active
June 4, 2018 23:56
-
-
Save vvzen/afd14c138096d49fc47edfa89afce588 to your computer and use it in GitHub Desktop.
A simple watering system using a relay to activate a peristaltic pump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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