Created
July 30, 2019 03:24
-
-
Save csaden/5899a17e800842fdb77d59e4c07e9294 to your computer and use it in GitHub Desktop.
Code to detect soil moisture using arduino uno
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 characters
#define SensorPin A0 | |
float sensorValue = 0; | |
int sensorLimit = 597; | |
int piezoPin = 8; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(13, OUTPUT); | |
} | |
void loop() { | |
for (int i = 0; i <= 100; i++) { | |
sensorValue = sensorValue + analogRead(SensorPin); | |
delay(1); | |
} | |
sensorValue = sensorValue / 100.0; | |
Serial.println(sensorValue); | |
if (sensorValue < sensorLimit) { | |
digitalWrite(13, HIGH); | |
tone(piezoPin, 50, 200); | |
} else { | |
digitalWrite(13, LOW); | |
} | |
delay(5000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment