Simple misting timer for Greenhouse 20 sec on, 20 min off

Edward A. Kimble, PhD, Purdue '77

  Greenhouse mist timer
  Turns on for 20 seconds, then off for remainder of 20 minutes,
  Action is echoed to the console if connected
int led1 = 13,onoff=0;
long a=1;

void setup() {     
  pinMode(led1, OUTPUT); 

void loop() { 
  a++;  if (a>1200){ a=0;}  //count to 20 minutes
   if (a<20){               //20 seconds on
   if (onoff==0){
    onoff=1;   //toggle output to on if off
    Serial.println("Sprinkler on"); 
    digitalWrite(led1, HIGH);
   } Serial.print(a);Serial.print(",");  //show sprinkler time
  else {
    if (onoff==1) {onoff=0;  //toggle output to off if it is on
    Serial.println(" ");Serial.println("Sprinkler off");
    digitalWrite(led1, LOW);} if ((a%60)==0){Serial.print(a/60);Serial.println(" Min");} }
 delay(1000);     //wait one second

Pin 13, on/off, suitable for driving an opto relay to run a greenhouse mister valve.Caveat emptor, cheap board, lazy programmer, smile

Edward Kimble, PhD click here to e-mail me at:
Edited June7, 2017