IR Remote

From STEAMwiki
Jump to: navigation, search

Need to first install the IR_Remote Library [1]


#include <IRremote.h>
int RECV_PIN = 11;
unsigned long ID;
IRrecv irrecv(RECV_PIN);
decode_results results;


//ENTER THE PINS THE MOTOR DRIVERS ARE ATTACHED TO
#define MOTORPIN1 1
#define MOTORPIN2 2
#define MOTORPIN3 3
#define MOTORPIN4 4

//ENTER THE IDs FOR THE BUTTONS (*as unsigned long*)
#define forwardID 16753245
#define backwardID 16736925 
#define leftID 16769565
#define rightID 16720605 


void forward() {
  //put the code to move the robot forward here:
  
}

void backward() {
  //put the code to move the robot backward here:
  
}

void left() {
  //put the code to turn the robot left here:
  
}

void right() {
  //put the code to turn the robot right here:
  
}












void setup()
{

  // Setting motor pins as outputs
  pinMode (MOTORPIN1, OUTPUT);
  pinMode (MOTORPIN2, OUTPUT);
  pinMode (MOTORPIN3, OUTPUT);
  pinMode (MOTORPIN4, OUTPUT);
  
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  IR_enable();

// Remote Logic
  if (ID == forwardID){
    forward();
  } else if (ID == backwardID){
    backward();
  } else if (ID == leftID){
    left();
  } else if (ID == rightID){
    right();
  }  
}


// Begin the IR
void IR_enable() {
  if (irrecv.decode(&results)) {
    ID = results.value;
    Serial.println(ID);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}