 Pull-up and pull-down resistors are a core component for any digital sensor that you might use in your Arduino or Raspberry Pi projects. In a nutshell, pull-up and pull-down resistors helps at the default resting position of your GPIO pin and also help filter out digital noise. We will learn how pull-up and pull-down resistors work, when to use which one, and how to wire them up for your project. But first, to understand how pull-up and pull-down resistors work, we must understand how digital signals work. In a sense, digital signals are zeros and ones, on or off. A zero is a ground or low voltage signal, while a one is a either 5 or 3.3 volt high voltage signal. A push-button switch is the easiest way to understand how this digital signal works. Now, if I wire it up following this circuit, you can see that pressing the push-button results in a value of one, while releasing the button results in a value of zero. Now, what if you wanted to reverse this behavior and I wanted to have a value of zero when I pressed the button and a value of one when I let go of the button? Now, you might imagine that changing this circuit to something like this might remedy the solution. But actually, if you try it out, you can see that pressing the button now is absolutely nothing. This is where the pull-up and pull-down resistor comes in. On a side note, you might have noticed that the values coming out of the circuits that we just talked about aren't very stable. Just by touching the digital pin, we can introduce some fluctuations called digital noise. This is because the pin is in a floating position and the pull-up or pull-down resistor can actually remedy this. So, let's start with the pull-down resistor. As you can see, when I connect this resistor between ground and our digital pin, the value instantly drops to zero. Furthermore, any digital noise introduced by touching the pin has also been eliminated. Our button functionality has not been compromised. Following a tweaked version of our original circuit, we can see that when we add the button and press it, we get a stable one reading and if we let go of the button, we get a stable zero reading. Now, let's move on to our pull-up resistor. We can wire up a pull-up resistor by connecting our digital pin through the resistor to our board's power source. On the Arduino, this is the 5V out and on the Raspberry Pi, this is the 3.3V out. As soon as we connect our resistor, you can see the value of our digital pin jumps up to a one. Now, if we modify our circuit and add a button from the digital pin to ground, you can see that pressing the button actually brings the value back down to zero and letting go of the button brings the value back up to a one. This means that the resting position of the digital pin is now a one. It's been pulled up from a default value of zero to a default value of one. This pull-up is where the pull-up resistor gets its name. Now, before we continue, do note that pull-up and pull-down resistors aren't a special category of resistors. They're just normal resistors that get the names based on how they're wired. If you want more information on resistors, you can watch the tutorial on resistors. So you might have noticed that I didn't talk about the specific value of the resistor used in our pull-up or pull-down resistor demos that we've conducted so far. Now we're going to learn about how to select the appropriate value for your pull-up or pull-down resistor. We know that the resistor's main function is to restrict the flow of current. This property is especially important for selecting a pull-up resistor. If you select too small of a resistance value, what'll happen is you'll have too much current flowing between your power source and your digital pin. This can either damage your microcontroller or cause a safety shutdown causing your microcontroller to turn off. This is why we use a higher resistance value for a pull-up or pull-down resistor. The second reason that we use a high resistance value is that if you didn't use a high enough resistance value, our digital pin might be stuck at the pulled-up or pulled-down state regardless of the value of our digital sensors also connected to our digital pin. As a general rule to avoid this, use a resistor value that's 1 tenth less than the input impedance of your input pin. If all of this sounds too complicated for you, stick to a simple 10 kilo ohm pull-up or pull-down resistor as it's almost universally used for this function. Now lucky for us, most microcontrollers actually have built-in pull-ups that can be enabled simply through the code. That means we don't need to wire them. Now let's understand how we can enable that through the code. Okay, here I have my code for the Arduino and here I have my code for the Raspberry Pi in Python. The Raspberry Pi is a bit special because it can do internal pull-ups and internal pull-downs. So as you can see by using this line here, we can enable internal pull-downs and by using this line we can enable internal pull-ups. You just need to change this piece right here, gpio.pud underscore up or underscore down. For the Arduino it's even simpler, you just do pin mode, in this case digital pin 2 and then your internal pull-up. And then you can go ahead and use it as a normal sensor, simple as that. That's it for this tutorial, thanks for watching.