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.

Revision:
0:62d1fc93556a
Child:
1:00bc4b85976e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jan 21 16:01:52 2013 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+#include "PinDetect.h"
+
+DigitalOut myLed(LED1);
+DigitalOut solenoid(p6);
+
+PinDetect button(p5);
+
+Timer timer;
+
+bool enable = 0;
+int timeInMinutes = 45;
+
+void StartStop() {
+    // Enabled = !Enabled
+    if(solenoid.read()) {
+        // Turn off
+        timer.stop();
+        solenoid = 0;
+    } else {
+        // Turn on
+        timer.reset();
+        timer.start();
+        solenoid = 1;
+    }
+}
+
+int main() {
+    // Set button interrupt w/PullDown and 20ms sample
+    button.mode(PullDown);
+    button.attach_asserted_held(&StartStop);
+    button.setSampleFrequency();
+    
+    // Infinite loop
+    while(1) {
+        // Stop if time > 45 Mins
+        if(timer.read() > timeInMinutes * 60) {
+            solenoid = 0;
+            timer.stop();
+        }
+        
+        // Slow pulse status LED when enabled
+        if(solenoid.read())
+            myLed = !myLed.read();
+        else
+            myLed = 0;
+        
+        wait(0.5);
+    }
+}