Created
February 28, 2019 10:14
-
-
Save VeggieVampire/dc125ef5a129463032a895b308b57c8a to your computer and use it in GitHub Desktop.
Revisions
-
VeggieVampire created this gist
Feb 28, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ // the setup function runs once when you press reset or power the board int led6 = 6; int buzzer = 7; int val = 0; //value for storing moisture value int soilPin = A4;//Declare a variable for the soil moisture sensor int soilPower = 2;//Variable for Soil moisture Power int SoilMoisture; int DryValue = 500; void setup() { pinMode(soilPower, OUTPUT);//Set D7 as an OUTPUT digitalWrite(soilPower, LOW);//Set to LOW so no power is flowing through the sensor pinMode(led6, OUTPUT); pinMode(buzzer, OUTPUT); // Serial Monitor @ 115200 Serial.begin(115200); Serial.println(" Starting at 115200 baud"); Serial.println("<Arduino is ready>"); } // the loop function runs over and over again forever void loop() { // //BUZZ(); //Serial.print("Soil Moisture = "); //get soil moisture value from the function below and print it //Serial.println(readSoil()); readSoil(); Serial.println(SoilMoisture); if(SoilMoisture >= DryValue){ LED_light(); //BUZZ(); // Serial.println(SoilMoisture); } delay(1000);//take a reading every second } int readSoil(){ //This is a function used to get the soil moisture content digitalWrite(soilPower, HIGH);//turn D7 "On" delay(10);//wait 10 milliseconds val = analogRead(soilPin);//Read the SIG value form sensor digitalWrite(soilPower, LOW);//turn D7 "Off" SoilMoisture = val; return val;//send current moisture value } void LED_light(){ Serial.println("Dry!!"); digitalWrite(led6, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led6, LOW); // turn the LED off by making the voltage LOW } void BUZZ(){ Serial.println("BUZZ"); digitalWrite(buzzer, HIGH); delay(1000); digitalWrite(buzzer, LOW); }