Soil Moisture Sensor with ESP32 Lolin32

Wicked
Posts: 10
Joined: Sat Jun 05, 2021 4:20 pm

Soil Moisture Sensor with ESP32 Lolin32

Postby Wicked » Tue Jun 08, 2021 7:41 am

Hey guys! I have the following ESP32 and I have to connect multiple sensors to it. So far, all my sensors required digital pins , and I’ve used pins like GPIO 32 33 25 etc, both as input and outputs.

I have a sensor for soil moisture that requires analog input, so I can read his values and map it so I have a percentage display. I tried different pins and none works , and I got really confused which ones I can actually use for analog input data.
The reading I get is 4095 , probably because all pins output 3.3V and converted to digital is 4095.

So, which pins can I use to read analog values ?

Code: Select all

// Sensor pins
#define sensorPower 26  // I use this to power the sensor only when I read data. The lifespan of this sensor is really low , I do need to buy a better one, but this has to do for now.
#define sensorPin **CANT FIND A PIN THAT WORKS**

void setup() {
	pinMode(sensorPower, OUTPUT);
	
	// Initially keep the sensor OFF
	digitalWrite(sensorPower, LOW);
	
	Serial.begin(9600);
}

void loop() {
	//get the reading from the function below and print it
	Serial.print("Analog output: ");
	Serial.println(readSensor());
	
	delay(1000);
}

//  This function returns the analog soil moisture measurement
int readSensor() {
	digitalWrite(sensorPower, HIGH);	// Turn the sensor ON
	delay(10);							// Allow power to settle
	int val = analogRead(sensorPin);	// Read the analog value form sensor
	digitalWrite(sensorPower, LOW);		// Turn the sensor OFF
	return val;							// Return analog moisture value
}
Thanks !

Image
Image


but_why
Posts: 2
Joined: Sat Jun 05, 2021 7:48 pm

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby but_why » Tue Jun 08, 2021 5:31 pm

First, in this article there is info, that you cant use ADC2 group of pins, when using Wi-Fi, so be shure to choose one from ADC1 group of pins: https://randomnerdtutorials.com/esp32-a ... duino-ide/
PS I messed up: the ADC2 is not usable , and ADC1 is working, sorry for misinformation
Second, you didn't show your wiring. Seems like there are at least two versions of the sensor's board with different pinout, so if you wire all looking on some picture, not looking to actual pin names - it may be the cause.
This have A0 on the left, and your - on the right.
3327005712113784881.jpg
3327005712113784881.jpg (178.86 KiB) Viewed 7575 times
Last edited by but_why on Wed Jun 09, 2021 10:08 am, edited 1 time in total.

becorey
Posts: 92
Joined: Sat Mar 28, 2020 4:18 pm

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby becorey » Wed Jun 09, 2021 3:55 am

Maybe you need something like

Code: Select all

pinMode(sensorPin, INPUT);

Wicked
Posts: 10
Joined: Sat Jun 05, 2021 4:20 pm

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby Wicked » Wed Jun 09, 2021 3:46 pm

becorey wrote: Maybe you need something like

Code: Select all

pinMode(sensorPin, INPUT);
This doesnt help, at least, I tried and it doesn't..

but_why wrote: First, in this article there is info, that you cant use ADC2 group of pins, when using Wi-Fi, so be shure to choose one from ADC1 group of pins: https://randomnerdtutorials.com/esp32-a ... duino-ide/
PS I messed up: the ADC2 is not usable , and ADC1 is working, sorry for misinformation
Second, you didn't show your wiring. Seems like there are at least two versions of the sensor's board with different pinout, so if you wire all looking on some picture, not looking to actual pin names - it may be the cause.
This have A0 on the left, and your - on the right.
Now im actually scared. I need to finish this project pretty soon, and my goal is to have a blynk app that shows all the data from my sensors + some controls from it. I do use Wifi to communicate, but I dont actually use the * Wifi.begin()* command . So my question is, will my ADC2 pins work in this case ?
Also, about the wiring: VCC -> GPIO 26 ( bc I want to turn on/off the sensor only when doing readings ) , and A0 I tried connecting to different ADC pins and none works.

Wicked
Posts: 10
Joined: Sat Jun 05, 2021 4:20 pm

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby Wicked » Wed Jun 09, 2021 4:00 pm

Also, reading the sensor's datasheet I can see that :
- Input Voltage = 3.3-5V
- Output Voltage = 0-4.2V

But because I want to connect the voltage to a GPIO pin , and not 5V , should I be aware of the output voltage to not harm my ESP? Because the GPIO pins can only take 3.3 V .

becorey
Posts: 92
Joined: Sat Mar 28, 2020 4:18 pm

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby becorey » Sat Jun 12, 2021 3:07 am

If the supply.voltage is 3.3v it (most likely) won't output any higher than that.

Separate parts of the system, figure out what isn't working. Can you use a multimeter or oscilloscope to read the analog voltage of the soil moisture sensor?
Can you put an intermediate 0-3.3v on the ADC pin and read a value 0-4095?

Wicked
Posts: 10
Joined: Sat Jun 05, 2021 4:20 pm

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby Wicked » Mon Jun 14, 2021 2:01 pm

becorey wrote:
Sat Jun 12, 2021 3:07 am
If the supply.voltage is 3.3v it (most likely) won't output any higher than that.

Separate parts of the system, figure out what isn't working. Can you use a multimeter or oscilloscope to read the analog voltage of the soil moisture sensor?
Can you put an intermediate 0-3.3v on the ADC pin and read a value 0-4095?
I somehow made it work. Also, I bought a capacitive sensor and I advise everyone to also use those, over the resistive ones.

Kelley541
Posts: 1
Joined: Fri Jun 18, 2021 4:51 am

Re: Soil Moisture Sensor with ESP32 Lolin32

Postby Kelley541 » Fri Jun 18, 2021 4:55 am

1.
2 More Images This setup procedure should work on a Windows PC, MAC and LINUX (x86) system. Unfortunately for Raspberry PI users the LINUX (ARM) Libraries for the ESP32 Board is not available yet (although there was real clever people who compiled them from source) . • Download and Install the Arduino IDE • In the Preferences menu, add https://dl.espressif.com/dl/package_esp32_index.json to the Aditional Boards Manager URL. • Install the ESP32 Libraries from Tools>Board>Boards Manager. Search for esp32 by espressif systems • Select your Board in the menu: Tools>Board>"WeMos" WiFi
2.
If you need to log your data, attach a Pololu Micro SD Card Module. Other SD cards may have different wiring and code.
3.
• Download the applicable arduino sketch from GitHub and open it. • Esp32_SoilMoisture
njmcdirect

Who is online

Users browsing this forum: No registered users and 104 guests