Monthly Archives: March 2015

Jitter Problem ‘fixed’

So here’s my code now and I think I’ve fixed the jitter. As noted in the prior post, I moved the servo attachment down into the loop so that it doesn’t attach until a button is hit (so no jitter before then). I’ve also added a couple lines and a wire so it reboots after the servo moves (which stops the jitter of course). Considering I’ll only be using this a couple times a day at most, I think that works. I think the real solution would be to get a separate servo controller, but I’m happy with my work-around. So far it seems to work really well. I haven’t really fixed the jitter problem…just made it so that it jitters for an acceptably short period.

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

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

int RECV_PIN = 3;// initialize the digital pin as an output.
int resetPin = 12;// initialize the digital pin as an output.
IRrecv irrecv(RECV_PIN);
decode_results results;

Servo servo1;
Servo servo2;

void setup() {   // put your setup code here, to run once:
digitalWrite(resetPin, HIGH);
delay(200);
pinMode(resetPin, OUTPUT);
Serial.begin(9600); // initialize the serial port
Serial.println(“reset”);//print reset to know the program has been reset
delay(200);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {  // put your main code here, to run repeatedly:

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

if(results.value == Value1) {
servo1.attach(9); // attach servo to digital pin 9
servo1.write(5); // move to 5 degrees
delay(5000); // 5 sec delay to let motor move
digitalWrite(resetPin, LOW);//restarts board
}

if(results.value == Value2) {
servo1.attach(9); // attach servo to digital pin 9
servo1.write(175); // move to 175 degrees
delay(5000); // 5 sec delay to let motor move
digitalWrite(resetPin, LOW);//restarts board
}

}

Advertisements