Skip to content

Instantly share code, notes, and snippets.

@csaden
Created July 30, 2019 03:24
Show Gist options
  • Save csaden/5899a17e800842fdb77d59e4c07e9294 to your computer and use it in GitHub Desktop.
Save csaden/5899a17e800842fdb77d59e4c07e9294 to your computer and use it in GitHub Desktop.
Code to detect soil moisture using arduino uno
#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