90 | | Explanation of how it works |
91 | | The pushbutton when left open, will leave the terminal pins that are connected to GND, and the digital pin, connected to each other. So, there is only one path between the digital pin and the GND. |
92 | | The 5v is left alone on the other side of the push button, so no current is flowing through. |
93 | | This makes the digital pin not have any power going to it, so it has a “Low” state, telling the Arduino that the digital pin receives no power. We can use this information in our code to know when to turn on the LED or not. |
94 | | Now, when the pushbutton is pressed, it allows the 5v to flow, but to which terminal does the electricity flow to? |
95 | | Electricity takes the path of least resistance, and since the path that connects to the digital pin is only a wire, it has no resistance (theoretically), so the electricity flows to the digital pin, making it have a “high” state. On the other hand, the path with the resistor has a lot of resistance in comparison to the path without a resistor, so no electricity flows through there. |
96 | | Code can be used to turn on the LED connected to digital pin 13 when power comes into digital pin 2 when the push button is pressed. |
97 | | The resistor serves as a barrier, herding the electrons away from the GND pin, and into the digital pin, so that we know when the push button was pressed. |
98 | | You might be asking, why can’t we just put the digital pin on 1 side of the push button, and the 5v on the other, and when the push button is pressed, the digital pin gets power? |
99 | | If we were to do that, the digital pin will turn on and off randomly even when the push button is left alone. The reason why is because there are a lot of waves of energy happening in the environment, like radio waves, infrared waves, etc, which can enter the push button and give power to the digital pin. We solve this by connecting the wire from the digital pin to GND, and add a resistor connected to GND so that when the push button is pressed, the 5v won’t just travel to GND and totally ignore the digital pin. |
| 91 | |
| 92 | == Explanation of how it works\\ |
| 93 | |
| 94 | a. The pushbutton when left open, will leave the terminal pins that are connected to GND, and the digital pin, connected to each other. So, there is only one path between the digital pin and the GND.\\ |
| 95 | |
| 96 | b. The 5v is left alone on the other side of the push button, so no current is flowing through.\\ |
| 97 | |
| 98 | c. This makes the digital pin not have any power going to it, so it has a “Low” state, telling the Arduino that the digital pin receives no power. We can use this information in our code to know when to turn on the LED or not.\\ |
| 99 | |
| 100 | d. Now, when the pushbutton is pressed, it allows the 5v to flow, but to which terminal does the electricity flow to?\\ |
| 101 | |
| 102 | e. Electricity takes the path of least resistance, and since the path that connects to the digital pin is only a wire, it has no resistance (theoretically), so the electricity flows to the digital pin, making it have a “high” state. On the other hand, the path with the resistor has a lot of resistance in comparison to the path without a resistor, so no electricity flows through there.\\ |
| 103 | |
| 104 | f. Code can be used to turn on the LED connected to digital pin 13 when power comes into digital pin 2 when the push button is pressed.\\ |
| 105 | |
| 106 | g. The resistor serves as a barrier, herding the electrons away from the GND pin, and into the digital pin, so that we know when the push button was pressed.\\ |
| 107 | |
| 108 | h. You might be asking, why can’t we just put the digital pin on 1 side of the push button, and the 5v on the other, and when the push button is pressed, the digital pin gets power?\\ |
| 109 | |
| 110 | i. If we were to do that, the digital pin will turn on and off randomly even when the push button is left alone. The reason why is because there are a lot of waves of energy happening in the environment, like radio waves, infrared waves, etc, which can enter the push button and give power to the digital pin. We solve this by connecting the wire from the digital pin to GND, and add a resistor connected to GND so that when the push button is pressed, the 5v won’t just travel to GND and totally ignore the digital pin. |