Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create an LED Dimmer Using Arduino

Creating an LED dimmer using Arduino is a practical project that introduces you to the concepts of pulse-width modulation (PWM) and analog input. This project allows you to control the brightness of an LED using a potentiometer. The Arduino board reads the analog input from the potentiometer and adjusts the PWM signal sent to the LED, effectively dimming or brightening it.

Components Required:

  1. Arduino Uno (or any compatible Arduino board)
  2. LED
  3. 220-ohm resistor
  4. Potentiometer (10k ohm recommended)
  5. Breadboard
  6. Jumper wires

Circuit Setup:

  1. Connect the LED in series with the 220-ohm resistor. Connect the anode (longer lead) of the LED to one end of the resistor.
  2. Connect the other end of the resistor to digital pin 9 on the Arduino.
  3. Connect the cathode (shorter lead) of the LED to the ground (GND) on the Arduino.
  4. Connect the middle pin of the potentiometer to analog pin A0 on the Arduino.
  5. Connect one of the outer pins of the potentiometer to 5V on the Arduino and the other outer pin to GND.

Arduino Code Example:

const int ledPin = 9;     // Pin connected to the LED
const int potPin = A0;    // Pin connected to the potentiometer

void setup() {
  pinMode(ledPin, OUTPUT);  // Set the LED pin as an output
}

void loop() {
  int potValue = analogRead(potPin);  // Read the potentiometer value
  int pwmValue = map(potValue, 0, 1023, 0, 255);  // Map the value to a range of 0-255
  analogWrite(ledPin, pwmValue);  // Write the PWM value to the LED pin
  delay(10);  // Small delay for stability
}

Explanation:

  • analogRead(potPin): This function reads the voltage level from the potentiometer, which ranges from 0 to 1023.
  • map(): This function maps the potentiometer value from its range (0-1023) to the PWM range (0-255) suitable for the analogWrite() function.
  • analogWrite(ledPin, pwmValue): This function writes the PWM signal to the LED pin, controlling the brightness of the LED.

Running the Code:

  1. Connect your Arduino to your computer using a USB cable.
  2. Open the Arduino IDE and paste the provided code into a new sketch.
  3. Select the correct board and port from the Tools menu.
  4. Upload the code to the Arduino.
  5. Turn the potentiometer to see the LED brighten and dim.

This project demonstrates how to use a potentiometer to control an LED's brightness via PWM, a fundamental concept in electronics and Arduino programming.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.