Gikfun Normal Open 2 pin Push Button Switch For Arduino Review and Code

This post talks about using the Gikfun Normal Open 2 pin push button switch with an Arduino.

Gikfun Normal Open 2 Pin Push Button Switch

The Gikfun normal open 2 pin push button switch is a standard SPST switch. Whenever the button is depressed the connection is made and electricity will be able to flow through the switch. After pressing this will reset back to the original disconnected position.

SPST stands for single-pole single-throw, which is the simplest method of switching, having two pins on the switch. When the switch is off the pins are fully disconnected. When the switch is toggled the connection is made between the two pins.

These switches are rated for 250 volts, 1 am, or 125 volts, 3 amps which means they can be used for higher voltage and amperage applications.

A useful feature of this button is that there is a washer that allows it to be mounted through a surface and screwed down.

Wiring it up to an Arduino

To wire this up to the Arduino you need a 10k ohm resistor.

One of the pins on the button must be connected to the 5 volt line. The other must be connected to a pin of the resistor.

The same side of the resistor that is connected to the button will be connected to the digital in pin. This is where the state of the button will be read from. The other side of the resistor is connected to the GND pin on the Arduino.

Programming the Arduino with the Gikfun push button switch

To check the state of the switch I only need to use one digital pin.

#define SWITCH_PIN 2

void setup() {
  Serial.begin(115200);
  pinMode(SWITCH_PIN, INPUT);
}

void loop() {
  int btnState = digitalRead(SWITCH_PIN);
  Serial.println(btnState);
  delay(25);
}

Here I configure the switch pin, pin 2, to be used as a digital input in the setup function. In addition to this, I also configure the serial connection to log the information.

In the main loop the state of the switch is read using digitalRead which returns either 0 or 1. Once the value has been read it is printed to the serial connection.

Final Review

These are useful push button switches that can be used for any Arduino project where a button press is required. Since they work at a range of voltages these can be used with the standard 3.3v or 5v supply lines.

I really like these as they are offered in a number of colours allowing for various colours for your project. Would buy again!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.