In the以前的教程,,,,we discussed the basics about Arduino sketches, with a a quickArduinolanguage reference. Now, it’s time to get our hands dirty. Interfacing LED and driving digital output from a source is the “Hello World” of embedded systems.
As discussed in the previous tutorial, a microcontroller interfaces and interacts with other electronic devices in five ways:
1。数字输出
2。Digital Input
3。模拟输出
4。Analog Input
5。连续交流。
In this tutorial, we’ll go into more detail about the first one of these methods: digital output. By driving digital output from Arduino UNO’s GPIO, we will build an LED driver.
发光二极管
发光二极管,,,,or LEDs, are semiconductor diodes that emit a narrow bandwidth of electromagnetic waves (either visible light, infrared light, or laser light) in forward bias condition. LEDs are similar to PN junction diodes. For example, when forward voltage is applied, a current will pass through LEDs. And, when reverse voltage is applied, the current will be blocked.
这些二极管由一层非常薄的半导体材料组成。就像PN连接二极管一样,这些是两端设备。P型半导体材料形成阳极,N型半导体材料形成阴极。
当应用正向偏置电压时(含义为阳极处的正势和二极管阴极的负电势)时,从N型半导体中退出了来自N型半导体的电子,并与P型半导体的孔结合 - 释放能量以单色光的形式。
由于LED中的半导体材料层非常薄,因此光子可以通过结,并产生可见或红外光线。因此,在正向偏置条件下,LED以光能的形式辐射电能。
在反向偏置条件下(当阳极处有负电势和二极管阴极的正势)时,P型半导体中的孔被吸引到负电位。同样,N型半导体中的电子被吸引到P型和N型半导体之间的正势扩大或耗尽区。结果,没有电流流过二极管,并从中散发出零光。
LEDs are constructed differently than typical signal diodes. The PN junction of an LED is enclosed in a transparent epoxy-resin hard-plastic shell, which can be hemispherical, cylindrical, or rectangular. However, the junction does not produce much light. Rather, the emitted light is reflected from the surrounding substrate base, such that when it leaves the diode it appears as a focused beam of monochromatic light. It’s the reason that light emitted from LED is brightest at the top of it.
As LEDs resemble a monochromatic type of light, they have an extremely low heat emission that manifolds their efficiency in comparison to non-semiconductor light sources. Typically, the cathode of LED is indicated by a notch in the shell and/or by shorter lead at the cathode terminal.
LED类型
LED可以通过它们发出的颜色来区分。与正常信号二极管不同的是掺杂锗或硅半导体制造的,LED是通过掺杂半导体化合物制成的,例如氨基苯甲酸盐(GAAS),碳化硅(SIC),磷酸盐(GAP),甘油(GAP),甘油(Gallium indium indium ninride)(Gallium gallium),甘油(GALN)(GANN)砷化磷化物(GAASP)和磷化铝(algap)。这些半导体化合物的不同比率可以产生不同的带宽光。
The main P-type dopant used in LEDs is Gallium (Ga) and the main N-type dopant used in LEDs is Arsenic (As).
Gallium Arsenide is the most common semiconductor material used for manufacturing LEDs. Gallium Arsenide produces infrared light, which has a wavelength of between 850 and 940 nm. It is compounded with other elements, such as Phosphorous, to reduce the resultant wavelength.
The actual monochromatic light produced from an LED depends on the choice and ratio of semiconductor compounds, and the level of their doping.
这是制造LED中一些更常用的半导体化合物。
The forward voltage required to light up the LED depends on its color and wavelength. The forward operating voltage typically ranges from 1.2 to 3.6 V, with a forward current from 12 to 30 mA.
LED特征
与信号二极管类似,LED也是电流控制的设备。这意味着它们的特性取决于输入电流。“更高”是流过它的电流,而“更大”是输出光的强度。但是,这并不意味着必须通过LED传递最大电流。
发光二极管有一层极薄的半导体material and an excessive current can easily damage or destroy it. So, LEDs typically need to be current-limited, which can be done by connecting a series resistor. However, an LED should绝不be connected directly across a battery or power source. They should also be current-limited by 5mA for normal brightness to 30mA for higher brightness.
所需的正向电压取决于坳or and wavelength of the LED light, the current rating can be obtained by investigating the voltage-current characteristics.
Here’s a comparison of the VI characteristics for different types of LEDs.
Current limiting resistor
Generally, LEDs are powered through a low-voltage DC supply. A series resistor is connected with LED to limit the current through it. The value of this resistor can be calculated by using Ohms Law.
如果提供了带有正向电压VF的LED,则可以通过将其连接到该方程式得出的值来限制通过它的电流与IF的电流:
RS = (VS – VF)/IF
LED系列
通过将它们连接到系列中,可以将多个LED从相同的电压源一起驱动。当串联连接时,总电压下降是所有LED的正向电压的总和。同样,通过所有LED的电流将保持不变。
随着LED串联跨度的电压下降的增加,需要重新考虑电流电阻的值。如果将三个LED连接为具有正向电压VF1,VF2和VF3的系列,则可以通过该方程来得出当前限制电阻器的值:
RS = (VS – (VF1 + VF2 + VF3)/ IF
LED驾驶员电路
LEDs are used for decorative purpose or as indicators in electronic devices. LEDs can be used to indicate mutually exclusive conditions, such as if:
- A device is switched on or off
- 选择或未选择的功能或选项
- A device is working or not working
在某些情况下,闪烁的LED表明了动作的进展。
打开和关闭LED的电路称为LED驱动器。为了驱动LED,电路必须控制电流通过它的流动。
通常,LED在电路中是硬连接的,因此可以通过其下沉或采购电流。为了打开LED,其阳极与阴极相比必须具有积极的潜力。如果必须通过采购电流来打开LED,则意味着阴极连接到地面,并将阳极连接到电流源。当源提供的积极潜力大于其正向电压时,电流将通过LED流动,因此它开始发光。在没有大于向前电压的正电压的情况下,LED将保持关闭。
If the LED has to be switched ON by sinking a current through it, this means its anode is connected to a positive DC voltage and the cathode is connected to the sink. When the voltage at the sink drops, the current will flow through the LED so that it starts glowing. When the sink maintains an equal or higher voltage, the LED remains switched OFF.
该图显示了驱动LED的两种方法。
Arduino GPIO和数字输入/输出
Most of the Arduino boards have low-power CMOS 8-bit microcontrollers based on AVR enhanced RISC architecture. The GPIO pins of these controllers operate at CMOS logic levels. A CMOS gate operating at 5V accepts voltage ranging from 0 to 1.5V as logical LOW and 3.5 to 5V as logical HIGH.
逻辑低的CMOS门的可接受输出信号电压范围为0至0.05V,逻辑高4.95至5V。
The Arduino pins can be configured as INPUT, OUTPUT, or INPUT_PULLUP. When a pin is configured as INPUT, a voltage greater than 3V and a voltage greater than 2V is read as logical HIGH in 5 and 3.3V boards, respectively. A voltage less than 1.5V and a voltage less than 1V is read as logical LOW in 5 and 3.3V boards, respectively.
A pin configured as INPUT is in a high-impedance state (for example, such that it’s connected in a series to a 100-Mega Ohms resistor). In such a state, the pin would have an extremely low demand from any external circuits. This means that if it’s unconnected, it would go into an unpredictable floating state.
Therefore, a pin configured as INPUT must be connected to a pull-up or pull-down resistor. A pull-up resistor hardwires the pin to a DC supply voltage and a pull-down resistor hardwires the pin to the ground.
当引脚配置为Input_pullup时,它通过内部上拉电阻访问逻辑级别。这意味着没有理由连接外部上拉电阻以避免浮动状态。当引脚配置为输入或Input_pullup时(如果施加的电压为负或大于电源导轨电压(5或3V),则PIN可能会损坏或破坏。
When a pin is configured as OUTPUT, a voltage of 5V and a voltage of 3.3V is sourced by the pin for logical HIGH in 5 and 3.3V boards, respectively. A voltage of 0V is sourced as a logical LOW in 5 and 3.3V boards.
Arduino引脚可以采购或下沉到40 mA的电流到外部电路。如果任何负载需要超过40 mA的电流,则必须通过晶体管或其他类似电路将其连接。由于LED通常需要12到20 mA的电流,因此它们可以直接接口并由Arduino引脚驱动。
Arduinoas LED driver
LED可以直接与Arduino引脚连接。Arduino GPIO可以通过采购或下沉电流来驱动LED。但是,由于LED必须由Arduino Pin控制,因此必须将引脚配置为数字输出。
如果LED的阳极连接到Arduino引脚,则必须将其阴极接地,以便销钉可以用作当前的源。在这种配置中,当引脚输出逻辑高时,LED发光。当引脚输出逻辑低时,将关闭LED。
如果LED的阴极连接到Arduino引脚,则必须将其阳极连接到直流电源电压。电源电压必须小于Arduino的正功率导轨。在这种配置中,销钉用作当前的水槽。当引脚输出逻辑高时,由于缺乏所需的正向电压(LED两个端子之间的电势差),LED仍会关闭。当引脚输出逻辑低时,LED发光作为所需的电势差(正向电压)跨端子。
因此,LED可以通过这两种方式进行硬连线,并且可以通过简单地切换数字输出来打开和关闭它们。只要它们的正向电压低,就可以通过将它们连接到串联的同一引脚来驱动多个LED。由于正向电压取决于LED的颜色,因此可能可以驾驶两个红色,绿色,黄色。或来自同一销的橙色LED。但是,两个白色的LED可能不会从同一销钉中驱动,即使它们的正向电压总和甚至超过Arduino的电源导轨电压。
Generally, a single LED is driven from one Arduino pin. The LED must remain connected to the Arduino pin via the current-limiting resistor as the output current can shoot up to 40 mA, which may damage the LED.
ArduinoLED driver recipe
In this recipe, we will build an LED driver using Arduino UNO. We will switch an LED ON and OFF regularly, blinking the LED from one of the digital input/output pins on the Arduino board.
The required components…
1。Arduino Uno X1
2。LED X1
3。330 Ohms Resistor x1
4。面包板X1
5。雄性跳线电线
The circuit connections…
- 将Arduino Uno的数字I/O引脚与LED的阳极连接。
- Connect the cathode of the LED with a series resistor of 330 Ohms and ground the other terminal of the resistor.
- The DC supply voltage and ground can be given to the circuit from the 5V power pin and one of the ground pins of the Arduino UNO, respectively.
电路图
Programming guide
For a blinking LED, the pin 2 where the LED is connected must be configured to a digital output. This is done in the setup() function by calling pinMode() function as:
void setup() {
pinMode(2, OUTPUT);
}
LED必须以一秒钟的间隔无限地眨眼。眨眼LED的代码以loop()函数编写,并且它会无限地迭代。
The pin is set to output a logical HIGH using digitalWrite() function and delay() function, which is called passing 1000 milliseconds as an argument to provide a delay of one second. As per the circuit connections, the LED is switched ON when a logical HIGH is an output from the pin.
在一秒钟的延迟之后,将引脚设置为使用DigitalWrite()函数输出逻辑低。再次使用delay()函数传递一秒钟的延迟。当loop()函数中的代码无限地迭代时,LED以一秒钟的定期间隔打开和关闭。
void loop() {
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(1000);
}
The LED is connected with the Arduino pin such that the pin acts as a current source for the LED. When the pin is set to logical HIGH, the LED is “forward biased” and it starts glowing. When the pin is set to logical LOW, the LED is deprived of the forward voltage and it will stop glowing.
逻辑高和低的无限序列是一秒钟的间隔从引脚发出的输出,以闪烁LED。随着微控制器代码一直无限迭代,直到关闭Arduino,LED也将不断闪烁。
自己做
Try driving a pair of series-connected LEDs from the Arduino pin. Will it impact the brightness of LEDs? Will you need to change the current-limiting resistor? What if two LEDs are connected in parallel to the Arduino pin. What if two LEDs are connected in parallel to the Arduino pin such that one LED requires pin as current source to switch ON and the other requires pin as current sink to switch ON?
In thenext tutorial,we will discuss reading digital input on Arduino and will use it to detect the status of a switch.
Demonstration video:
Filed Under:Arduino,,,,354manbetx
Questions related to this article?
询问并讨论电气技术在线.comandEDAboard.comforums.
Tell Us What You Think!!
你一定是logged into post a comment.