Skip to content

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.

Notifications You must be signed in to change notification settings

asathiskumar98-byte/ESP8266-Variable-Resistor-Controlled-LED-Brightness-MicroPython

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages