Title: MG995 Servos Start Automatically, Button Debouncing Issues & Jerking Motors – Works in Tinkercad but Not in Real Setup
Hello Arduino Community,
We’ve built a project to drive two MG995 servo motors using an Arduino Uno. The system is supposed to work in two modes:
-
Synchronous Mode: Both servos rotate together.
-
Asynchronous Mode: Servo 1 rotates first, followed by Servo 2, and vice versa.
We tested our logic in Tinkercad simulation, and everything works perfectly there. However, in the real hardware setup, we are facing three major problems:
- Motors Start Immediately on Power-Up
Expected Behavior: Servos should remain at rest (0° position) when Arduino is powered on. They should only start moving when the Start button is pressed.
Actual Behavior: As soon as the Arduino is powered, the servos begin moving, even without pressing the Start button.
- Buttons (Stop/Delay Mode) are Unresponsive
We are using INPUT_PULLUP for Start, Stop, and Delay Mode buttons.
Problem: These buttons sometimes require 5 to 10 presses to register an action.
This doesn’t happen in Tinkercad, only in real-world usage.
We suspect a debouncing issue, but need confirmation and advice.
- Motors Show Jerky Movements
We're using two MG995 servos, each powered by a separate regulated 6.5V supply.
Despite this, the servos jerk erratically during operation, and don’t run smoothly as in the simulation.
All GNDs (servo power and Arduino GND) are properly connected.
Code Summary:
Buttons are set with INPUT_PULLUP.
Servos are driven using the Servo.h library.
Logic checks for button presses and uses flags (motorRunning and delayMode) to control motion.
We use delay(300) after button presses for debouncing, but it doesn’t seem reliable in hardware.
Code:
#include <Servo.h>
const int START_BUTTON_PIN = 7;
const int STOP_BUTTON_PIN = 6;
const int DELAY_BUTTON_PIN = 5;
const int SERVO_PIN_1 = 10;
const int SERVO_PIN_2 = 11;
Servo servo1, servo2;
bool motorRunning = false;
bool delayMode = false;
void setup() {
Serial.begin(9600);
pinMode(START_BUTTON_PIN, INPUT_PULLUP);
pinMode(STOP_BUTTON_PIN, INPUT_PULLUP);
pinMode(DELAY_BUTTON_PIN, INPUT_PULLUP);
servo1.attach(SERVO_PIN_1);
servo2.attach(SERVO_PIN_2);
servo1.write(0);
servo2.write(0);
}
void loop() {
if (digitalRead(START_BUTTON_PIN) == LOW) {
Serial.println("Start button pressed");
motorRunning = true;
delay(300);
}
if (digitalRead(STOP_BUTTON_PIN) == LOW) {
Serial.println("Stop button pressed");
motorRunning = false;
delayMode = false;
delay(300);
}
if (digitalRead(DELAY_BUTTON_PIN) == LOW) {
Serial.println("Delay mode activated");
delayMode = true;
delay(300);
}
while (motorRunning) {
if (delayMode) {
servo1.write(90); delay(500);
servo2.write(90); delay(500);
servo1.write(0); delay(500);
servo2.write(0); delay(500);
} else {
servo1.write(90); servo2.write(90); delay(1000);
servo1.write(0); servo2.write(0); delay(1000);
}
if (digitalRead(STOP_BUTTON_PIN) == LOW) {
Serial.println("Stop button pressed");
motorRunning = false;
delayMode = false;
delay(300);
}
}
}
My Questions:
-
Why do the motors start immediately when powered on, even though motorRunning is initialized to false?
-
Why do the buttons require multiple presses to register a state change?
Should I use software/hardware debouncing (e.g., millis() or capacitors)?
- Why are the MG995 motors jerking, even with a regulated 6.5V supply and separate GNDs?
Is this a power issue, servo library timing issue,