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:
Mon Jan 21 16:01:52 2013 +0000
Revision:
0:62d1fc93556a
Child:
1:00bc4b85976e
Initial release (minor testing)

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 0:62d1fc93556a 4 DigitalOut myLed(LED1);
fossum_13 0:62d1fc93556a 5 DigitalOut solenoid(p6);
fossum_13 0:62d1fc93556a 6
fossum_13 0:62d1fc93556a 7 PinDetect button(p5);
fossum_13 0:62d1fc93556a 8
fossum_13 0:62d1fc93556a 9 Timer timer;
fossum_13 0:62d1fc93556a 10
fossum_13 0:62d1fc93556a 11 bool enable = 0;
fossum_13 0:62d1fc93556a 12 int timeInMinutes = 45;
fossum_13 0:62d1fc93556a 13
fossum_13 0:62d1fc93556a 14 void StartStop() {
fossum_13 0:62d1fc93556a 15 // Enabled = !Enabled
fossum_13 0:62d1fc93556a 16 if(solenoid.read()) {
fossum_13 0:62d1fc93556a 17 // Turn off
fossum_13 0:62d1fc93556a 18 timer.stop();
fossum_13 0:62d1fc93556a 19 solenoid = 0;
fossum_13 0:62d1fc93556a 20 } else {
fossum_13 0:62d1fc93556a 21 // Turn on
fossum_13 0:62d1fc93556a 22 timer.reset();
fossum_13 0:62d1fc93556a 23 timer.start();
fossum_13 0:62d1fc93556a 24 solenoid = 1;
fossum_13 0:62d1fc93556a 25 }
fossum_13 0:62d1fc93556a 26 }
fossum_13 0:62d1fc93556a 27
fossum_13 0:62d1fc93556a 28 int main() {
fossum_13 0:62d1fc93556a 29 // Set button interrupt w/PullDown and 20ms sample
fossum_13 0:62d1fc93556a 30 button.mode(PullDown);
fossum_13 0:62d1fc93556a 31 button.attach_asserted_held(&StartStop);
fossum_13 0:62d1fc93556a 32 button.setSampleFrequency();
fossum_13 0:62d1fc93556a 33
fossum_13 0:62d1fc93556a 34 // Infinite loop
fossum_13 0:62d1fc93556a 35 while(1) {
fossum_13 0:62d1fc93556a 36 // Stop if time > 45 Mins
fossum_13 0:62d1fc93556a 37 if(timer.read() > timeInMinutes * 60) {
fossum_13 0:62d1fc93556a 38 solenoid = 0;
fossum_13 0:62d1fc93556a 39 timer.stop();
fossum_13 0:62d1fc93556a 40 }
fossum_13 0:62d1fc93556a 41
fossum_13 0:62d1fc93556a 42 // Slow pulse status LED when enabled
fossum_13 0:62d1fc93556a 43 if(solenoid.read())
fossum_13 0:62d1fc93556a 44 myLed = !myLed.read();
fossum_13 0:62d1fc93556a 45 else
fossum_13 0:62d1fc93556a 46 myLed = 0;
fossum_13 0:62d1fc93556a 47
fossum_13 0:62d1fc93556a 48 wait(0.5);
fossum_13 0:62d1fc93556a 49 }
fossum_13 0:62d1fc93556a 50 }