Skip to content

About

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.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

💡 ESP8266 Variable Resistor Controlled LED Brightness — MicroPython

🧠 Overview

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.


⚙️ Hardware Setup

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

🧩 Code

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)

About

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.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages