Last active
June 18, 2020 17:56
-
-
Save brandonaaskov/10a6fb6883fa2d0bb6ca107185f35a13 to your computer and use it in GitHub Desktop.
Moisture soil sensor
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
int soilPin = A0; | |
int soilPower = 7; | |
void setup() | |
{ | |
Serial.begin(9600); // open serial over USB | |
pinMode(soilPower, OUTPUT); | |
digitalWrite(soilPower, LOW); | |
} | |
void loop() | |
{ | |
Serial.print("Soil Moisture = "); | |
Serial.println(readSoil()); | |
delay(1000); | |
} | |
int readSoil() | |
{ | |
digitalWrite(soilPower, HIGH); | |
delay(1000); | |
int val = analogRead(soilPin); | |
digitalWrite(soilPower, LOW); | |
return val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment