CIPAD_04. Gradateur pour ampoule, LED-vitesse d'un moteur CC, led tricolores à 16Millions de couleur
Table of Contents
Introduction
This tutorial will guide you through programming an Arduino to control the brightness of a 5-volt bulb, manage the speed of a 5-volt DC motor, and create over 16 million colors with a tricolor LED. By following these steps, you'll gain hands-on experience with Arduino programming and electronics, making it ideal for beginners and hobbyists alike.
Step 1: Setting Up Your Arduino Environment
- Gather Materials: You will need the following components:
- Arduino board (e.g., Arduino Uno)
- 5-volt bulb
- 5-volt DC motor
- Tricolor LED
- Resistors (as required)
- Breadboard and jumper wires
- Install Arduino IDE: Download and install the Arduino Integrated Development Environment (IDE) from the official Arduino website. This software will allow you to write and upload code to your Arduino board.
Step 2: Wiring the Circuit
-
Connect the Bulb:
- Use a transistor to control the bulb's brightness.
- Connect the positive terminal of the bulb to the power source.
- Connect the negative terminal to the collector of the transistor.
- Connect the emitter of the transistor to ground.
- Connect the base of the transistor to a PWM-capable pin on the Arduino (e.g., pin 9).
-
Connect the DC Motor:
- Connect one terminal of the motor to the power source and the other to a different transistor.
- Follow the same process as with the bulb for connecting the transistor.
- Use a PWM-capable pin (e.g., pin 10) to control the motor speed.
-
Connect the Tricolor LED:
- Identify the anode and cathodes of the LED.
- Connect the anode to a positive power source through a resistor.
- Connect each cathode to separate PWM-capable pins (e.g., pin 11 and pin 12) on the Arduino.
Step 3: Writing the Arduino Code
-
Start with the Basics: Open the Arduino IDE and create a new sketch.
-
Define Pin Numbers: At the top of your sketch, define the pin numbers for the bulb, motor, and LED:
const int bulbPin = 9; const int motorPin = 10; const int redPin = 11; const int greenPin = 12; const int bluePin = 13;
-
Setup Function: In the
setup()
function, initialize the pins as OUTPUT:void setup() { pinMode(bulbPin, OUTPUT); pinMode(motorPin, OUTPUT); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); }
-
Loop Function: In the
loop()
function, add code to control brightness, motor speed, and LED colors:void loop() { // Control bulb brightness for (int brightness = 0; brightness <= 255; brightness++) { analogWrite(bulbPin, brightness); delay(10); } for (int brightness = 255; brightness >= 0; brightness--) { analogWrite(bulbPin, brightness); delay(10); } // Control motor speed for (int speed = 0; speed <= 255; speed++) { analogWrite(motorPin, speed); delay(10); } for (int speed = 255; speed >= 0; speed--) { analogWrite(motorPin, speed); delay(10); } // Create colors for the LED for (int i = 0; i < 256; i++) { analogWrite(redPin, i); analogWrite(greenPin, 255 - i); delay(10); } }
Conclusion
In this tutorial, you learned how to set up an Arduino to control the brightness of a bulb, the speed of a DC motor, and produce a variety of colors with a tricolor LED. By experimenting with the provided code and wiring, you can further customize your projects. Next steps could include integrating sensors for more interactive controls or exploring additional Arduino libraries for advanced functionalities. Happy tinkering!