Skip to Content

How To Use A DIP Switch With An Arduino

How To Use A DIP Switch With An Arduino

A DIP switch is a group of switches packaged in a single housing. DIP switches are very helpful in setting the modes of operation or providing specific settings as input. 

In this article, let us go through the intrinsics of DIP switches, several applications where DIP switches are essential, and a datasheet of a DIP switch to understand the parameters. 

I will present the hardware connection guide, a few examples of Arduino code, and a compilation of the most frequently answered questions about the DIP switches.

We will see some tips and tricks to best use DIP switches. By altering the connections between VCC and GND, we will see how to prepare the DIP pins as active high or low inputs.

Let’s get started!

Components Needed To Build Arduino DIP Switch Project

Hardware Components

Software is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on

Basics of A DIP Switch

In this section, I will brief about DIP switches in detail. We will see the types of DIP switches available, the specifications of a DIP switch, and a few applications. 

You will find DIP switches in many applications. The DIP switches are in Modems, Control circuit boards, HMI boards, etc.

DIP Switch Actuators

The DIP switch consists of several tiny switches. To activate the switch, you will have to slide the actuator. 

Several types of actuators are available. You can choose the right one for your application.

Some DIP switches will have the actuators on the top, and some will have actuators on the edge.

The side actuators are also known as Piano style DIP switches due to their resemblance to piano keys.

DIP Switch internals

The DIP switch contains several tiny switches. Each tiny switch can be operated independently.

A simplistic representation of a DIP switch with eight positions is shown below. 

When you move the actuator to the ON position, it will close the switch and vice-versa.

DIP Switch Types

The DIP switches come in various options. There are NC, NO, multiple-stage switches, etc. 

An NC switch is one where the tiny switches on the DIP module will be ON in a normal state.

An NO switch is one where the tiny switches on the DIP will be OFF when you put the switch in a normal state.

There is also an ON-FF-ON DIP switch where there can be three stages of the actuators. 

You will also find SPDT and DPDT configurations of DIP switches. You should choose the one which is more suitable for your application.

DIP Switch Specifications

Let us see a DIP switch’s most important specifications, which will help you choose the right DIP switch reliably for your applications. 

  • Circuit type – Most of the DIP switches you find are SPST types (Single Pole, Single Throw). Many other configurations, such as single pole double throw, and double pole double throw, are also available. 
  • Number of Positions – The number of positions refers to the number of tiny switches on the module. The usual ones I use have either 4 or 8 positions. You will find multiple options in the stores. 
  • Current rating – The amount of current each tiny switch on the DIP can handle. Always use not more than 60% of the maximum rating. You shouldn’t operate the DIP switch close to the maximum current rating since you bring down the expected lifetime of the switch. 
  • Voltage rating – The voltage rating mentions the maximum voltage you can apply across the DIP switch. If you are using an Arduino UNO, the maximum voltage you may apply is 5 V. So, you should choose at least 5 V as the minimum rating of the Arduino UNO. 
  • Mechanical Life / Electrical Life – The number of operations supported by the DIp switch before the switching operations become unreliable.
  • The On state resistance – The on-state resistance will be significantly less ( in a few mOhms range).  This is critical if you are using these in the analog section where every mV matters. 

Below is a screenshot from a DIP switch datasheet, where you can see most of the parameters listed for our reference.

screenshot from a DIP switch datasheet

Applications Of The DIP Switch

There are several applications for the DIP switch. I have listed a few below. Let me know what you are using the DIP switch for!

  1. You can generate two to the power N distinct values using the DIP switch to set the price. N represents the number of tiny switches present on the DIP switch. Hence, by using a DIP switch with four positions, you can create 16 different values.
  2. To Set timer options for automatic lighting.
  3. Assign different IDs to multiple remote controller nodes.
  4. Set the operation mode of the room controller (Vacation mode, hating mode, party mode, eco mode, etc.)
  5. Configuring the control boards to either act like a repeater, a hub, or a monitor. 
  6. Use it as a security passcode to enter the garage.
  7. Set different communication frequency channels for wireless radios.

-> Read our guide about What You Can Build with Adruino.

Step-By-Step Instructions To Connect The DIP Switch To An Arduino

In this section, we will build a project using Arduino UNO and a DIP switch. 

You will control the LEDs connected to the Arduino using the DIP switch. 

Let’s get started with the hardware connections!

How To Connect The DIP Switch To The Arduino UNO?

Below is the step-by-step connection guide to complete the Arduino and the DIP-switch module. 

In this project, you will control 6 Arduino GPIO inputs. Based on the status of the DIP switch, you will drive one or more LEDs connected to the Arduino.

You need 6 LEDs, a DIP switch, and connecting wires to complete the connections. 

Step 1: Let us start with the DIP switch

Let us start with the DIP switch

The DIP switch has eight tiny switches on it. We will use six of them. 

Step 2: Let us connect the DIP switch to the Arduino UNO

Let us connect the DIP switch to the Arduino UNO

Pins 2 to 7 are connected to the DIP switch.

Step 3: Complete the DIP switch connection

Complete the DIP switch connection

You can use any of the six switches on the DIP to complete the connections. I have used the switches from 1 to 6.

Step 4: Connect GND to the DIP Switch

Connect GND to the DIP Switch

You can use any GND pins on the Arduino to complete the connection. 

Step 5: Connect the LEDs

Connect the LEDs

Pins 8 to 13 are used as output pins to drive the LEDs. Connect the Anode pins of the LEDs to the Arduino GPIOs. 

Step 6: Complete the LED connections

Complete the LED connections

Connect the cathodes of all the LEDs and connect them to the GND pin of the Arduino. Use series resistors for each LED for safety reasons. 

Step 7: The complete connection

The complete connection

The complete connection looks like the image above. Congratulations on successfully completing the necessary connections.

-> Read our article about How Easy Is It To Learn Arduino?

Arduino Code Example For The DIP Switch Project

In this section, you will find the Arduino sketch necessary to complete the project. The Arduino code is written in an easy-to-understand way. 

Instead of the LEDs, you can process the DIP switch status and take a particular action in the future.

For example, if the DIP switch provides a value of 000001, you can turn on AC; if it is 000010, you can turn on a music system, Etc.

The complete Arduino code

// Natalia Fargasch Norman
// LED control via DIP switches
// Arduino pins used for the LEDs
#define LED1 13
#define LED2 12
#define LED3 11
#define LED4 10
#define LED5 9
#define LED6 8
// Arduino pins used for the switches
#define S1 7
#define S2 6
#define S3 5
#define S4 4
#define S5 3
#define S6 2
// State of each switch (0 or 1)
int s1state;
int s2state;
int s3state;
int s4state;
int s5state;
int s6state;
void setup() {
  // pins for LEDs are outputs
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);
  // pins for switches are inputs
  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(S3, INPUT);
  pinMode(S4, INPUT);
  pinMode(S5, INPUT);
  pinMode(S6, INPUT);
  // setup serial port
  Serial.println("Serial port open");
void loop() {
  s1state = digitalRead(S1);
  digitalWrite(LED1, s1state);
  s2state = digitalRead(S2);
  digitalWrite(LED2, s2state);
  s3state = digitalRead(S3);
  digitalWrite(LED3, s3state);
  s4state = digitalRead(S4);
  digitalWrite(LED4, s4state);
  s5state = digitalRead(S5);
  digitalWrite(LED5, s5state);
  s6state = digitalRead(S6);
  digitalWrite(LED6, s6state);

The lines below configure the GPIOs as input. You are using six pins as inputs.

// Arduino pins used for the switches
#define S1 7
#define S2 6
#define S3 5
#define S4 4
#define S5 3
#define S6 2

The LEDs are connected to six Arduino GPIO outputs. The below lines of code will configure the Arduino GPIO pins as output.

 // pins for LEDs are outputs
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);

In the loop() function, you read the status of the switch. The function digitalRead() will either return a one or a zero based on the position of the switch.

  s1state = digitalRead(S1);
  digitalWrite(LED1, s1state);

Then you write the value (a zero or a one) to the digital write. 

You repeat the same process for all the remaining five switches.

  // Read second switch and update second LED
  s2state = digitalRead(S2);
  digitalWrite(LED2, s2state);
  // Read third switch and update third LED
  s3state = digitalRead(S3);
  digitalWrite(LED3, s3state);
  // Read fourth switch and update fourth LED
  s4state = digitalRead(S4);
  digitalWrite(LED4, s4state);
  // Read fifth switch and update fifth LED
  s5state = digitalRead(S5);
  digitalWrite(LED5, s5state);
  // Read sixth switch and update sixthLED
  s6state = digitalRead(S6);
  digitalWrite(LED6, s6state);

FAQs About The DIP Switch and Arduino Projects

I have compiled a list of the most frequently asked questions about projects using Arduino and DIP switches.

If you have any other questions, please post them in the comments section.

I will be glad to answer them.

1) What are DIP Switches?

DIP stands for Dual-in-line package. A DIP switch contains a set of switches arranged and packed in a single package. The switches help to handle 8 GPIO inputs easily. 

You can use DIP switches to program Arduino UNO to set different modes.

You can also control the LEDs or relays using DIP switches without any MCUs.

What are DIP Switches

The DIP switch in the image above consists of 8 buttons. 

2) What is a 4-pin DIP switch?

A 4-Pin DIP switch consists of 4 independent switches in one package. Here is one such example of a 4-pin DIP switch.

What is a 4-pin DIP switch

3) How much current can a DIP switch handle?

The DIP switch can handle currents in the mA range. Here is one example datasheet of a DIP switch, which can handle up to 100 mA of continuous current.

Hence, you can use the DIP switch to control the LED. 

The current rating will be higher for a continuous current. For a switching current, the ratings will be slightly lower. 

4) How do you tell whether a DIP switch is ON or OFF?

The DIP switch is ON when the slider is near the ON marker on the switch. In the image below, the DIP switch has eight switches in it. Switches 1 and 2 are ON.

The remaining eight switches are OFF.

How do you tell whether a DIP switch is ON or OFF

> Check out our guide to the Top 12 Best Arduino Online Courses


In this article, we understood the basic concepts of a DIP switch. I am hoping that the article was easy to follow. 

We have covered different types of DIP switches available. We also reviewed the specifications one should look for while deciding the right choice of the DIP switch. 

 I will be excited to learn about the projects you built. Please share the links to your projects in the comments section. 

I hope you enjoyed the article. If you have any suggestions to improve the article, I will be glad to hear them.

Please do not forget to share the article with your fellow Arduino enthusiasts.