#include <IRremote.h>
const byte IR_RECEIVE_PIN = 4;
#define LeftWheelForwardTerminal1 5
#define LeftWheelForwardTerminal2 6
#define LeftWheelBackwardTerminal1 7
#define LeftWheelBackwardTerminal2 8
#define RightWheelForwardTerminal1 9
#define RightWheelForwardTerminal2 10
#define RightWheelBackwardTerminal1 11
#define RightWheelBackwardTerminal2 12
void setup()
{
pinMode(LeftWheelForwardTerminal1,OUTPUT);
pinMode(LeftWheelForwardTerminal2,OUTPUT);
pinMode(LeftWheelBackwardTerminal1,OUTPUT);
pinMode(LeftWheelBackwardTerminal2,OUTPUT);
pinMode(RightWheelForwardTerminal1,OUTPUT);
pinMode(RightWheelForwardTerminal2,OUTPUT);
pinMode(RightWheelBackwardTerminal1,OUTPUT);
pinMode(RightWheelBackwardTerminal2,OUTPUT);
digitalWrite(RightWheelForwardTerminal1,LOW);
digitalWrite(RightWheelForwardTerminal2,LOW);
digitalWrite(RightWheelBackwardTerminal1,LOW);
digitalWrite(RightWheelBackwardTerminal2,LOW);
digitalWrite(LeftWheelForwardTerminal1,LOW);
digitalWrite(LeftWheelForwardTerminal2,LOW);
digitalWrite(LeftWheelBackwardTerminal1,LOW);
digitalWrite(LeftWheelBackwardTerminal2,LOW);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}
void loop()
{
if (IrReceiver.decode())
{
IrReceiver.resume();
if(IrReceiver.decodedIRData.command==78) //Forward
{
Serial.println("Moving forward");
digitalWrite(LeftWheelBackwardTerminal1,LOW);
digitalWrite(LeftWheelBackwardTerminal2,LOW);
digitalWrite(RightWheelBackwardTerminal1,LOW);
digitalWrite(RightWheelBackwardTerminal2,LOW);
digitalWrite(LeftWheelForwardTerminal1,HIGH);
digitalWrite(LeftWheelForwardTerminal2,HIGH);
digitalWrite(RightWheelForwardTerminal1,HIGH);
digitalWrite(RightWheelForwardTerminal2,HIGH);
}
else if(IrReceiver.decodedIRData.command==4) //Backward
{
Serial.println("Moving backward");
digitalWrite(LeftWheelForwardTerminal1,LOW);
digitalWrite(LeftWheelForwardTerminal2,LOW);
digitalWrite(RightWheelForwardTerminal1,LOW);
digitalWrite(RightWheelForwardTerminal2,LOW);
digitalWrite(LeftWheelBackwardTerminal1,HIGH);
digitalWrite(LeftWheelBackwardTerminal2,HIGH);
digitalWrite(RightWheelBackwardTerminal1,HIGH);
digitalWrite(RightWheelBackwardTerminal2,HIGH);
}
else if(IrReceiver.decodedIRData.command==6) //Left
{
Serial.println("Turning left");
digitalWrite(RightWheelForwardTerminal1,LOW);
digitalWrite(RightWheelForwardTerminal2,LOW);
digitalWrite(RightWheelBackwardTerminal1,LOW);
digitalWrite(RightWheelBackwardTerminal2,LOW);
digitalWrite(LeftWheelForwardTerminal1,HIGH);
digitalWrite(LeftWheelForwardTerminal2,HIGH);
}
else if(IrReceiver.decodedIRData.command==7) //Right
{
Serial.println("Turning right");
digitalWrite(LeftWheelForwardTerminal1,LOW);
digitalWrite(LeftWheelForwardTerminal2,LOW);
digitalWrite(LeftWheelBackwardTerminal1,LOW);
digitalWrite(LeftWheelBackwardTerminal2,LOW);
digitalWrite(RightWheelForwardTerminal1,HIGH);
digitalWrite(RightWheelForwardTerminal2,HIGH);
}
else if(IrReceiver.decodedIRData.command==5) // Brake
{
Serial.println(" On brake");
digitalWrite(LeftWheelForwardTerminal1,LOW);
digitalWrite(LeftWheelForwardTerminal2,LOW);
digitalWrite(LeftWheelBackwardTerminal1,LOW);
digitalWrite(LeftWheelBackwardTerminal2,LOW);
digitalWrite(RightWheelForwardTerminal1,LOW);
digitalWrite(RightWheelForwardTerminal2,LOW);
digitalWrite(RightWheelBackwardTerminal1,LOW);
digitalWrite(RightWheelBackwardTerminal2,LOW);
}
}
}
Comments