Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO PWM LED Dimmer

View and Edit Project In Cirkit DesignerImage of Arduino UNO PWM LED Dimmer

Circuit Documentation

Summary of the Circuit

This circuit consists of an Arduino UNO microcontroller, a red two-pin LED, and a resistor. The purpose of the circuit is to control the brightness of the LED using Pulse Width Modulation (PWM) provided by the Arduino UNO. The LED's brightness is varied in a fading pattern, which is achieved by incrementally changing the PWM value on a digital pin of the Arduino.

Component List

Arduino UNO

LED: Two Pin (red)

Resistor

Wiring Details

Arduino UNO

LED: Two Pin (red)

Resistor

Documented Code

// Code for Arduino UNO
// Filename: sketch.ino

int led = 9;         // the PWM pin the LED is attached to
int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

This code is designed to run on the Arduino UNO microcontroller. It initializes pin 9 as an output and uses it to control the brightness of the connected LED through PWM. The brightness variable is altered on each iteration of the loop function, causing the LED to fade in and out. The fadeAmount determines the rate of fading, and the direction of the fade is reversed when the brightness reaches its minimum or maximum value.