Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Halifax Makerspace
- Sunday workshop
- -----
- Moisture sensing plant waterer
- */
- bool debug = true;
- int led = 13;
- int motorPin = 9;
- int sensorPin = 0;
- int moistureThreshold = 1100;
- int pumpOnTime = 1000;
- int loopDelay = 3000;
- void setup()
- {
- pinMode(motorPin, OUTPUT);
- if (debug) {
- pinMode(led, OUTPUT);
- Serial.begin(9600);
- delay(5000);
- }
- }
- void loop()
- {
- int sensorValue = analogRead(sensorPin);
- if (sensorValue > moistureThreshold)
- {
- if (debug) {
- digitalWrite(led, HIGH); // Turn on the LED
- }
- digitalWrite(motorPin, HIGH);
- delay(pumpOnTime);
- digitalWrite(motorPin, LOW);
- if (debug) {
- digitalWrite(led, LOW); // Turn off the LED
- }
- }
- if (debug) {
- Serial.println(sensorValue);
- }
- delay(loopDelay);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement