🛠 Allumer une LED externe en respectant les broches 3,3 V et 9 mA de la Due
Objectives
Move away from all-in-one setups: wire an external LED to a Due pin by correctly calculating the resistor. On a 5 V board, you can take "220 Ω with your eyes closed"; on the Due, the logic is at 3.3 V AND the current per pin is much lower than on AVR chips: 9 mA for group 1, 3 mA for group 2, and 130 mA total across all I/O pins. This tutorial establishes good electrical practices.
Hardware
- 1 Arduino Due
- 1 red LED (Vf ≈ 2 V) or green/blue LED (Vf ≈ 2.1–3.2 V)
- 1 resistor from 100 Ω to 220 Ω
- 2 male-to-male wires, micro-USB cable
Complete code
// LED externe sur la broche 9 (groupe 1 : 9 mA max par broche)
const uint8_t LEDX = 9;
void setup {
pinMode(LEDX, OUTPUT);
}
void loop {
digitalWrite(LEDX, HIGH); // 3,3 V sur la broche -> LED allumée
delay(300);
digitalWrite(LEDX, LOW); // 0 V -> LED éteinte
delay(300);
}
Resistor calculation: R = (Vpin − Vf) / I. For a red LED at 3.3 V: (3.3 − 2.0) / 0.010 A ≈ 130 Ω → use 150 Ω, the LED will see ~9 mA and the pin will stay within its 9 mA limit. With 220 Ω it is even more conservative and perfectly visible.
Expected verification
The LED blinks every 300 ms. If you disconnect the resistor, the LED shines brighter, but you are injecting uncontrolled current: never leave it in this state. The program runs autonomously on 7–12 V jack power, with USB disconnected.
Common errors
- Forgetting the resistor: on a 3.3 V output, the current quickly exceeds the 9 mA (group 1) or 3 mA (group 2) limits from the official datasheet; unlike an AVR pin rated for 20–40 mA, the Due suffers damage faster, and the total budget of 130 mA across all pins limits the number of LEDs.
- Connecting a pin to a 5 V circuit (a sensor or shield designed for Uno): risk of destruction — the Due is NOT 5 V tolerant, you need a level shifter.
- LED inserted backwards (anode/cathode reversed): nothing lights up, no damage; swap the legs.
- Relying on the 3V3 pin to power a power-hungry module: it is designed for logic, not for actuators; beyond a few tens of mA, use an external power supply.
- Driving a relay or motor directly: you need a transistor/MOSFET with a separate power supply and a flyback diode.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino Due et apprivoiser ses deux ports USB
- Lire un potentiomètre avec le vrai ADC 12 bits de la Due
- Générer une vraie tension analogique avec les DAC 12 bits (broches 66 et 67)
- Dialoguer avec un GPS (ou tout module TTL) sur Serial1 sans bloquer la boucle
- Scanner les deux bus I2C de la Due (Wire sur 20/21, Wire1 sur 70/71)
- Monter la Due sur un bus CAN 500 kbit/s avec un transceiver externe
Code examples for this board
clignotante.inoArduinobouton-led.inoArduinodac-onde.inoArduinoadc-12-bits.inoArduinopwm-12-bits.inoArduinogps-serial1.inoArduino