CIPAD_05. comment réaliser un Bargraphe à 10 LED

3 min read 4 hours ago
Published on Oct 01, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial will guide you through the process of creating a 10 LED bar graph using simple electronic components. You'll learn essential concepts like pull-down circuits and debouncing techniques, making this project suitable for beginners and those looking to enhance their electronics skills.

Step 1: Gather Your Materials

Before starting the project, ensure you have the following components:

  • 10 LEDs (different colors can be used for visual appeal)
  • 10 current-limiting resistors (typically 220 ohms)
  • 1 microcontroller (e.g., Arduino)
  • Breadboard
  • Jumper wires
  • Push button switch
  • Resistor for pull-down (10k ohm is common)
  • Power supply (USB or battery)

Tip: Organize your workspace to avoid losing small components.

Step 2: Set Up the Circuit

  1. Place the LEDs on the breadboard in a vertical line.
  2. Connect the current-limiting resistors to the cathodes (shorter leg) of each LED.
  3. Connect the anodes (longer leg) of each LED to digital pins on the microcontroller. For example, use pins 2 to 11.
  4. Connect the other end of each resistor to the ground rail on the breadboard.
  5. Add the push button switch:
    • Connect one terminal to a digital input pin on the microcontroller (e.g., pin 12).
    • Connect the other terminal to the ground.
    • Use a pull-down resistor (10k ohm) connected between the input pin and ground.

Common Pitfall: Ensure you connect the LEDs with the correct polarity to avoid damaging them.

Step 3: Write the Code

Create a simple code to control the LEDs based on the button press. Below is a basic example:

const int buttonPin = 12; // Pin connected to the button
const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Pins connected to LEDs
int ledCount = sizeof(ledPins) / sizeof(ledPins[0]);

void setup() {
    pinMode(buttonPin, INPUT);
    for (int i = 0; i < ledCount; i++) {
        pinMode(ledPins[i], OUTPUT);
    }
}

void loop() {
    if (digitalRead(buttonPin) == HIGH) {
        for (int i = 0; i < ledCount; i++) {
            digitalWrite(ledPins[i], HIGH);
            delay(100); // Delay to see the LED turn on
            digitalWrite(ledPins[i], LOW);
        }
    }
}

Tip: Adjust the delay to control the speed of the LED sequence.

Step 4: Test Your Circuit

  1. Connect your microcontroller to your computer or power supply.
  2. Upload the code you wrote using the Arduino IDE.
  3. Press the button to see the LEDs light up in sequence.

Troubleshooting: If the LEDs do not light up, check your connections and ensure your code uploaded correctly.

Conclusion

You have successfully created a 10 LED bar graph! This project introduced you to basic electronics concepts and practical coding. For next steps, consider experimenting with different patterns or integrating sensors for more interactive projects. Happy tinkering!