LEDs
https://www.circuitbasics.com/arduino-7-segment-display-tutorial/
LED Basics
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.
Anode to GPIO
With the LED’s anode connected to a digital pin, the cathode is connected to ground:

To light up an LED with the anode connected to a digital pin, you set the digital pin to HIGH:
void setup(){
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
}
void loop(){
}
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);
.
Cathode to GPIO
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:
void setup(){
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
}
void loop(){
}
Last updated
Was this helpful?