Created
May 19, 2018 19:57
-
-
Save hernan43/10267114d25607acac094927715011d2 to your computer and use it in GitHub Desktop.
Basic soil moisture sensor(arduino)
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
int sensor_pin = A0; | |
int buzzer_pin = 2; | |
int output_value ; | |
void setup() { | |
pinMode(buzzer_pin, OUTPUT); | |
tone(buzzer_pin, 3500, 200); | |
Serial.begin(9600); | |
Serial.println("Reading From the Sensor ..."); | |
delay(2000); | |
} | |
void loop() { | |
output_value = analogRead(sensor_pin); | |
Serial.print("Moisture(raw) : "); | |
Serial.print(output_value); | |
Serial.println(); | |
output_value = map(output_value, 1000, 250, 0, 100); | |
Serial.print("Moisture : "); | |
Serial.print(output_value); | |
Serial.println("%"); | |
if(output_value <= 20){ | |
// beep beep | |
Serial.println("beep beep"); | |
tone(buzzer_pin, 3500, 200); | |
delay(200); | |
tone(buzzer_pin, 3500, 200); | |
delay(200); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment