Introduction to Arduino Basics (Let the LED light up)

LED lights are the most common Arduino module. Today we talk about how to use arduino to control external LED lights.
1. Introduction to LED
Light Light Emitting Diode (LED for short) is a component that converts electrical energy into light energy. LED is a polar component. Among the two leads, the longer lead is the anode and the shorter lead is the cathode. There is a notch at the bottom of the LED cap, and the side of the notch also represents the cathode of the LED. Different LEDs have different working parameters. Generally, the rated working voltage of an LED with a diameter of 5mm is between 1.7V and 2.2V.
Insert picture description here

2. Light up the LED
1. Required devices:
1 LED lamp 1
220Ω resistor 1
Dupont line
2. Breadboard view: Insert picture description here
3. Setting instructions:
The positive connection resistance of the LED is connected to the digital pin 9 of the control board, and the negative connection is connected to the control The GND pin of the board.
4. Mixly program:
Insert picture description here
5. Program writing:
int LED=9; //Define the led pin as a digital pin 9
void setup()
{ pinMode(LED,OUTPUT); } void loop() { //Set the pin Is high, light up the LED digitalWrite(LED, HIGH); }







6. Program description:
Upload the program to the UNO board, the LED light will light up.
3. LED lights flashing
1. Required components:
1 LED light 1
220Ω resistor 1
Dupont line
2. Breadboard view: Insert picture description here
3. Setting instructions:
The positive pole of the LED is connected to the digital pin 9 of the control board, and the negative pole is connected to the control The GND pin of the board.
4. Mixly program:
Insert picture description here

	5、程序编写:
			int  LED=9;     //定义led引脚为数字引脚9
			void setup()
			 {
			  pinMode(LED,OUTPUT);
				}				
			void loop() 
			{
				//设置该引脚为高电平,点亮LED
			  digitalWrite(LED,HIGH);      
			  delay(1000);                  //延迟1000毫秒
			  digitalWrite(LED,LOW);
			  delay(1000);                  //延迟1000毫秒
				}
	6、程序说明:
	将程序上传到UNO板,LED灯就会闪烁起来。

4. Analog traffic lights
1. Required components:
3 LED lights (one each for red, yellow, and blue)
3 220Ω resistors
Several Dupont wires
2. Breadboard view:
Insert picture description here
3. Installation instructions: the
green light positive is connected to the resistor, and the digital pin is connected 9. Connect the negative pole to GND.
The positive pole of the yellow light is connected to the resistor, connected to digital pin 8, and the negative pole is connected to GND.
The positive pole of the red light is connected to the resistor, connected to digital pin 7, and the negative pole is connected to GND.
4. Mixly program: Insert picture description here
5. Program writing:
int red=7; //define the red light pin as a digital pin 7
int yellow=8; //define the yellow light pin as a digital pin 8
int green=9; / /Define the blue light pin as a digital pin 9
void setup() { pinMode(red,OUTPUT); //Set this pin to output mode pinMode(yellow,OUTPUT); //Set this pin to output mode pinMode( green,OUTPUT); //Set this pin to output mode } void loop() { digitalWrite(green,HIGH); //Set this pin to high level and turn on the green light delay(5000); //Delay 5000 Millisecond digitalWrite(green,LOW); //Turn off the green light digitalWrite(yellow,HIGH); //Set this pin to high level and light up the yellow light









delay(500); //Delay 500 milliseconds
digitalWrite(yellow,LOW); //Turn off the yellow light
delay(100); //Delay 100 milliseconds
digitalWrite(yellow,HIGH); //Set this pin to high level, Turn on the yellow light
delay(500); //Delay 500 milliseconds
digitalWrite(yellow,LOW); //Turn off the yellow light
delay(100); //Delay 100 milliseconds
digitalWrite(yellow,HIGH); //Set this pin to High level, turn on the yellow light
delay(500); //Delay 500 milliseconds
digitalWrite(yellow,LOW); //Turn off the yellow light
digitalWrite(red,HIGH); //Set the pin to high level, light up Red light
delay(5000); //delay 5000 milliseconds
digitalWrite(red,LOW); //turn off the red light
}
6. Program description:
upload the program to the UNO board, the LED light will appear green light for 5 seconds, yellow light Flashes 3 times at 0.5 second intervals, and then the red light is on for 5 seconds.

Guess you like

Origin blog.csdn.net/lhwanglei/article/details/108569051