Javatpoint Logo
Javatpoint Logo

Arduino button

The buttons are similar to switches that create and break electrical connections in the circuits. The button plays a transition between ON and OFF state. A single press turns the state ON, while another press turns the state OFF. It means that the button connects the two points in a circuit when we press them.

There are two types of button, which are listed below:

  • NO (Normally Open)

We mostly use NO types of buttons. In such type, the state of the button is in rest. It means that a terminal in such a condition is not connected.

It is shown below:

Arduino button

When we push the button, the terminals become electrically connected.

  • NC (Normally Closed)

It is defined as the working state of the button. It connects the terminals of the circuit and allows current to flow through the load.

It is shown below:

Arduino button

NC and NO are also defined as the momentary type of switches.

Let's understand NO and NC with the help of a circuit.

The NO state of a circuit is shown below:

Arduino button

Due to the open ends of the circuit, the current cannot flow through it. The state of the circuit is in rest.

The NC state of a circuit is shown below:

Arduino button

The current can easily flow through the circuit due to its connected ends. The LED will be ON until we push the button again.

Another type of button is pushbutton, which is widely used in projects and circuits.

Structure of pushbutton

Let's understand the structure of pushbutton.

The pushbutton is a square shape button with four terminals, as shown below:

Arduino button

The two pins are next to each other on one side and another two pins on the other side. The pins across to each other are connected. The pins next to each other can only be connected, when we press the button.

We can also connect two opposite terminals of the pushbutton, as shown below:

Arduino button

Let's understand buttons with an example.

Code Example

Here, we will light an LED by pressing the pushbutton. When we press the push button, it turns ON the LED connected to the PIN 13 on the Arduino UNO board.

Components Required

The required components are listed below:

  • Arduino UNO board. Here, we are using UNO R3.
  • 1 x 220 ohm resistor
  • 1 x 10 Kohm resistor
  • Jump wires
  • 1 x pushbutton
  • 1 x red LED (we can take LED of any color)
  • 1 x Breadboard

The steps for such an example are listed below:

  1. Attach the red LED on the breadboard board.
  2. Connect a resistor in series with the LED and connect it to PIN 2 of the breadboard.
  3. Connect the negative terminal of the LED to the GND pin.
  4. Attach the pushbutton on the breadboard.
  5. Connect a 10 kohm resistor in series with the lower right corner of the pushbutton and connect it to the GND pin.
  6. Connect the upper right corner of the pushbutton to PIN 4.
  7. Connect lower left corner of the pushbutton to 5V.

The circuit is shown below:

Arduino button

Code

The code for the upper circuit is shown below:

Output

The LED will light be OFF at the initial state.

When we continuously press the button, LED will light. The message 'LED is ON' will print on the Serial Monitor after every 500 milliseconds.

Let's watch the output on the serial monitor.

When LED is OFF, the output appears as:

Arduino button

When LED is ON, the output appears as:

Arduino button
Next TopicArduino PWM





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA