# How to connect 10 toggle switches to an arduino board?

**URL:** <https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636>\
**Category:** General Electronics\
**Created:** [March 27, 2024, 2:36pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636 "2024-03-27T14:36:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![yorbus](https://avatars.discourse-cdn.com/v4/letter/y/d9b06d/32.png) [@yorbus](https://forum.arduino.cc/u/yorbus)\
**Post date:** [March 27, 2024, 2:36pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/1 "2024-03-27T14:36:07Z")

</div>

Hello,

I am in the process of making a remote control. I would like to connect 10 toggle switches (see image)

 ![Toggle switch](https://europe1.discourse-cdn.com/arduino/original/4X/1/d/3/1d3b634918ac83d3381a2604ba4bc6a9b9c6a488.webp)  
to my arduino boards so that I have 10 separate digital inputs of 0 or 1. How should I connect these? Is that also with resistors? If so, how?  
Thanks in advance!

Greetings Yorbe

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [March 27, 2024, 2:39pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/2 "2024-03-27T14:39:41Z")

</div>

Center pin to GND, one of the other pins to an Arduino pin. Use the built-in pull-up resistor.

---

<div class="post-metadata">

**Author:** ![yorbus](https://avatars.discourse-cdn.com/v4/letter/y/d9b06d/32.png) [@yorbus](https://forum.arduino.cc/u/yorbus)\
**Post date:** [March 27, 2024, 2:41pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/3 "2024-03-27T14:41:16Z")

</div>

Yes, but you have to use also the VCC right?

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [March 27, 2024, 2:48pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/4 "2024-03-27T14:48:18Z")

</div>

No, no VCC needed.

 ![20240327_165139](https://europe1.discourse-cdn.com/arduino/original/4X/f/2/4/f24d1d5bfb6786b41387fb1404b023433d6bdcfe.jpeg)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [March 27, 2024, 3:07pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/5 "2024-03-27T15:07:25Z")

</div>

Example code:

```cpp
#define SWITCHON LOW

const uint8_t switchPins[] = {2, 3, 4, 5, 6, 7, 8, 9, A0, A1};

void setup()
{
  Serial.begin(115200);
  for (uint8_t cnt = 0; cnt < sizeof(switchPins) / sizeof(switchPins[0]); cnt++)
  {
    pinMode(switchPins[cnt], INPUT_PULLUP);
  }
}

void loop()
{
  for (uint8_t cnt = 0; cnt < sizeof(switchPins) / sizeof(switchPins[0]); cnt++)
  {
    uint8_t pinStatus = digitalRead(switchPins[cnt]);

    Serial.print(F("Switch "));
    Serial.print(cnt);
    if (pinStatus == SWITCHON)
    {
      Serial.println(F(" is on"));
    }
    else
    {
      Serial.println(F(" is off"));
    }
  }
  delay(1000);
}

```

The code starts with a macro to make your code a little more readable. LOW and HIGH just mean that, SWITCHON makes it clear that LOW means that the switch is on.

The two for-loops use a calculation (`sizeof(switchPins) / sizeof(switchPins[0])` to calculate the number of pins and iterate through the pins.

---

<div class="post-metadata">

**Author:** ![dougp](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dougp/32/238908_2.png) [@dougp](https://forum.arduino.cc/u/dougp)\
**Post date:** [March 27, 2024, 3:14pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/6 "2024-03-27T15:14:51Z")

</div>

> [@yorbus](#):
>
> Yes, but you have to use also the VCC right?

It's there but it's connected through a resistor internal to the processor. See S3 in the diagram below.

 ![SwitchesAndLEDs](https://europe1.discourse-cdn.com/arduino/original/4X/7/e/0/7e0ee1e51f1df32e30893550c85f0dd33244fb0e.jpeg)

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [March 27, 2024, 3:32pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/7 "2024-03-27T15:32:01Z")

</div>

### FYI

- You also have the option of using **one** GPIO pin connected to an IR receiver.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/d/b/0/db093585019c9248a2d43ad8e3f0e39f0e9a1212.jpeg)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [March 27, 2024, 3:49pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/8 "2024-03-27T15:49:36Z")

</div>

@LarryD , is the image posted by @dougp yours? I would like to give credit if I use it.

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [March 27, 2024, 3:54pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/9 "2024-03-27T15:54:19Z")

</div>

- Yes I drew it up.  
It can be found here:

> [@Share tips you have come across](https://forum.arduino.cc/t/share-tips-you-have-come-across/428745/999):
>
> Different circuit schematics to refer to: DIY basic Logic Probe and Logic Plulser. @ 5V, Logic Probe's load is ~1.6mA. let’s say we have circuit S1. Let’s say the switch is 10 feet from the Arduino. This means we are taking the +5v supply line out 10 feet and 10 feet back. 5v is now extended 20 feet with the potential of it coming in contact with things that can go pop if there was ever a short circuit on the cable. Also, sending 5v out on…

- It’s just a summary I put together.

---

<div class="post-metadata">

**Author:** ![GoForSmoke](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/goforsmoke/32/1127097_2.png) [@GoForSmoke](https://forum.arduino.cc/u/GoForSmoke)\
**Post date:** [March 27, 2024, 4:03pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/10 "2024-03-27T16:03:12Z")

</div>

It is VCC when you set pin mode to INPUT\_PULLUP

pinMode( pin, INPUT\_PULLUP );

that pin sources VCC through 20K to 50K resistance. It is very weak but it is VCC that you can safely ground. The pin reads LOW when grounded.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 23, 2024, 4:03pm UTC](https://forum.arduino.cc/t/how-to-connect-10-toggle-switches-to-an-arduino-board/1240636/11 "2024-09-23T16:03:48Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
