CONTROL SERVO BY IR REMOTE

Servo remote IR

#include <IRremote.h> //must copy IRremote library to arduino libraries

#include <Servo.h>

#define plus 0xEF10609F //clockwise rotation button

#define minus 0xEF10E01F //counter clockwise rotation button

int RECV_PIN = 14; //IR receiver pin, pin A0

Servo servo;

int val; //rotation angle

bool cwRotation, ccwRotation; //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()

{

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

servo.attach(15); //servo pin, pin A1

}

void loop()

{

if (irrecv.decode(&results)) {

Serial.println(results.value, HEX);

irrecv.resume(); // Receive the next value

if (results.value == plus)

{

servo.write(180);

delay(1);//controlling speed

}

if (results.value == minus)

{

servo.write(0);

delay(1);

}

}

}

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s