PWM LED Brightness Control

Share on facebook
Share on google
Share on twitter
Share on linkedin
A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

Pulse Width Modulation at last! In our last example, we read a potentiometer (pot) to get a analog value of 0-1023, and used that number to delay the digital on and off times of a LED. This example will do the same read, but output a analog value (PWM) of 0-255 to control the brightness of a LED. It’s still controlling the on and off times, but so quickly the eye doesn’t see off, it just sees decreased or increased brightness. this is much more power efficient than using a resistor to shed voltage, dimming a bulb. We will use this same method in an upcoming post to control the speed of a motor.

(video uploaded to youtube)

int sensorPin = A0;    // Analog input pin to pot
int ledPin = 7; // PWM pin to LED
int sensorValue = 0; // variable to store pot value

void setup() {}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // converts 0-1023 to 0-255
  sensorValue /=4;   
  // outputs PWM signal to LED
  analogWrite(ledPin, sensorValue);

Steve Spence

Steve Spence

Leave a Reply

Leave a Comment

Your email address will not be published. Required fields are marked *