Problem controlling servo with IR .

Hello, i recently bought 2 tg9e servos, and i am trying to control them with a remote control, the problem is that once a press a button the servo goes to the specified angle but immediately returns to the initial position, and i dont think its supposed to do that, especially cause when a put weight on it with my finger it works just fine (it goes to the specified position and stays there until a next coordenate is entered).

my code (just in case):

#include <Servo.h> 
#include <IRremote.h>
 
Servo myservo;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results; 
                
int pos = 0; 
int go = 0 ;
 
void setup() 
{ 
  myservo.attach(9);
  myservo.write(pos);
  irrecv.enableIRIn();
} 
 
void loop() 
{ 
  pos = myservo.read();
  if (pos == go){
    if (irrecv.decode(&results)) {
      switch(results.value){
        case 0xE17A807F: go = 90; break;
        case 0xE17A40BF: go = 179; break;
        case 0xE17AC03F: go = 0; break;
      }
      irrecv.resume(); 
    }
  }
  else{  
      myservo.write(go);              
      delay(15);                      
  }
}

I'd appreciate any help :slight_smile:

Try something simpler

void loop()
{
    if (irrecv.decode(&results)) {
      switch(results.value){
        case 0xE17A807F: go = 90; break;
        case 0xE17A40BF: go = 179; break;
        case 0xE17AC03F: go = 0; break;
      }
      irrecv.resume();
    }
      myservo.write(go);             
      delay(15);                     
}

...R

I used your code, its smaller and works fine, but it didnt solved my problem :I, but then i switched to another usb port and everything seems to be working correctly, im not quite sure why...

Not all usb ports are created equal...

cvmcosta:
I used your code, its smaller and works fine, but it didnt solved my problem

If it did not solve the problem it cannot "work fine" - unless the problem has shifted.

but then i switched to another usb port and everything seems to be working correctly, im not quite sure why...

Perhaps this means you are powering the servo from your Arduino. Don't. Give the servo its own power supply with a common GND with the Arduino.

Does your original code work on that USB connection?

...R