Site icon Circuit Ideas for You

Simple Arduino LED Dimmer Circuit using PWM

This post shows how to use Pulse Width Modulation PWM on an Arduino microcontroller to regulate the brightness of an LED.

PWM is a technology that successfully controls the average output voltage by varying the square waves duty cycle.

We can alter the brightness of the LED by varying the duty cycle, which modifies the amount of power sent to the light source.

Coding with Explanation:

#define LED_PIN 9
#define BUTTON1_PIN 2
#define BUTTON2_PIN 3

int brightness = 0;

void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUTTON1_PIN, INPUT_PULLUP);
  pinMode(BUTTON2_PIN, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(BUTTON1_PIN) == LOW)   
 {
    brightness++;
    if (brightness > 255) {
      brightness = 255;
    }
  }

  if (digitalRead(BUTTON2_PIN) == LOW) {
    brightness--;
    if (brightness < 0) {
      brightness = 0;
    }
  }

  analogWrite(LED_PIN, brightness);
  delay(10);
}

Circuit Working:

Parts List:

ComponentQuantity
Arduino Uno board1
LED 5mm 20mA (any color)1
100µF 25V capacitor1
220Ω resistor1
10k resistor2
Tactile switches2

The LED should be connected correctly, as per the above the circuit diagram.

The push buttons might not be stable, but it wont pass any errors.

It is easy to use PWM on Arduino setting up PWM on ATMEGA is harder, as you need to adjust many settings.

Arduino already has these settings ready, so you can use PWM easily by calling the right functions.

On the LED pin, the Arduino microcontroller produces a square wave signal.

The resistors and capacitor filter the square wave to create a DC voltage.

The average DC voltage, which in turn regulates the LEDs brightness, is found in the duty cycle of the square wave.

The LED brightness may be adjusted by increasing or decreasing the duty cycle using the push buttons.

When we press button1 the LED illumination increases and when button 2 is pressed the LED illumination decreases

How to Build:

To build a Simple Arduino LED Dimmer Circuit using PWM follow the below mentioned steps:

Conclusion:

This article shows how to use PWM on an Arduino to regulate an LEDs brightness in a simple yet efficient manner.

You may develop a variety of lighting control applications by comprehending the PWM concepts and the code implementation.

References:

Dimmer PWM Led using Arduino Nano Every

Exit mobile version