This project demonstrates how to control the brightness of an LED using a variable resistor (potentiometer) connected to the ADC pin of the ESP8266 board.
The analog voltage from the potentiometer is read and converted into a PWM (Pulse Width Modulation) duty cycle to adjust the LED brightness smoothly.
| Component | ESP8266 Pin | Description | 
|---|---|---|
| LED | GPIO2 | Output pin with PWM control | 
| Variable Resistor | A0 | Analog input (0β1V range) | 
| Power (VCC) | 3.3V | Potentiometer VCC | 
| Ground (GND) | GND | Common ground | 
πͺ Connect:
- Potentiometer middle pin β A0
 - One side β 3.3V
 - Other side β GND
 - LED (with 220Ξ© resistor) β GPIO2
 
import machine
from machine import ADC
import utime
# A0 = Variable resistor middle pin (Sensor Output)
# ADC 10-bit resolution = 0β1024
led = machine.Pin(2, machine.Pin.OUT)
pwm = machine.PWM(led)
variable_resistor = machine.ADC(0)
while True:
    adc_value = variable_resistor.read()
    pwm.duty(adc_value)
    print('step_value:', adc_value)
    utime.sleep_ms(200)