700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 上拉电阻和下拉电阻_硬件基础:下拉电阻和上拉电阻如何工作

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

时间:2024-05-17 15:10:20

相关推荐

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

上拉电阻和下拉电阻

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 a0when nothing is connected and a1when 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 a1, and all is good.

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

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

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

We wanted a0when nothing is connected, but how can you guarantee this? Currently, there is no way to guarantee the GPIO to be0.

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

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

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

One way to get a logical0is to tie the pin to Ground:

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

Yay! So, now it’s a guaranteed logical zero. While pushing the button, it’s going to be1now. 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 a1when 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 a1. When you pressed the button, the GPIO will be0.

现在让我们看看相反的情况:上拉电阻。 这是同一件事,但相反。 当未按下按钮时,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 logical1.

未被按下时,我们将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 logical0.

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

? The End.

? 结束。

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

I joined Losant in September of 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. ?

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

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

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

Pull-up Resistors -Another thing to point out is that the larger the resistance for the pull-up, the slower the pin is to respond to…

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

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.

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

翻译自: /news/a-simple-explanation-of-pull-down-and-pull-up-resistors-660b308f116a/

上拉电阻和下拉电阻

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。