I've created a robot arm using 3 servo motors and when I adjust the sliders on an app the servos all twitch. I tried using a capacitor to stabilize the current flow but that was not enough to calm it down. Other posts about the twitching problem say it's because of a lack of power supply. My li-po battery has enough voltage (7.4V) to provide and has a high discharge rate (25c) meaning it should be able to handle all 3 servos. I was able to control them before using potentiometers.
My materials:
- Arduino Nano
- HC-05 Bluetooth module
- 3 MG996R servo motors (datasheet attached)
- 1 L298N Motor driver
- 2 DC Gearbox motors
- Turnigy 7.4V 2200mAh Lipo
- Li-on 3.7V
My code:
#include <SoftwareSerial.h>
#include <Servo.h> // servo library
Servo myservo1, myservo2, myservo3; // servo name
int motorOne = 3;
int motorOne2 = 4;
int motorTwo = 5;
int motorTwo2 = 6;
int en1 = 2;
int en2 = 7;
int bluetoothTx = 10;
int bluetoothRx = 11;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
// MUST HAVE enA and enB, edit the first while loop to include bluetooth, 3.7v lipo small batt, and reattach robot claw then yearly project is done! YAYY!!
//initial motors pin
char command;
char Value;
void setup()
{
myservo1.attach(9); // attach servo signal wire to pin 9
myservo2.attach(12);
myservo3.attach(13);
//Setup usb serial connection to computer
Serial.begin(9600);
bluetooth.begin(9600);
//Setup Bluetooth serial connection to android
}
void loop()
{
while (bluetooth.available() > 0) {
Value = bluetooth.read();
Serial.println(Value);
}
if ( Value == 'F') {
// Robo Pet Run Forward
digitalWrite(en1, HIGH);
digitalWrite(en2, HIGH);
digitalWrite(motorOne, HIGH);
digitalWrite(motorOne2, LOW);
digitalWrite(motorTwo, HIGH);
digitalWrite(motorTwo2, LOW);
} else if (Value == 'B') {
//Robo Pet Run Backward
digitalWrite(en1, HIGH);
digitalWrite(en2, HIGH);
digitalWrite(motorOne, LOW);
digitalWrite(motorOne2, HIGH);
digitalWrite(motorTwo, LOW);
digitalWrite(motorTwo2, HIGH);
} else if (Value == 'L') {
//Robo Pet Turn Left
digitalWrite(en1, HIGH);
digitalWrite(motorOne, HIGH);
digitalWrite(motorOne2, LOW);
digitalWrite(motorTwo, LOW);
digitalWrite(motorTwo2, LOW);
} else if (Value == 'R') {
//Robo Pet Turn Right
digitalWrite(en1, HIGH);
digitalWrite(motorTwo, HIGH);
digitalWrite(motorTwo2, LOW);
digitalWrite(motorOne, LOW);
digitalWrite(motorOne2, LOW);
} else if (Value == 'S') {
//Robo Pet Stop
digitalWrite(motorOne, LOW);
digitalWrite(motorOne2, LOW);
digitalWrite(motorTwo, LOW);
digitalWrite(motorTwo2, LOW);
}
//Read from bluetooth and write to usb serial
if(bluetooth.available()> 0 )
{
unsigned int servopos = bluetooth.read();
unsigned int servopos1 = bluetooth.read();
unsigned int realservo = (servopos1 *256) + servopos;
Serial.println(realservo);
if (realservo >= 1000 && realservo <1180) {
int servo1 = realservo;
servo1 = map(servo1, 1000, 1180, 0, 180);
myservo1.write(servo1);
Serial.println("Servo 1 ON");
delay(10);
}
if (realservo >= 2000 && realservo <2180) {
int servo2 = realservo;
servo2 = map(servo2, 2000, 2180, 0, 180);
myservo2.write(servo2);
Serial.println("Servo 2 ON");
delay(10);
}
if (realservo >= 3000 && realservo <3180) {
int servo3 = realservo;
servo3 = map(servo3, 3000, 3180, 0, 180);
myservo3.write(servo3);
Serial.println("Servo 3 ON");
delay(10);
}
}
}
The app i'm using for controlling servos:
https://drive.google.com/file/d/1CMS4IN4Hxd922cu4Q6afkjA03YsoZK6r/view
Schematic of connections:
Datasheet of servos:
Hopefully, I provided all the information you need. Any tips and help would be much appreciated.
Thank you!