ESP32 C3 Super Mini - Potentiometer LED

This tutorial shows you how to use the ESP32 C3 Super Mini with a potentiometer to change the brightness of an LED. Turn the knob and the LED fades up or down. It is a simple, fun project for beginners.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - Potentiometer LED

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Potentiometer
1×Alternatively, 10k Ohm Trimmer Potentiometer
1×Alternatively, Potentiometer Kit
1×Alternatively, Potentiometer Module with Knob
1×LED Kit
1×LED (red)
1×LED Module
1×Alternatively, Button and LED Kit
1×220Ω Resistor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

Overview of LED and Potentiometer

A potentiometer is a knob that gives a changing voltage, and an LED is a small light whose brightness you can control.

Key Features:

  • Potentiometer: Outputs a smooth voltage from 0V up to VCC as you turn it.
  • LED: Fades smoothly with a PWM signal.
  • Together: The knob sets the value, and the board turns that value into brightness.

Technical Specifications:

  • Analog input range: 0V to 3.3V, read as 0 to 4095 (12-bit)
  • PWM brightness range: 0 (OFF) to 255 (brightest)
  • LED resistor: 220 ohm

Each part has its own tutorial with the pinout, how it works, wiring and code:

Pinout

Here are the pins you will connect in this project.

  • Potentiometer VCC: connect to 3.3V
  • Potentiometer GND: connect to GND (0V)
  • Potentiometer Output: gives the voltage to the analog input pin
  • LED Anode (+): the longer leg, controlled by the PWM pin through the resistor
  • LED Cathode (-): the shorter leg, connects to GND

Wiring Diagram

The potentiometer uses three wires, and the LED uses two wires plus a resistor.

  • Note: Power the potentiometer from 3.3V, never from 5V. The GPIO pins are 3.3V only.
  • Note: The potentiometer output goes to GPIO4, because analog input works only on GPIO0 to GPIO4.
  • Note: Always use the 220 ohm resistor with the LED, or the LED can burn out.
Component Pin ESP32 C3 Super Mini Pin
Potentiometer VCC 3.3V
Potentiometer GND GND
Potentiometer Output GPIO4
LED Anode (+) GPIO3 (through 220 ohm resistor)
LED Cathode (-) GND
The wiring diagram between ESP32 C3 Super Mini Rotary Potentiometer LED

This image is created using Fritzing. Click to enlarge image

Here is the same wiring without a breadboard:

The wiring diagram between ESP32 C3 Super Mini Rotary Potentiometer LED  (No Breadboard)

This image is created using Fritzing. Click to enlarge image

How To Program

The program does three small jobs, over and over.

  • Read: reads the input on the analog pin (value between 0 and 4095)
int analogValue = analogRead(4); // GPIO4
  • Scale: scales it to brightness (value between 0 and 255)
int brightness = map(analogValue, 0, 4095, 0, 255);
  • Set: sets the brightness of the LED
analogWrite(LED_PIN, brightness);

ESP32 C3 Super Mini Code

The code below lets the potentiometer on GPIO4 control the LED on GPIO3.

What This Code Does:

  • Starts Serial: opens the Serial Monitor at 115200 baud.
  • Sets the ADC: analogSetAttenuation(ADC_11db) lets the pin read the full 0V to 3.3V range.
  • Reads the knob: analogRead() gives a number from 0 to 4095.
  • Changes the LED: map() turns that number into 0 to 255, and analogWrite() sets the brightness.
  • Prints the values: shows the reading and the brightness every 100 ms.
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-potentiometer-led */ #define POTENTIOMETER_PIN 4 // The ESP32 C3 SuperMini pin connected to Potentiometer pin #define LED_PIN 3 // The ESP32 C3 SuperMini pin connected to LED's pin // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 115200 bits per second: Serial.begin(115200); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); // declare LED pin to be an output: pinMode(LED_PIN, OUTPUT); } // the loop routine runs over and over again forever: void loop() { // reads the input on analog pin GPIO4 (value between 0 and 4095) int analogValue = analogRead(POTENTIOMETER_PIN); // scales it to brightness (value between 0 and 255) int brightness = map(analogValue, 0, 4095, 0, 255); // sets the brightness LED that connects to pin GPIO3 analogWrite(LED_PIN, brightness); // print out the value Serial.print("Analog value = "); Serial.print(analogValue); Serial.print(" => brightness = "); Serial.println(brightness); delay(100); }

Detailed Instructions

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Wire it up: Connect the potentiometer and the LED as shown above.
  • Connect the board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open the IDE: Copy the code above and paste it into Arduino IDE.
  • Select the board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Select the port: Pick the COM port of your board in Tools > Port.
  • Upload: Click the Upload button on Arduino IDE.
  • Open Serial Monitor: Open it on Arduino IDE and set the baud rate to 115200.
How to open serial monitor on Arduino IDE
  • Turn the knob: Rotate the potentiometer slowly.
  • Watch the LED: See the LED fading as you turn.
  • Check the result: See the values on the Serial Monitor. It looks like the below:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
Analog value = 6 => brightness = 0 Analog value = 128 => brightness = 7 Analog value = 642 => brightness = 39 Analog value = 1024 => brightness = 63 Analog value = 1487 => brightness = 92 Analog value = 2059 => brightness = 128 Analog value = 2730 => brightness = 170 Analog value = 3310 => brightness = 206 Analog value = 3891 => brightness = 242 Analog value = 4095 => brightness = 255
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: If the LED does not light up at all, turn the LED around. The longer leg must go to the resistor side, toward GPIO3.

Project Ideas

This same idea can control many real things.

  • Desk Lamp Dimmer: Set the brightness of a small lamp with a knob.
  • Night Light: Keep the LED at a soft level before going to sleep.
  • Display Backlight Knob: Change how bright a small screen looks.
  • Fan Speed Dial: Use the same code to set the speed of a small fan through a driver.
  • Mood Light: Use three knobs to mix the colors of an RGB LED.

Challenge Yourself

Try these small upgrades to learn more about the ESP32 C3 Super Mini.

  • Easy: Reverse the direction, so turning the knob up makes the LED dimmer.
  • Easy: Print the brightness as a percentage from 0% to 100%.
  • Medium: Start from a soft night-light level, so the LED never turns fully OFF.
  • Medium: Average 10 readings to stop the LED from flickering.
  • Advanced: Add a second LED on GPIO5 that fades in the opposite direction.
  • Advanced: Add a second potentiometer on GPIO2 to control the second LED.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!