controlling two servos

hello, for my project i am controlling 2 servos, for this I use an extarnal 6v power source. The servos are not really working vey well, at first I had to wrtie values like 93 to stop them from moving. Then suddenly one did not stop at all, I opened the servo but did not do anything, now it moves at full speed clockwise no matter what value I give. I think the circuit is right. negatives from the servos go to gnd together with batterie and positive with positive. also th signal cables are inserted into the arduino.

Any idea what I could be doing wrong? Thanks

#include <Servo.h> 
 
Servo myservo;   
Servo myserva;  
const int button1 = 4;
const int button2 = 12;
const int button3 = 2;
const int button4 = 7;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;


void setup()
{
myservo.attach(9);
myserva.attach(5);  
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(button3,INPUT);
pinMode(button4,INPUT);
  
}

void loop()
{
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3);
  buttonState4 = digitalRead(button4);
myservo.write(91);
myserva.write(90);
if(buttonState1 == HIGH){
  myserva.write(95);}
if(buttonState2 == HIGH){
  myserva.write(89);}  
if(buttonState3 == HIGH){
  myservo.write(100);}
if(buttonState4 == HIGH){
  myservo.write(82);}  
   
}

hello, for my project i am controlling 2 servos, for this I use an extarnal 6v power source. The servos are not really working vey well, at first I had to wrtie values like 93 to stop them from moving. Then suddenly one did not stop at all, I opened the servo but did not do anything, now it moves at full speed clockwise no matter what value I give. I think the circuit is right. negatives from the servos go to gnd together with batterie and positive with positive. also th signal cables are inserted into the arduino.

Any idea what I could be doing wrong? Thanks

#include <Servo.h> 
 
Servo myservo;   
Servo myserva;  
const int button1 = 4;
const int button2 = 12;
const int button3 = 2;
const int button4 = 7;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;


void setup()
{
myservo.attach(9);
myserva.attach(5);  
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(button3,INPUT);
pinMode(button4,INPUT);
  
}

void loop()
{
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3);
  buttonState4 = digitalRead(button4);
myservo.write(91);
myserva.write(90);
if(buttonState1 == HIGH){
  myserva.write(95);}
if(buttonState2 == HIGH){
  myserva.write(89);}  
if(buttonState3 == HIGH){
  myservo.write(100);}
if(buttonState4 == HIGH){
  myservo.write(82);}  
   
}

negatives from the servos go to gnd together with batterie

And do they go to the Arduino ground as well?

What servos do you use? Datasheet please.
They are continuously rotating? And a related question: Did you modify them?

You posted this in the motors forum as well.... you shouldn't do that :roll_eyes:

Yes they do

Sorry, I was not getting any replies and I need this finished tonight.

The servo is running continious now, but what I want it to do is not continious.

I did not modify it and the site just says Servo - 360° (3.2kg/cm) and on 6 v = 630 mA and 1100 mA

And it sounds like these are continuous rotation servos? I've never used one before...

It's looping really really fast thru that loop though, so I think you'll be confusing the servos by the frequency with which you send those writes (whether the servos are normal or continuous....)

Edit....

Afaik, once a servo is continuous, that's the way it's going to stay. On a normal servo the value you send is a position, but for a continuous one, that value is the rotation speed.

Duplicate topics merged.

I'm getting really bored with saying this, but I'm going to force myself

DO NOT CROSS-POST, IT WASTES TIME

I was not getting any replies and I need this finished tonight.

Not our problem.

I added some delays if that’s what you mean, that didnt help. It’s like the signal cable doesnt influence the motor at all

But you have these in the loop:

myservo.write(91);
myserva.write(90);

so each time thru the loop, myservo for example is going to 91 followed by whatever the button tells it to do.

But if they're continuous servos, and you need normal operation, I think you're screwed anyway.

the other servo is working correctly, also with the buttons. another detail: I can only upload when the gnd is not plugged in, else it gives an error message

The servos are not really working vey well

I thought both were problematic, but now you say:

the other servo is working correctly

the other one has its issues as well, write(90) should stop them, that number varies, the wroking one need 91 atm

any suggestions for the code then? I just want the motors to do nothing untill a button is pressed, should be possible right?

timmie:
any suggestions for the code then? I just want the motors to do nothing untill a button is pressed, should be possible right?

Servo test code that has writeMicroseconds which is better with continous rotation servos.

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}