I test to read data from 2 analog pin 33 and 35 like this code.
int soil_pin = 35;
int rain_pin = 33;
int SoilRead(){
int v;
v = analogRead(soil_pin);
v = map(v, 0, 4095, 100, 0);
return v;
}
String RainRead(){
int v;
String st;
v = analogRead(rain_pin);
v = map(v, 0, 4095, 100, 0);
st = "No Rain";
if(v > 0){
st = "Raining";
}
return st;
}
void setup() {
Serial.begin(9600); // set up serial port for 9600 baud (speed)
delay(500); // wait for display to boot up
}
void loop() {
Serial.print(SoilRead());
Serial.println(" %");
Serial.print(RainRead());
Serial.println("");
delay(500); //wait for half a second, so it is easier to read
}
when I drop water on rain drop sensor the output of soil sensor also increase. when I wipe the water on rain drop sensor then soil sensor back to 0%. How to fix it?
If you disconnect the sensors and connect Pin33 to gnd and Pin35 to 3V3.
What do you get?
If you disconnect the sensors and connect Pin35 to gnd and Pin33 to 3V3.
Can you please post a link to spec/data of the two devices?
I'm not familiar with the ESP32. Maybe the same rules apply as for the AVR based boards where you need to give the Sample-and-Hold circuit time to adjust to the new input before reading it. This is usually done by reading a pin twice and throwing the first result away.