
As shown in the schematic diagram above, the anode of LED is connected to
Arduino’s GPIO via a resistor, and the cathode of LED is connected to the
ground(GND). When the GPIO output high level, the LED is on; when the GPIO
output low level, the LED is off.
The size of the current-limiting resistor is calculated as follows: 5~20mA
current is required to make an LED on, and the out put voltage of the Arduino
UNO’s GPIO is 5V, so we can get the resistance:
R = U / I = 5V / (5~20mA) = 250Ω~1KΩ
Since the LED has a certain resistance, thus we choose a 220ohm resistor.
②
As shown in the schematic diagram above, the anode of LED is connected to
VCC(+5V), and the cathode of LED is connected to the Arduino’s GPIO. When
the GPIO output low level, the LED is on; when the GPIO output high level, the
LED is off.
The experiment is based on method ①, we select Arduino's D8 pin to control
the LED. When the Arduino’s D8 pin is programmed to output high level, then
the LED will be on, next delay for the amount of time, and then programmed
the D8 pin to low level to make the LED off. Continue to perform the above
process, you can get a blinking LED.
3. Key functions:
●setup()
The setup() function is called when a sketch starts. Use it to initialize variables,
pin modes, start using libraries, etc. The setup function will only run once,
after each powerup or reset of the Arduino board.
●loop()
After creating a setup() function, which initializes and sets the initial values,
the loop() function does precisely what its name suggests, and loops