• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Circuit Ideas for You

Get free circuit ideas online.

  • Home
  • Privacy Policy
  • About
Home » Simple Arduino LED Dimmer Circuit using PWM

Simple Arduino LED Dimmer Circuit using PWM

Last updated on 21 August 2024 by Admin-Lavi Leave a Comment

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);
}
  • The Arduino pins linked to the LED and the two push buttons are identified by the constants LED_PIN, BUTTON1_PIN and BUTTON2_PIN.
  • Brightness in the LEDs current brightness level is stored in this variable.
  • setup() function sets the button pins as inputs with built -in pull-up resistors and the LED pin as an output.
  • loop() method keeps an eye on the push buttons conditions all the time.
  • The brightness increases when BUTTON1 is pressed and decreases when BUTTON2 is pressed.
  • The PWM duty cycle on the LED pin is set using the analog Write() method, which regulates the LEDs brightness.

Circuit Working:

Simple Arduino LED Dimmer Circuit Diagram using PWM

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:

  • Gather all the components mentioned in the above circuit diagram.
  • Connect a regulated IC1 7809 to provide a regulated 9V DC  to the Arduino board
  • Connect capacitor 100μF positive side between resistor 220Ω and red LED and negative side to the GND.
  • Connect 220Ω resistor and Red LED in series from pin 9 on the Arduino board and cathode of LED to ground.
  • Connect Tactile switch button1 one leg from pin 2 on the Arduino board and other leg to ground.
  • Connect Tactile switch button2 one leg from pin 3 on the Arduino board and other leg to ground.
  • Connect one 10k resistor between pin 2 and positive 5V on Arduino board.
  • Connect other 10k resistor between pin 3 and positive 5V on Arduino board.

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

Filed Under: Arduino Projects, LED and Lamps

About Admin-Lavi

Lavi is a B.Tech electronics engineer with a passion for designing new electronic circuits. Do you have questions regarding the circuit diagrams presented on this blog? Feel free to comment and solve your queries with quick replies

Previous Post: « Arduino Temperature Controller Circuit using DC Fan
Next Post: Simple Servo Motor Controller Circuit using Arduino »

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

Categories

  • Alarm Circuits (30)
  • Amplifier Circuits (67)
  • Arduino Projects (29)
  • Audio Circuits (93)
  • Automobile Circuits (19)
  • Battery Charger Circuits (48)
  • Free Energy (13)
  • Heater and Temperature Controllers (9)
  • Indicator Circuits (38)
  • Inverter Circuits (13)
  • LDR Circuits (13)
  • LED and Lamps (111)
  • Meters and Testers (27)
  • Motor Controllers (18)
  • Oscillator Circuits (32)
  • Power Supply Circuits (91)
  • Remote Control Circuits (6)
  • Security and Protection (23)
  • Sensors and Detectors (71)
  • Solar Circuits (16)
  • Timer Circuits (27)
  • Transistor Circuits (56)
  • Transmitter Circuit (12)
  • Tutorials (4)
  • Water Level Controller (4)

Copyright © 2025 | New Circuit Ideas