SunFounder ESP32 Starter Kit
• Open the 5.9_moisture.py file located in the esp32-starter-kit-main\micropython\codes path, or
copy and paste the code into Thonny. Then, click “Run Current Script” or press F5 to execute it.
• Make sure to select the “MicroPython (ESP32).COMxx” interpreter in the bottom right corner.
from machine import ADC,Pin
import time
# create an ADC object acting on a pin
moisture = ADC(Pin(35, Pin.IN))
# Configure the ADC attenuation to 11dB for full range
moisture.atten(moisture.ATTN_11DB)
while True:
# read a raw analog value in the range 0-4095
value = moisture.read()
print(value)
time.sleep(0.05)
When the script runs, you will see the soil moisture value in the Shell.
By inserting the module into the soil and watering it, the value of the soil moisture sensor will become smaller.
3.28 5.10 Temperature Sensing
A thermistor is a temperature sensor that exhibits a strong dependence on temperature, and it can be classified into two
types: Negative Temperature Coefficient (NTC) and Positive Temperature Coefficient (PTC). The resistance of an NTC
thermistor decreases with increasing temperature, while the resistance of a PTC thermistor increases with increasing
temperature.
In this project, we will be using an NTC thermistor. By connecting the NTC thermistor to an analog input pin of the
ESP32 microcontroller, we can measure its resistance, which is directly proportional to the temperature.
By incorporating the NTC thermistor and performing the necessary calculations, we can accurately measure the temper-
ature and display it on the I2C LCD1602 module. This project enables real-time temperature monitoring and provides
a visual interface for temperature display.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name ITEMS IN THIS KIT LINK
ESP32 Starter Kit 320+
You can also buy them separately from the links below.
3.28. 5.10 Temperature Sensing 387