-
Notifications
You must be signed in to change notification settings - Fork 0
/
Capacitive_Soli_Moist_Sensor.ino
43 lines (35 loc) · 1.16 KB
/
Capacitive_Soli_Moist_Sensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Find soil moisture level using generic capacitive moisture sensor (3 Pins)
https://www.clevertronics.blogspot.com
Used Hardware : ESP32 by ESPRESSIF SYSTEMS
Used IDE : Arduino IDE 1.8.12
*/
const int AirValue = 0; //Replace this value with ADC value when probe is in air(Val_1).
const int WaterValue = 3100; //Replace this with ADC value when probe is fully dipped in water(Val_2).
int soilMoistureValue = 0;
int soilmoisturepercent=0;
const int MoistPin=35; // ADC PIN in your MCU
void setup()
{
Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop()
{
soilMoistureValue = analogRead(MoistPin); //Reads the capacitive sensor value.
Serial.println(soilMoistureValue); // This is pure ADC value. Use this for above 2 test cases(Val_1 and Val_2).
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if(soilmoisturepercent > 100)
{
Serial.println("100 %");
}
else if(soilmoisturepercent <0)
{
Serial.println("0 %");
}
else if(soilmoisturepercent >0 && soilmoisturepercent < 100)
{
Serial.print(soilmoisturepercent);
Serial.println("%");
}
delay(500);
}