robot arm 3 servo control problem

i just try to control 3 servo engines. I send a data to first servo. i want to move only first but second and third engine work with it too its not complete work but 2nd and 3rd servo engines just vibrating and try to move. How can i fix that problem ? could you help me (Y)

//arduino code

#include <Servo.h>
Servo alt,kol,ust;
static int pos=0,apos=0,upos=0;

void setup()
{
  Serial.begin(9600);
  kol.attach(9);  // attaches the servo on pin 9 to the servo object
  alt.attach(3);
  ust.attach(6);
  
}
void loop()
{
 
 if(Serial.available() > 0)
  {
    char gelen = Serial.read();
    
    if(gelen == 'a')
    {
      while(Serial.available() <1)
            ; // wait for a character
      pos=0;
      do{
         gelen = Serial.read();    
        if(gelen >= '0' && gelen <= '9')              // is ch a number?  
          pos = pos * 10 + gelen - '0';           // yes, accumulate the value
      
    }
      while(gelen != 'b'); 
      kol.write(pos);
      pos = 0; 

      
    }
    
    else if(gelen == 'c')
    {
      while(Serial.available() <1)
            ; // wait for a character
      apos=0;
      do{
         gelen = Serial.read();    
        if(gelen >= '0' && gelen <= '9')             
          apos = apos * 10 + gelen - '0';
          
      }
      while(gelen != 'd'); 
      alt.write(apos);
      apos = 0; 
      
      
      }
    
    else
    {
      while(Serial.available() <1)
            ; // wait for a character
      upos=0;
      do{
         gelen = Serial.read();    
        if(gelen >= '0' && gelen <= '9')             
          upos = upos * 10 + gelen - '0'; 
             
      }
      while(gelen != 'f'); 
      ust.write(upos);
      upos = 0; 
      
    }
    }

  }

c# code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            serialPort1.PortName = "COM4";
            serialPort1.BaudRate = 9600;

            
            
         
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            serialPort1.Open();
            label1.Text = trackBar1.Value.ToString();
            serialPort1.Write("e");
            serialPort1.Write(trackBar1.Value.ToString());
            serialPort1.Write("f");
            serialPort1.Close();
    
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            serialPort1.Open();
            label2.Text = trackBar2.Value.ToString();
            serialPort1.Write("c");
            serialPort1.Write(trackBar2.Value.ToString());
            serialPort1.Write("d");
            serialPort1.Close();
            
        }

        private void trackBar3_Scroll(object sender, EventArgs e)
        {
            serialPort1.Open();
            label3.Text = trackBar3.Value.ToString();
            serialPort1.Write("a");
            serialPort1.Write(trackBar3.Value.ToString());
            serialPort1.Write("b");
            serialPort1.Close();
            
        }

       

       
    }
}
  kol.attach(9);  // attaches the servo on pin 9 to the servo object
  alt.attach(3);
  ust.attach(6);

It is not necessary to attach the servos to PWM pins.

It is necessary, though, to tell us how the servos are powered.

      do{
         gelen = Serial.read();    
        if(gelen >= '0' && gelen <= '9')              // is ch a number?  
          pos = pos * 10 + gelen - '0';           // yes, accumulate the value
      
    }
      while(gelen != 'b');

It's advisable to wait for serial data to arrive.

What is sending the serial data?
Edit: Never mind. I see that you have a C# application mishandling the communication. Are you aware that opening the serial port resets the Arduino? Are you aware that closing the serial port resets the Arduino? You should be. You should re-write your C# application so that happens ONCE each, not every time you want to send data.

new aplication still problem.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            serialPort1.PortName = "COM4";
            serialPort1.BaudRate = 9600;
            serialPort1.Open();
            
            
         
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            
            label1.Text = trackBar1.Value.ToString();
            serialPort1.Write("e");
            serialPort1.Write(trackBar1.Value.ToString());
            serialPort1.Write("f");
            
    
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            
            label2.Text = trackBar2.Value.ToString();
            serialPort1.Write("c");
            serialPort1.Write(trackBar2.Value.ToString());
            serialPort1.Write("d");
            
            
        }

        private void trackBar3_Scroll(object sender, EventArgs e)
        {
           
            label3.Text = trackBar3.Value.ToString();
            serialPort1.Write("a");
            serialPort1.Write(trackBar3.Value.ToString());
            serialPort1.Write("b");
            
            
        }

       

       
    }
}

Your logic seems rather incomprehensible, but the most likely reason for your problem, is inadequate power supply for the servos.

Don't power servos directly from the arduino. Below is a typical way to power servos.

what kind of cabling are you using? how long are your signal wires? and what make/model are those servos??

I don't have the appetite for studying long lengths of code but the semi-colon on the first line of this looks suspicious (from your original post)

 while(gelen != 'd'); 
      alt.write(apos);
      apos = 0;

Also it looks like there are opening curly brackets without matching closing brackets.

Plus (of course) the other comments about how things are wired up.

...R

there is no problem with 2 engines but there is problem with 3 engines.

1x TowerPro SG90 Servo Specifications and Reviews

2x TowerPro MG946R Servo Specifications and Reviews

there is no problem with 2 engines but there is problem with 3 engines.

But you are not going to tell us how they are wired. Well, we are not going to tell you how to solve your problem, then, either.

You say that you can only get two of them to run simultaneously, and when a third is added the 2nd and 3rd start to shiver??

are you referring to both of the MG946R servos start shivering? or the SG-90 and one of the MG946Rs?

also i see they are rated from 4.8 to 7.2 Vin.
so have you tried:
trimming your servo input voltage to 4.9v and test.
trimming your servo input voltage to 5.1v and test.
does that make any difference??

I found with some servos that the signal's amplitude is somewhat dependent on the input voltage.

one thing to try is maybe adding some hefty sized caps across your positive and negative rails.

but what are you using to power these servos (a variable bench PS, wall transformer, LDO)???

and a few questions about whats in your toolbox:

Do you have access to an oscilloscope of any kind??

and most importantly, do you have a DMM handy???

Best of luck!!!