sketch works for servo SG-5010, but not MG90S

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
heathsmith
 
Posts: 10
Joined: Tue Jun 25, 2013 4:51 pm

sketch works for servo SG-5010, but not MG90S

Post by heathsmith »

Hello, I'm having a servo problem that I'm hoping someone can help me with. I bought two servos from Adafruit, SG-5010 and MG90S. When I do the 'Sweep' example sketch, they both work fine (tested separately of course).

My problem is when I try to use my own sketch...which works just fine for the SG-5010, but it doesn't work with MG90S. (I'm trying to control a servo with buttons on my TV remote - one button to move to 5 degrees, one button to move to 175 degrees). The only effect for the MG90S, is that when the Arduino powers up, there will be some servo jitter, but when I hit either button, the jitter stops. Again, the sketch works as intended on the SG-5010.

I've tried it powering the Arduino through both a computer USB and through a 9v 500mA power supply. I've also tried it on pins 9 and 12.

Here is my sketch:

Code: Select all

#include <Servo.h>
#include <IRremote.h>

unsigned long Value2 = 0x7B8; // where 7B8 is the remote button's values [RED button]
unsigned long Value1 = 0x78B; // where 78B is another button on the remote [YELLOW button]

int RECV_PIN = 3;
IRrecv irrecv(RECV_PIN);
decode_results results;
 
 
Servo servo1;

// the setup routine runs once when you press reset:
void setup() {              

Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

  // initialize the digital pin as an output.

servo1.attach(12); // attach servo to digital pin 12
}
// the loop routine runs over and over again forever:
void loop() {

if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }

if(results.value == Value1) {
servo1.write(5);
}

if(results.value == Value2) {
servo1.write(175);
}

}
Anyone have any ideas?
thanks!
Last edited by Franklin97355 on Wed Aug 27, 2014 1:14 pm, edited 1 time in total.
Reason: Added [code] tags

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: sketch works for servo SG-5010, but not MG90S

Post by adafruit_support_bill »

Try adding a delay in your loop. 15-20ms should be sufficient. Some servos are more fussy about the update rate for the servo pulse.

User avatar
heathsmith
 
Posts: 10
Joined: Tue Jun 25, 2013 4:51 pm

Re: sketch works for servo SG-5010, but not MG90S

Post by heathsmith »

Thanks for your help, but still no luck. The below sketch works fine for the SG-5010, but still not the MG90S. The only other thing I noticed is that when doing the Sweep example, the MG90S only rotates about 95-100 degrees...considerably less than the SG-5010. Below I highlighted my additions (i tried delays of 15 and 20).

Thanks again



#include <Servo.h>
#include <IRremote.h>

unsigned long Value2 = 0x7B8; // where 7B8 is the remote button value [RED button]
unsigned long Value1 = 0x78B; // where 78B is the other button value [YELLOW button]

int RECV_PIN=3;
IRrecv irrecv(RECV_PIN);
decode_results results;


Servo servo1;

// the setup routine runs once when you press reset:
void setup() {

Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

// initialize the digital pin as an output.

servo1.attach(9); // attach servo to digital pin 9
}
// the loop routine runs over and over again forever:
void loop() {

if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}

if(results.value == Value1) {
servo1.write(5);
delay(20);
}

if(results.value == Value2) {
servo1.write(175);
delay(20);
}

}

EDIT: As a wild guess, I also tried moving the delay down below the individual 'if' statements (so between the last two brackets) with no luck ....so my last three lines looked like this:
}
delay(20);
}

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: sketch works for servo SG-5010, but not MG90S

Post by adafruit_support_bill »

the MG90S only rotates about 95-100 degrees
Sounds like a bad one. If you contact [email protected] with a link to this thread we can send you another.

User avatar
heathsmith
 
Posts: 10
Joined: Tue Jun 25, 2013 4:51 pm

Re: sketch works for servo SG-5010, but not MG90S

Post by heathsmith »

thank you so much.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”