# Servo control with one button

**URL:** <https://forum.arduino.cc/t/servo-control-with-one-button/1447740>\
**Category:** Jobs and Paid Consultancy\
**Created:** [June 9, 2026, 2:07pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740 "2026-06-09T14:07:51Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![joergx](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/joergx/32/1274287_2.png) [@joergx](https://forum.arduino.cc/u/joergx)\
**Post date:** [June 9, 2026, 2:07pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/1 "2026-06-09T14:07:51Z")

</div>

Hi everyone, I'm looking for someone to put together a project for me. I want to move 10 servos simultaneously with a single push button (maximum 180°). The button should indicate the servo endpoints: -90° in green and +90° in red. This will be used as a drawer lock in a camper van. Of course, I'll pay for it ;-) Thanks in advance! Best regards, Joerg

---

<div class="post-metadata">

**Author:** ![zwieblum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zwieblum/32/427702_2.png) [@zwieblum](https://forum.arduino.cc/u/zwieblum)\
**Post date:** [June 9, 2026, 2:27pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/2 "2026-06-09T14:27:21Z")

</div>

What's the budget?

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [June 9, 2026, 2:30pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/3 "2026-06-09T14:30:15Z")

</div>

Do you already have the hardware for this project ?

I assume that you will be doing the installation of the hardware. How big is the campervan ? This is important because the cable runs could potentially be quite long

---

<div class="post-metadata">

**Author:** ![xfpd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/xfpd/32/1120236_2.png) [@xfpd](https://forum.arduino.cc/u/xfpd)\
**Post date:** [June 9, 2026, 2:47pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/4 "2026-06-09T14:47:09Z")

</div>

> [@joergx](#):
>
> move 10 servos simultaneously

Moving them sequentially, at a very small interval, will lessen the current capacity of the power supply. Reconsider "simultaneously."

[edit] just going to sneak this little code dump in here

> **onebuttontenservos.ino**
>
> ```arduino
> #include <Servo.h>
> const char servos = 10; // number of servos
> Servo servo[servos]; // create servo instances
> 
> unsigned char buttonpin = 12, ledpin = 14; // pins
> bool lockstate = 0, actuate = 0; // lock state and flag to actuate locks
> int lockangle = 180, openangle = 0; // angle value for locked/opened
> int timebetweenservos = 250; // time given to 180 degree servo move
> 
> bool currentButtonState, lastButtonRead; // button reading
> unsigned long buttonTimer, buttonTimeout = 50;
> 
> void setup() {
> pinMode(buttonpin, INPUT_PULLUP);
> pinMode(ledpin + 0, OUTPUT); // red
> pinMode(ledpin + 1, OUTPUT); // grn
> 
> digitalWrite(ledpin + 0, lockstate); // red
> digitalWrite(ledpin + 1, !lockstate); // grn
> 
> for (byte i = 0; i < servos; i++) {
> servo[i].attach(i + 2); // servo[0] = pin 2, servo[9] = pin 11
> servo[i].write(openangle); // servo home
> delay(timebetweenservos); // pause between servo move
> }
> }
> 
> void loop() {
> readButton();
> if (actuate) // if button was pressed
> actuateservos();
> }
> 
> void actuateservos() { // if locked then open. if opened then lock.
> actuate = 0; // reset flag
> lockstate = !lockstate; // change state
> for (byte i = 0; i < servos; i++) {
> servo[i].write(lockstate * lockangle); // state 0 = 0 degreesm state 1 = 180 degrees
> delay(timebetweenservos); // pause between servo move
> }
> digitalWrite(ledpin + 0, lockstate);
> digitalWrite(ledpin + 1, !lockstate);
> }
> 
> void readButton() {
> bool currentButtonRead = digitalRead(buttonpin); // read button pin
> 
> if (currentButtonRead != lastButtonRead) { // if button pin changes...
> buttonTimer = millis(); // ...start a timer
> lastButtonRead = currentButtonRead; // ... and store current state
> }
> 
> if ((millis() - buttonTimer) > buttonTimeout) { // if button change was longer than debounce timeout
> if (lastButtonRead == LOW && currentButtonState == HIGH) { // ...button WAS PRESSED but state IS RELEASED
> //==================================================
> actuate = 1; // set flag to actuate locks open or closed
> //==================================================
> }
> currentButtonState = currentButtonRead; // update button state
> }
> }
> 
> ```

> **diagram.json for wokwi.com simulator**
>
> ```arduino
> {
> "version": 1,
> "author": "xfpd",
> "editor": "wokwi",
> "parts": [
> { "type": "wokwi-arduino-nano", "id": "nano", "top": 81.6, "left": -0.5, "attrs": {} },
> { "type": "wokwi-servo", "id": "servo1", "top": -261.2, "left": 201.6, "attrs": {} },
> {
> "type": "wokwi-led",
> "id": "led1",
> "top": 142.8,
> "left": -65.8,
> "rotate": 270,
> "attrs": { "color": "red", "flip": "1" }
> },
> {
> "type": "wokwi-resistor",
> "id": "r1",
> "top": 176.75,
> "left": -19.2,
> "attrs": { "value": "330" }
> },
> { "type": "wokwi-servo", "id": "servo2", "top": -213.2, "left": 201.6, "attrs": {} },
> { "type": "wokwi-servo", "id": "servo3", "top": -165.2, "left": 201.6, "attrs": {} },
> { "type": "wokwi-servo", "id": "servo4", "top": -117.2, "left": 201.6, "attrs": {} },
> { "type": "wokwi-servo", "id": "servo5", "top": -69.2, "left": 201.6, "attrs": {} },
> {
> "type": "wokwi-pushbutton",
> "id": "btn1",
> "top": 54.2,
> "left": 201.6,
> "attrs": { "color": "green", "xray": "1" }
> },
> {
> "type": "wokwi-led",
> "id": "led2",
> "top": 162,
> "left": -65.8,
> "rotate": 270,
> "attrs": { "color": "limegreen", "flip": "1" }
> },
> { "type": "wokwi-vcc", "id": "vcc1", "top": -248.84, "left": 9.6, "attrs": {} },
> { "type": "wokwi-gnd", "id": "gnd1", "top": 153.6, "left": 172.2, "attrs": {} },
> {
> "type": "wokwi-servo",
> "id": "servo6",
> "top": -50.8,
> "left": -170,
> "rotate": 180,
> "attrs": {}
> },
> {
> "type": "wokwi-servo",
> "id": "servo7",
> "top": -99.6,
> "left": -167.2,
> "rotate": 180,
> "attrs": {}
> },
> {
> "type": "wokwi-servo",
> "id": "servo8",
> "top": -146.8,
> "left": -170,
> "rotate": 180,
> "attrs": {}
> },
> {
> "type": "wokwi-servo",
> "id": "servo9",
> "top": -194.8,
> "left": -170,
> "rotate": 180,
> "attrs": {}
> },
> {
> "type": "wokwi-servo",
> "id": "servo10",
> "top": -242.8,
> "left": -170,
> "rotate": 180,
> "attrs": {}
> },
> {
> "type": "wokwi-resistor",
> "id": "r2",
> "top": 157.55,
> "left": -19.2,
> "attrs": { "value": "330" }
> }
> ],
> "connections": [
> ["nano:2", "servo5:PWM", "green", ["v0"] ],
> ["nano:3", "servo4:PWM", "green", ["v0"] ],
> ["nano:4", "servo3:PWM", "green", ["v0"] ],
> ["nano:5", "servo2:PWM", "green", ["v0"] ],
> ["nano:6", "servo1:PWM", "green", ["v0"] ],
> ["vcc1:VCC", "servo1:V+", "red", ["v0"] ],
> ["nano:7", "servo10:PWM", "green", ["v0"] ],
> ["nano:8", "servo9:PWM", "green", ["v0"] ],
> ["nano:9", "servo8:PWM", "green", ["v0"] ],
> ["nano:10", "servo7:PWM", "green", ["v0"] ],
> ["nano:11", "servo6:PWM", "green", ["v0"] ],
> ["led1:C", "r2:1", "green", ["h0"] ],
> ["led2:C", "r1:1", "green", ["h0"] ],
> ["led1:A", "nano:A0", "green", ["h57.6"] ],
> ["led2:A", "nano:A1", "green", ["h67.2"] ],
> ["nano:GND.1", "r2:2", "black", ["v0"] ],
> ["nano:GND.1", "r1:2", "black", ["v0"] ],
> ["btn1:1.l", "nano:12", "gold", ["h0"] ],
> ["gnd1:GND", "btn1:2.l", "black", ["v0"] ],
> ["gnd1:GND", "nano:GND.3", "black", ["v0"] ],
> ["gnd1:GND", "servo5:GND", "black", ["v0"] ],
> ["servo5:GND", "servo4:GND", "black", ["h-19.2", "v-48"] ],
> ["servo4:GND", "servo3:GND", "black", ["h-19.2", "v-48"] ],
> ["servo3:GND", "servo2:GND", "black", ["h-19.2", "v-48"] ],
> ["servo2:GND", "servo1:GND", "black", ["h-19.2", "v-48"] ],
> ["servo1:V+", "servo2:V+", "red", ["h-9.6", "v19.3"] ],
> ["servo2:V+", "servo3:V+", "red", ["h-9.6", "v48.1"] ],
> ["servo4:V+", "servo3:V+", "red", ["h-9.6", "v-47.9"] ],
> ["servo4:V+", "servo5:V+", "red", ["h-9.6", "v48.1"] ],
> ["vcc1:VCC", "servo10:V+", "red", ["v0"] ],
> ["servo10:V+", "servo9:V+", "red", ["h19.2", "v48"] ],
> ["servo9:V+", "servo8:V+", "red", ["h19.2", "v48"] ],
> ["servo8:V+", "servo7:V+", "red", ["h19.2", "v47.2"] ],
> ["servo7:V+", "servo6:V+", "red", ["h16.4", "v48.8"] ],
> ["gnd1:GND", "servo6:GND", "black", ["v0"] ],
> ["servo6:GND", "servo7:GND", "black", ["h9.6", "v-48"] ],
> ["servo7:GND", "servo8:GND", "black", ["h6.8", "v-47.2"] ],
> ["servo8:GND", "servo9:GND", "black", ["h9.6", "v-48"] ],
> ["servo9:GND", "servo10:GND", "black", ["h9.6", "v-48"] ]
> ],
> "dependencies": {}
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [June 9, 2026, 2:53pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/5 "2026-06-09T14:53:48Z")

</div>

> [@joergx](#):
>
> This will be used as a drawer lock in a camper van.

What will be the servo positions if power is ever removed? What will be the servo positions when power is first applied?

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [June 9, 2026, 3:22pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/6 "2026-06-09T15:22:06Z")

</div>

Former 42ft 8 ton RV owner here. Most will not understand the phrase 'rolling earthquake'.  
A push button can easily be accidently pushed. I suggest you use a hooded ON/OFF/ON switch.

 ![Screenshot 2026-06-09 at 11.21.22](https://europe1.discourse-cdn.com/arduino/original/4X/7/1/f/71f02130722add946ea2f7d7b6a958df489aa24b.jpeg)

I realize the pictured switch is only ON/OFF, but the project requires ON/OFF/ON which is -90 / OFF / +90.

---

<div class="post-metadata">

**Author:** ![HazardsMind](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hazardsmind/32/215209_2.png) [@HazardsMind](https://forum.arduino.cc/u/HazardsMind)\
**Post date:** [June 9, 2026, 3:49pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/7 "2026-06-09T15:49:02Z")

</div>

What about an actual key for safety concerns? Or even a key fob, tap once to unlock and tap again to lock. Perhaps add an indicator led too.

---

<div class="post-metadata">

**Author:** ![EmilyJane](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/emilyjane/32/821537_2.png) [@EmilyJane](https://forum.arduino.cc/u/EmilyJane)\
**Post date:** [June 9, 2026, 3:54pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/8 "2026-06-09T15:54:07Z")

</div>

I would add a test for if the drawer is fully closed before latching.

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [June 9, 2026, 4:06pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/9 "2026-06-09T16:06:26Z")

</div>

I stupidly assumed an LED was included. I don't like the Key Fob idea, if it fails to work for some reason, it could present issues. A key isn't a terrible idea, but if it were my RV, I would mount the main power hooded switch inside the main control panel (if it has a door) or failing that as far from the push button as possible.  
NOTE to non-RVers. I am assuming the OP's rig is a slide-out, so there will likely be only a small area of the RV reachable when buttoned up and any and all components need to be handy. Another option is a master switch in the basement.  
The OP needs to tell us the parameters.

---

<div class="post-metadata">

**Author:** ![zwieblum](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/zwieblum/32/427702_2.png) [@zwieblum](https://forum.arduino.cc/u/zwieblum)\
**Post date:** [June 9, 2026, 6:03pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/10 "2026-06-09T18:03:07Z")

</div>

Most likely a simple mechanical locker solves the problem more reliable than any arduino+servo combo could do for a reaonable price :)

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [June 9, 2026, 8:39pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/11 "2026-06-09T20:39:48Z")

</div>

Most likely, this isn't about security per se; the OP is probably trying to prevent the drawers from opening every time he hits a pothole in the road. Better confirm with the OP as to the actual need.  
To me, so-called child locks, simple little plastic tabs that engage with a plastic ear on the drawer, are just as effective; just don't expect them to actually slow down a child much, as they're purely for frustrating adults.

---

<div class="post-metadata">

**Author:** ![cedarlakeinstruments](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cedarlakeinstruments/32/1128931_2.png) [@cedarlakeinstruments](https://forum.arduino.cc/u/cedarlakeinstruments)\
**Post date:** [June 9, 2026, 9:33pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/12 "2026-06-09T21:33:36Z")

</div>

Or use that switch **and** a pushbutton. I have a garden tractor key replacement partially wired. Flip up the hood to energize/lift magneto ground, push button to start.

---

<div class="post-metadata">

**Author:** ![sonofcy](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sonofcy/32/1283617_2.png) [@sonofcy](https://forum.arduino.cc/u/sonofcy)\
**Post date:** [June 9, 2026, 9:41pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/13 "2026-06-09T21:41:00Z")

</div>

Sorry if I wasn't clear, the switch is only meant to energize the button. Re-reading the OP, it sounds like a simple ON/OFF switch is plenty. We used to call them SPST, is that still correct? It should be obvious, but that switched wire is the hot wire. In many recreational vehicles, the frame is often common ground but I advise against it for control circuits at least.

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [June 9, 2026, 9:59pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/14 "2026-06-09T21:59:16Z")

</div>

Hi @joergx!

Controlling ten servos is easily achievable. Here is an example where two LEDs (red and green) indicate the "closed" and "open" states, and the corresponding LED flashes during the transition (red while closing, green while opening).

```arduino
/*
  Forum: https://forum.arduino.cc/t/servo-control-with-one-button/1447740
  Wokwi: https://wokwi.com/projects/466365025604980737

  2026/06/09
  ec2021

*/

#include <Servo.h>

constexpr byte pwmPins[] = { 5, 6, 9, 10, 11 };
constexpr int noOfPins = sizeof(pwmPins) / sizeof(pwmPins[0]);
Servo servos[noOfPins];

constexpr byte btPin{ 2 };
constexpr byte redPin{ 4 };
constexpr byte greenPin{ 3 };
constexpr unsigned long duration{ 3000 };
constexpr byte delta{ 10 };
constexpr byte openPosition{ 180 };
constexpr byte closePosition{ 0 };

enum class LOCK { IDLE,
                  CLOSING,
                  OPENING,
                  PREPARE
                };

LOCK state = LOCK::IDLE;
boolean locked = true;
byte lockPosition = 0;
unsigned long lastStep = 0;

void setup() {
  Serial.begin(115200);
  pinMode(btPin, INPUT_PULLUP);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  for (int i = 0; i < noOfPins; i++) {
    servos[i].attach(pwmPins[i]);
  }
}

void loop() {
  drawerLock();
}

void drawerLock() {
  switch (state) {
    case LOCK::IDLE:
      if (digitalRead(btPin) == LOW) {
        state = locked ? LOCK::OPENING : LOCK::CLOSING;
        delay(100); //Very simple debouncing
        digitalWrite(redPin, LOW);
        digitalWrite(greenPin, LOW);
      }
      break;
    case LOCK::CLOSING:
      doBlink(redPin);
      if (millis() - lastStep > 100) {
        lastStep = millis();
        if (lockPosition < delta) {
          lockPosition = closePosition;
        } else {
          lockPosition -= delta;
        }
        setServoTo(lockPosition);
      }
      if (lockPosition == closePosition) {
        locked = true;
        state = LOCK::PREPARE;
      }
      break;
    case LOCK::OPENING:
      doBlink(greenPin);
      if (millis() - lastStep > 100) {
        lastStep = millis();
        if (lockPosition + delta >= openPosition) {
          lockPosition = openPosition;
        } else {
          lockPosition += delta;
        }
        setServoTo(lockPosition);
      }
      if (lockPosition == openPosition) {
        locked = false;
        state = LOCK::PREPARE;
      }
      break;
    case LOCK::PREPARE:
      if (locked) {
        setLedsOnOff(redPin, greenPin);
      } else {
        setLedsOnOff(greenPin, redPin);
      }
      state = LOCK::IDLE;
      break;
  }
}

void setServoTo(byte value) {
  for (int i = 0; i < noOfPins; i++) {
    servos[i].write(value);
  }
}

void doBlink(byte pin) {
  static unsigned long lastBlink = 0;
  if (millis() - lastBlink > 500) {
    lastBlink = millis();
    byte newState = !digitalRead(pin);
    digitalWrite(pin, newState);
  }
}

void setLedsOnOff(byte a, byte b) {
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
}

```

siehe [https://wokwi.com/projects/466365025604980737](https://wokwi.com/projects/466365025604980737)

Additionally, it would be worth checking whether the drawers are fully pushed in so that the closing mechanism operates correctly without any mechanical issues.

The sketch controls two servos per pin to limit the current drawn on each pin. This probably isn't even necessary, given that a pin can supply up to 20 mA and servos typically draw very little current (less than 1 mA).

Whether implementing this electrically—without an emergency release—and using a single button is actually a good solution is another matter entirely...

Regards,  
ec2021

BTW: In any case make sure to supply the servos directly with sufficient energy, not from the Arduino board!

---

<div class="post-metadata">

**Author:** ![cedarlakeinstruments](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cedarlakeinstruments/32/1128931_2.png) [@cedarlakeinstruments](https://forum.arduino.cc/u/cedarlakeinstruments)\
**Post date:** [June 9, 2026, 11:11pm UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/15 "2026-06-09T23:11:21Z")

</div>

> [@ec2021](#):
>
> a pin can supply up to 20 mA and servos typically draw very little current (less than 1 mA)

If OP doesn't mind them all opening or closing at the same time, driving all the servos from one pin might simplify wiring. Just need to address the current demand.

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [June 10, 2026, 6:55am UTC](https://forum.arduino.cc/t/servo-control-with-one-button/1447740/16 "2026-06-10T06:55:46Z")

</div>

I couldn't find reliable information about the use of several servos with one single pin.

it's surely possible to connect more than two servos to one pin but I would not exclude that more than four of them might have an influence on the signal.

It depends on the electrical input behavior of the specific servo type (high or low impedance, capacitance).

The cost of using several pins is low, just some extra wiring. The change in software is simple, only change the pins in the pwmPins array.

For sure an appropriate power supply will be crucial to avoid problems.
