2. Configure the system in the setup() function.
void
setup() {
Serial.begin(115200);
// Configure PWM
ledcSetup(channel, freq, resolution);
ledcAttachPin(ledPin, channel);
}
• In the setup() function, the Serial communication is started at a baud rate of 115200.
• The ledcSetup() function is called to set up the PWM channel with the specified frequency
and resolution, and the ledcAttachPin() function is called to associate the specified LED pin
with the PWM channel.
3. Main loop (executed repeatedly) in the loop() function.
void
loop() {
int
potValue
potentiometer
uint32_t
in millivolts
ledcWrite(channel, potValue);
Serial.print("Potentiometer Value:
Serial.print(potValue);
Serial.print(", Voltage:
Serial.print(voltage_mV
Serial.println("
delay(100);
}
• uint32_t analogReadMilliVolts(uint8_t pin);: This function is used to get ADC value
for a given pin/ADC channel in millivolts.
– pin GPIO pin to read analog value.
The potentiometer value is directly used as the PWM duty cycle for controlling the LED brightness
via the ledcWrite() function, as the range of values is also from 0 to 4095.
1.25 5.9 Measure Soil Moisture
This capacitive soil moisture sensor is different from most of the resistive sensors on the market, using the principle of
capacitive induction to detect soil moisture.
By visually reading the values from the soil moisture sensor, we can gather information about the moisture level in the
soil. This information is useful for various applications, such as automatic irrigation systems, plant health monitoring,
or environmental sensing projects.
Required Components
In this project, we need the following components.
1.25. 5.9 Measure Soil Moisture
=
analogRead(potPin);
voltage_mV
=
analogReadMilliVolts(potPin);
");
/
1000.0);
V");
SunFounder ESP32 Starter Kit
// read the value of
// Read the
");
// Convert millivolts to volts
the␣
voltage␣
89
Need help?
Do you have a question about the ESP32 and is the answer not in the manual?