Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

Lesson 13: Potentiometer Module

In this lesson, you’ll learn how to read the analog value of a potentiometer with the ESP32 development board. We’ll connect a potentiometer module to pin 25 and observe the changing analog values (0-4095) in the serial monitor. This project provides hands-on experience in understanding analog inputs and serial communication, making it an excellent exercise for beginners to explore the capabilities of the ESP32 board.

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

Universal Maker Sensor Kit

94

Universal Maker Sensor Kit

You can also buy them separately from the links below.

Component Introduction

Purchase Link

ESP32 & Development Board (ESP32 Board)

BUY

Potentiometer Module

BUY

Breadboard

BUY

Wiring

../_images/Lesson_13_Potentiometer_Module_esp32_bb.png

Code

Code Analysis

  1. This line of code defines the pin number to which the potentiometer is connected on the ESP32 Development Board.

    const int sensorPin = 25;
    
  2. The setup() function is a special function in Arduino that is executed only once when the ESP32 Development Board is powered on or reset. In this project, the Serial.begin(9600) command initiates serial communication at a baud rate of 9600.

    void setup() {
      Serial.begin(9600);
    }
    
  3. The loop() function is the main function where the program runs repeatedly. In this function, the analogRead() function reads the analog value from the potentiometer and prints it to the serial monitor using Serial.println(). The delay(50) command makes the program wait for 50 milliseconds before taking the next reading.

    void loop() {
      Serial.println(analogRead(sensorPin));
      delay(50);
    }