In this project, we’ll look at how to light a LED without programming and with programming. In both examples you’ll need a resistor to limit the current in your LED.
We’ll use a 220 ohm resistor, which is suitable if your LED is connected to 3.3V or 5V.
Which way to connect the LED?
The LED can’t be connected in either direction: The longest or curved pin, called the anode, must be connected to the + terminal on your Arduino board.
Conversely, the cathode, which is the right-hand or shorter pin, connects to the GND terminal on your Arduino board.
Turn on LED
Here we will see how to light a red LED without programming, by connecting it to the 5V or 3.3V pin of the Arduino board and to its ground:
Now let’s see how to program your LED, to make it blink for example. Here is the circuit image:
int LED=7; // the pin to which our LED is connected
void setup() {
pinMode(LED, OUTPUT); // Declare output led
}
void loop() {
digitalWrite(LED, HIGH); // The LED lights up
}