Skip to content

Instantly share code, notes, and snippets.

@nobodyguy
Last active September 25, 2015 21:53
Show Gist options
  • Save nobodyguy/80f9c21c62561cc6efc4 to your computer and use it in GitHub Desktop.
Save nobodyguy/80f9c21c62561cc6efc4 to your computer and use it in GitHub Desktop.
Watering system using Arduino, soil humidity sensor and 3-6V water pump. Checking for humidity is done every 24 hours.
const int sensorPin = A0;
const int sensorPowerPin = 4;
int sensorValue = 0;
const int transistorPin = 5;
const long sleepTime = 86390000; // 24 hours - 10 seconds
const int wateringTime = 10000; // 10 seconds
const int drySoil = 400;
const int wetSoil = 500;
void setup() {
pinMode(sensorPowerPin, OUTPUT);
pinMode(transistorPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = getSensorValue();
if (sensorValue < wetSoil) {
waterIt();
}
delay(sleepTime);
}
int getSensorValue() {
digitalWrite(sensorPowerPin, HIGH);
int sensorValueTemp = analogRead(sensorPin);
digitalWrite(sensorPowerPin, LOW);
return sensorValueTemp;
}
void waterIt() {
digitalWrite(transistorPin, HIGH);
delay(wateringTime);
digitalWrite(transistorPin, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment