LEDs
https://www.circuitbasics.com/arduino-7-segment-display-tutorial/
Last updated
https://www.circuitbasics.com/arduino-7-segment-display-tutorial/
Last updated
A single LED consists of two terminals, an anode and a cathode. The anode is the positive terminal and the cathode is the negative terminal:
To power the LED, you connect the cathode to ground and the anode to the voltage supply. The LED can be turned on or off by switching power at the anode or the cathode.
With the LED’s anode connected to a digital pin, the cathode is connected to ground:
All LEDs need a current limiting resistor placed on either the anode side or cathode side to prevent the LED from burning out. The resistor value will determine how bright the LED shines. 1K ohms is a good place to start, but you can calculate the ideal value with an LED resistor calculator.
To light up an LED with the anode connected to a digital pin, you set the digital pin to HIGH:
In the void setup()
block, we configure GPIO pin 7 as an output with pinMode(7, OUTPUT)
; and drive it high with digitalWrite(7, HIGH);
.
With an LED’s cathode connected to a digital pin, the anode is connected to Vcc. To turn on the LED, the digital pin is switched LOW, which completes the circuit to ground:
In this case we drive GPIO pin 7 LOW with digitalWrite(7, LOW)
;. This closes the circuit and allows current to flow from Vcc to ground: