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.

Committer:
fossum_13
Date:
Tue Jan 22 16:59:24 2013 +0000
Revision:
1:00bc4b85976e
Parent:
0:62d1fc93556a
Fully tested v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fossum_13 0:62d1fc93556a 1 #include "mbed.h"
fossum_13 0:62d1fc93556a 2 #include "PinDetect.h"
fossum_13 0:62d1fc93556a 3
fossum_13 1:00bc4b85976e 4 // Objects
fossum_13 0:62d1fc93556a 5 DigitalOut myLed(LED1);
fossum_13 0:62d1fc93556a 6 DigitalOut solenoid(p6);
fossum_13 0:62d1fc93556a 7 PinDetect button(p5);
fossum_13 0:62d1fc93556a 8 Timer timer;
fossum_13 0:62d1fc93556a 9
fossum_13 1:00bc4b85976e 10 // Primitives
fossum_13 1:00bc4b85976e 11 int timeInMinutes = 25; // Timer is only good to about 30 mins!
fossum_13 1:00bc4b85976e 12 float halfSecond = 0.5; // LED blink rate
fossum_13 0:62d1fc93556a 13
fossum_13 1:00bc4b85976e 14 // Interrupt function for start/stop button
fossum_13 1:00bc4b85976e 15 //////////////////////////////////////////////////
fossum_13 0:62d1fc93556a 16 void StartStop() {
fossum_13 0:62d1fc93556a 17 // Enabled = !Enabled
fossum_13 0:62d1fc93556a 18 if(solenoid.read()) {
fossum_13 0:62d1fc93556a 19 // Turn off
fossum_13 0:62d1fc93556a 20 timer.stop();
fossum_13 1:00bc4b85976e 21 solenoid = false;
fossum_13 0:62d1fc93556a 22 } else {
fossum_13 0:62d1fc93556a 23 // Turn on
fossum_13 0:62d1fc93556a 24 timer.reset();
fossum_13 0:62d1fc93556a 25 timer.start();
fossum_13 1:00bc4b85976e 26 solenoid = true;
fossum_13 0:62d1fc93556a 27 }
fossum_13 0:62d1fc93556a 28 }
fossum_13 0:62d1fc93556a 29
fossum_13 1:00bc4b85976e 30 // Main loop
fossum_13 1:00bc4b85976e 31 //////////////////////////////////////////////////
fossum_13 0:62d1fc93556a 32 int main() {
fossum_13 1:00bc4b85976e 33 // Set button interrupt w/PullDown and debounce
fossum_13 0:62d1fc93556a 34 button.mode(PullDown);
fossum_13 0:62d1fc93556a 35 button.attach_asserted_held(&StartStop);
fossum_13 1:00bc4b85976e 36 button.setSampleFrequency(9);
fossum_13 0:62d1fc93556a 37
fossum_13 0:62d1fc93556a 38 // Infinite loop
fossum_13 1:00bc4b85976e 39 while(true) {
fossum_13 1:00bc4b85976e 40 // Stop if time(s) > n Mins(m) * 60(s)
fossum_13 0:62d1fc93556a 41 if(timer.read() > timeInMinutes * 60) {
fossum_13 1:00bc4b85976e 42 solenoid = false;
fossum_13 0:62d1fc93556a 43 timer.stop();
fossum_13 0:62d1fc93556a 44 }
fossum_13 0:62d1fc93556a 45
fossum_13 0:62d1fc93556a 46 // Slow pulse status LED when enabled
fossum_13 0:62d1fc93556a 47 if(solenoid.read())
fossum_13 0:62d1fc93556a 48 myLed = !myLed.read();
fossum_13 0:62d1fc93556a 49 else
fossum_13 1:00bc4b85976e 50 myLed = false;
fossum_13 0:62d1fc93556a 51
fossum_13 1:00bc4b85976e 52 // Wait so LED pulses
fossum_13 1:00bc4b85976e 53 wait(halfSecond);
fossum_13 0:62d1fc93556a 54 }
fossum_13 0:62d1fc93556a 55 }