BITE SIZE ARDUINO – 3 PIN SNAP-ACTION LEVER SWITCH

Today we are looking at how to connect a 3 pin snap-action lever switch to an Arduino board and reading when it is pressed.

switch

The lever switch has 3 pins – the common terminal, the normally off terminal and the normally on terminal. If the switch is not pressed current will flow from the common terminal to the normally on terminal, however if the switch is pressed current will cease flowing from common to normally on and will start flowing from the common to normally off terminals.

For this example we will only utilise 2 of the terminals – the common and the normally off terminal.

The common terminal is connected to the 5V pin on the Arduino board and the normally off terminals’ connection is split:

One leg connecting to the Arduino boards’ ground pin with a 10kOhm resistor in series.
The other leg connecting to a digital pin on the Arduino board, for this example digital pin 2.
lever Switch_bb

Here is the code to determine when the switch is pressed:

#define LEVER_SWITCH_PIN 2
int pressSwitch = 0;
void setup()
{
Serial.begin(9600);
}

void loop()
{
pinMode(LEVER_SWITCH_PIN,INPUT);
pressSwitch = digitalRead(LEVER_SWITCH_PIN);
if(pressSwitch == High)
{
Serial.println(“Switch Pressed!");
delay(1000);
}
}
BITE SIZE ARDUINO – 3 PIN SNAP-ACTION LEVER SWITCH

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s