Connecting a button as a digital input

The simplest circuit that we can prepare to be used as a digital input is that consisting of a switch connected to a digital input of the Arduino board.

A typical momentary push button usually has two states, open or closed, and acts like a switch that, when not pressed, keeps the circuit open, preventing the connection between the two parts of the circuit it connects, and when pressed, makes these two parts connected.

Keeping in mind that an Arduino digital input can sense values of 0V and 5V, we have to prepare our circuitry in such a way that it provides a 0V signal to the Arduino digital input when we want to consider it LOW and a 5V signal when we want to consider it HIGH.

To be precise, the Arduino microcontroller can sense anything between 3V and 5V as a HIGH value and something between 1.5V and 0V as a LOW value, the range between 1.5V and 3V undetermined and, thus, not valid.

For the purposes of our first digital input example, we will use a very simple circuit that you can see in the next schematic:

Connecting a button as a digital input

A basic switch connection to Arduino

Although it is a simple circuit, it may deserve some explanation. It basically exposes two different states: the button or switch pressed or released:

  • Released: When the button is not pressed, the two parts of the circuit remain unconnected, thus not flowing any current through that branch of the circuit. In this case, the Arduino board only senses a GND or 0V value through the digital input by which we connect this circuit to it due to the fact that it is physically connected to the ground through the resistor.
  • Pressed: When we press the button or close the switch, what we are internally doing is connecting both parts of the circuit, that is, the 5V upper side to the GND lower side, allowing current to flow from one to the other through the 10K resistor. This is precisely why we use the 10K resistor: to provide some load to this branch of the circuit, preventing the short circuiting of the power source. From the point of view of the Arduino board, it senses a 5V signal in the pin we use to connect this circuit to the board.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.54.7