Last active
February 6, 2020 09:41
-
-
Save tiagomehackit/f19aa0bdb233a35f492a1ce85ac29bf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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