Skip to content

Instantly share code, notes, and snippets.

@qguv
Last active Feb 13, 2019
Embed
What would you like to do?
bloemenbad
/*
* _ _
* | |__ | | ___ ___ _ __ ___ ___ _ __
* | '_ \| |/ _ \ / _ \ '_ ` _ \ / _ \ '_ \
* | |_) | | (_) | __/ | | | | | __/ | | |
* |_.__/|_|\___/ \___|_| |_| |_|\___|_| |_|
* ____ _ ____
* | __ ) / \ | _ \
* | _ \ / _ \ | | | |
* | |_) / ___ \| |_| |
* |____/_/ \_\____/
*
* _ _ __ _
* /'\/ ' '\/ \_/ \_',
* ( )
* \ /
* (_, _ _ )
* \_,/ \_/'\/ \_)
* | | | | | | |
* | | | | | |
* | | | | | | |
* | | | | | |
* | | | | | | |
* | | | | | |
* | | | | | | |
* | | | | | |
*
* 1. turn on relay, turning on a valve or pump
* 2. wait WET_DURATION milliseconds
* 3. turn off relay, turning off the valve or pump
* 4. blink every 5s until it's been on for RESTART_AFTER milliseconds
* 5. restart
*
*/
#define LED_PIN 13
#define RELAY_PIN 12
#define SECONDS_ms 1000
#define DAYS_ms (24 * 60 * 60 * 1000)
/* how much water to give the plants at each watering */
#define WET_DURATION 10 * SECONDS_ms
/* how often to water the plants */
#define RESTART_AFTER (3 * DAYS_ms) - (1 * SECONDS_ms)
#define BLINK_OFF_DURATION 200
#define BLINK_ON_DURATION 4800
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
digitalWrite(RELAY_PIN, HIGH);
delay(WET_DURATION);
digitalWrite(RELAY_PIN, LOW);
}
void loop() {
if (millis() > RESTART_AFTER)
ESP.restart();
digitalWrite(LED_PIN, LOW);
delay(BLINK_ON_DURATION);
digitalWrite(LED_PIN, HIGH);
delay(BLINK_OFF_DURATION);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment