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);
}
}
thanks!