上拉电阻和下拉电阻_硬件基础:下拉电阻和上拉电阻如何工作

上拉电阻和下拉电阻

by Taron Foxworth

通过塔伦·福克斯沃思(Taron Foxworth)

硬件基础:下拉电阻和上拉电阻如何工作 (Hardware fundamentals: how pull-down and pull-up resistors work)

If you’ve ever wired up a button to an Arduino, you’ve come across this diagram:

如果您曾经将一个按钮连接到Arduino,那么您会遇到以下图表:

At first, this can be confusing. My first thoughts: “Why do I need a resistor? I just want to it to tell me whether the button is being pressed.”

首先,这可能会造成混淆。 我的第一个想法是:“为什么需要电阻? 我只是想告诉我按钮是否被按下。”

After a lot of reading, there wasn’t a simple explanation.

经过大量阅读后,没有一个简单的解释。

这里发生了什么 (What’s going on here)

In that button — AKA a switch—the wires are shaped in the form of an “H”. But the middle isn’t connected — or the circuit isn’t connected — until we press the button.

在该按钮(也称为开关)中,电线的形状为“ H”形。 但是直到我们按下按钮,中间才被连接(或电路未被连接)。

In reality, we want to read from the Arduino a 0 when nothing is connected and a 1 when the button is pressed.

实际上,我们要在未连接任何东西时从Arduino读取0 ,并在按下按钮时读取1

On the Arduino, this is called General Purpose Input Output (GPIO).

在Arduino上,这称为通用输入输出( GPIO )。

So, we can do something like this:

因此,我们可以执行以下操作:

We connect positive (5v, 3.3V, or VCC) to the left side of the circuit.

我们将正极(5v,3.3V或VCC)连接到电路的左侧。

Now, when the button is pressed, the GPIO will read a 1, and all is good.

现在,当按下按钮时,GPIO将读取1 ,一切正常。

Well, no. Let’s take a look at Diagram 2 again:

好吧,不。 让我们再次看一下图2:

We wanted a 0 when nothing is connected, but how can you guarantee this? Currently, there is no way to guarantee the GPIO to be 0.

当没有任何连接时,我们希望为0 ,但是如何保证呢? 当前,无法保证GPIO为0

There is also electromagnetic frequencies in the air that could draw your GPIO to 0 or 1. It could even fluctuate between the two! This way, we can’t be positive it’s a 0 (I’m so bad at puns). This is also known as a logical 0.

空气中也存在电磁频率,可能会使GPIO变为01 。 两者之间甚至可能波动! 这样,我们不能肯定它是0 (我双关语很不好)。 也称为逻辑0

One way to get a logical 0 is to tie the pin to Ground:

获得逻辑0一种方法是将引脚接地。

Yay! So, now it’s a guaranteed logical zero. While pushing the button, it’s going to be 1 now. Right?

好极了! 因此,现在保证是逻辑零。 按下按钮时,现在将为1 。 对?

Well, No.

好吧,不

You just created a short circuit. ?

您刚刚造成了短路 。 ?

This is where the resistor comes in. To avoid a short circuit, we need to add resistance to our circuit. The resistor keeps things under control.

这是电阻器进入的地方。为避免短路,我们需要在电路中增加电阻。 电阻使事物处于受控状态。

Electricity will take the path of least resistance. Your GPIO will now register a 1 when the button is pressed. Like so:

电力将沿着阻力最小的道路前进。 现在,按下按钮后,您的GPIO将注册为1 。 像这样:

Woo Hoo! Now we’re working with something.

呜呼! 现在,我们正在处理某些东西。

Now let’s look at the opposite: pull-up resistors. It’s the same thing but in reverse. While the button is not pressed, the GPIO will register a 1. When you pressed the button, the GPIO will be 0.

现在让我们看看相反的情况:上拉电阻。 这是同一件事,但相反。 当未按下按钮时,GPIO将注册1 。 当您按下按钮时,GPIO将为0

While not pressed, we have the GPIO connected to positive ( VCC ). So, any current that is there will be pulled-up so that the GPIO registers a logical 1.

未被按下时,我们将GPIO连接到正极(VCC)。 因此,存在的任何电流都会被上拉,以使GPIO注册为逻辑1

It’s important to note here that, electricity always wants to go to Ground. So, when we press the button, the current that’s flowing will flow to Ground. Thus, any current that would have been going to the GPIO goes with it, leaving the GPIO at a logical 0.

在此必须注意的是,电总是要接地。 因此,当我们按下按钮时,正在流动的电流将流向地面。 因此,本应流向GPIO的任何电流都会随之流逝,而GPIO保持逻辑0

? The End.

? 结束。

我为什么写这个? (Why did I write this?)

I joined Losant in September of 2016 with no hardware experience. Every single hardware starter kit gives you a button with no explanation of this concept. Hopefully, this helps your light bulb go off too. ?

我于2016年9月加入Losant ,没有硬件经验。 每个单独的硬件入门套件都为您提供了一个按钮,但没有对此概念进行解释。 希望这也有助于您的灯泡熄灭。 ?

This only scratched the surface. If you want to dig deeper, check out these resources:

这只是划伤表面。 如果您想进一步研究,请查看以下资源:

Pull-up Resistors - learn.sparkfun.comAnother thing to point out is that the larger the resistance for the pull-up, the slower the pin is to respond to…learn.sparkfun.com

上拉电阻-Learn.sparkfun.com还要指出的 另一点是,上拉电阻越大,引脚响应的速度就越慢。

I love feedback. So, please let me know if this could be improved. If I totally missed the ball on this, let me know! I would love to make it better for others.

我喜欢反馈。 因此,请让我知道是否可以改进。 如果我完全错过了球,请告诉我 我想为他人做得更好。

翻译自: https://www.freecodecamp.org/news/a-simple-explanation-of-pull-down-and-pull-up-resistors-660b308f116a/

上拉电阻和下拉电阻

已标记关键词 清除标记
表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
相关推荐
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页