Advertisement
adamundefined

Arduino - Plant Waterer

Jul 30th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. /*
  2. Halifax Makerspace
  3. Sunday workshop
  4. -----
  5. Moisture sensing plant waterer
  6. */
  7.  
  8. bool debug = true;
  9.  
  10. int led = 13;
  11. int motorPin = 9;
  12. int sensorPin = 0;
  13. int moistureThreshold = 1100;
  14. int pumpOnTime = 1000;
  15. int loopDelay = 3000;
  16.  
  17. void setup()
  18. {
  19.   pinMode(motorPin, OUTPUT);
  20.   if (debug) {
  21.     pinMode(led, OUTPUT);
  22.     Serial.begin(9600);
  23.     delay(5000);
  24.   }
  25. }
  26.  
  27. void loop()
  28. {
  29.   int sensorValue = analogRead(sensorPin);  
  30.   if (sensorValue >  moistureThreshold)
  31.   {
  32.     if (debug) {
  33.       digitalWrite(led, HIGH);   // Turn on the LED
  34.     }
  35.     digitalWrite(motorPin, HIGH);
  36.     delay(pumpOnTime);
  37.     digitalWrite(motorPin, LOW);
  38.     if (debug) {
  39.       digitalWrite(led, LOW);    // Turn off the LED  
  40.     }  
  41.   }
  42.   if (debug) {
  43.     Serial.println(sensorValue);
  44.   }
  45.   delay(loopDelay);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement