Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//sketch designed for the resistive moisture sensor YL-69 sensor.
//it's recommended to use this sensor without a continuous VCC
int moistReadpin = A0; //moist sensor reading pin
int pumpPin = 2; //triggers pump to work
int okLED = 5; //good moist light pin
int wateringLED = 6; //watering light pin
int sensorValue; //reading from the sensor
void setup(){
pinMode(pumpPin, OUTPUT);
pinMode(okLED, OUTPUT);
pinMode(wateringLED, OUTPUT);
Serial.begin(9600);
runTests(); //runs series of tests to the main components.
Serial.println("Starting reading...");
delay(5000);
}
void loop(){
}
void runTests() {
//turns ON and OFF the LEDs in the circuit
Serial.println("LED's test...");
digitalWrite(wateringLED, HIGH);
digitalWrite(okLED, HIGH);
delay(2000);
digitalWrite(wateringLED, LOW);
digitalWrite(okLED, LOW);
delay(2000);
//turns ON and OFF the pump for a really short period
Serial.println("Pump test...");
digitalWrite(pumpPin, HIGH);
delay(500);
digitalWrite(pumpPin, LOW);
delay(2000);
//turns the moisture sensor ON and gives a sample reading to the Serial Monitor
int testCounter = 0;
Serial.println("Sensor test...");
while (testCounter < 200) {
sensorValue = analogRead(moistReadpin);
Serial.print("Sensor value: ");
Serial.println(sensorValue);
testCounter = testCounter + 1;
}
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment