Software: Controlling the first Servo (jitter problems)

I’m referencing this site again. Here’s the code I’m using:

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

unsigned long Value2 = 0x7B8; // RED button where 7B8 is on our your remote’s values.
unsigned long Value1 = 0x78B; // YELLOW button where 78B is another button on your remote

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(2);
}

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

}

Note that it still has the code to continue to print the hex values.

If you look at the site and compare it to my code, you’ll note there’s a typo on the site when it references Value1 and Value2 at the bottom of the code (site references Value1 both times).

And it works!  one button turns it one way, and the other button turns it the other way.

The only problem I’m having is that there’s significant jitter that I know it would bug me. I’ve Googled around it likes like an issue with the Arduino’s timer (above my head really). I tried the smaller servo just to see what would happen and I have the same jitter. There’s someone out there on this site who suggests using a 100pF capacitor (here’s another site that talks about it). Guess I need to buy some. I can get 50 for $1.60 on ebay (from China) or 100 for $3.00 (from the US). I need like 5 of them – ha.  Considering my last China purchase took about 40 days to get to me, I’m going with the $3.  I’m not terribly sure they’ll work for me, but for $3, its a decent gamble.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: