I needed a device to time my sprinklers, because I had been forgetting to turn them off. So I made a very simple program to turn them off after 45 minutes. Future versions will have an array of outputs, so you can run sections with one button push. Hardware: Either board should work, I used the LPC1768. You will also need a solenoid to control the water, I am testing a 12V rainbird valve with a relay and 12V power supply.

Dependencies:   PinDetect mbed

Sprinkler Timer

I needed a device to time my sprinklers, because I had been forgetting to turn them off. So I made a very simple program to turn them off after some number of minutes.

Hardware

Connections

Button:

  • One side to pin 5
  • the other to Vout

Relay:

  • Vcc to Vout
  • Gnd to ground
  • IN1 to pin 6

Directions/Use

Do not hold button while restarting!

I have experienced negative effects during testing while the button was held on. If you have problems and suspect this you may need to reflash your chip

  • The button will start the sprinkler when it is off and vice versa.
  • Once started if not interrupted, the sprinkler shall run for 25 minutes.

Future

Future versions will have an array of outputs, so you can run sections with one button push.

main.cpp

Committer:
fossum_13
Date:
2013-01-22
Revision:
2:5c195b07885c
Parent:
1:00bc4b85976e

File content as of revision 2:5c195b07885c:

#include "mbed.h"
#include "PinDetect.h"

// Objects
DigitalOut myLed(LED1);
DigitalOut solenoid(p6);
PinDetect button(p5);
Timer timer;

// Primitives
int timeInMinutes = 25; // Timer is only good to about 30 mins!
float halfSecond = 0.5; // LED blink rate

// Interrupt function for start/stop button
//////////////////////////////////////////////////
void StartStop() {
    // Enabled = !Enabled
    if(solenoid.read()) {
        // Turn off
        timer.stop();
        solenoid = false;
    } else {
        // Turn on
        timer.reset();
        timer.start();
        solenoid = true;
    }
}

// Main loop
//////////////////////////////////////////////////
int main() {
    // Set button interrupt w/PullDown and debounce
    button.mode(PullDown);
    button.attach_asserted_held(&StartStop);
    button.setSampleFrequency(9);
    
    // Infinite loop
    while(true) {
        // Stop if time(s) > n Mins(m) * 60(s)
        if(timer.read() > timeInMinutes * 60) {
            solenoid = false;
            timer.stop();
        }
        
        // Slow pulse status LED when enabled
        if(solenoid.read())
            myLed = !myLed.read();
        else
            myLed = false;
        
        // Wait so LED pulses
        wait(halfSecond);
    }
}