Muhammad_Munir
Published © GPL3+

Robotic Car controlled over IR Remote

How to make A Simple CAR Controlled with IR Remote

IntermediateFull instructions provided6,443
Robotic Car controlled over IR Remote

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
IR Receiver
×1
Gear motor
×2
L298 motor driver
×1
5 mm LED: Yellow
5 mm LED: Yellow
×2
High Brightness LED, White
High Brightness LED, White
×2
12 Volt Battery
×1
TV Remote
×1
Jumper wires (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Code

Arduino
#include <IRremote.h>

/* define IR sensor pin */
int IRsensorPin = 12;

/* define the some functions used by the library */
IRrecv irrecv(IRsensorPin);
decode_results results;

/* define L298N motor drive control pins */
int RightMotorForward = 2;    // IN1
int RightMotorBackward = 3;   // IN2
int LeftMotorForward = 4;     // IN3
int LeftMotorBackward = 5;    // IN4
int LeftLED = 6;
int RightLED = 7;

void setup(){
  
  /* initialize motor control pins as output */
  pinMode(LeftMotorForward,OUTPUT);
  pinMode(RightMotorForward,OUTPUT);
  pinMode(LeftMotorBackward,OUTPUT);
  pinMode(RightMotorBackward,OUTPUT);
  pinMode(LeftLED,OUTPUT);
  pinMode(RightLED,OUTPUT);

  /* start serial communication to see hex codes */
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop(){
  
  /* if the sensor is receive any signal */
  if (irrecv.decode(&results)){
    
    /* print the hex code value on the serial monitor */
    Serial.println(results.value);
    delay(5);

    /* resume function according to hex code */
    irrecv.resume();
  }
 
  if(results.value == 752) MotorForward();
  if(results.value == 2800) MotorBackward();
  if(results.value == 3280) TurnRight();
  if(results.value == 720) TurnLeft();
  if(results.value == 2672) MotorStop();
  
}

/* FORWARD */
void MotorForward(){
  digitalWrite(LeftLED,LOW);
  digitalWrite(RightLED,LOW);
  digitalWrite(LeftMotorForward,HIGH);
  digitalWrite(RightMotorForward,HIGH);
  digitalWrite(LeftMotorBackward,LOW);
  digitalWrite(RightMotorBackward,LOW); 
}

/* BACKWARD */
void MotorBackward(){
  digitalWrite(LeftLED,LOW);
  digitalWrite(RightLED,LOW);
  digitalWrite(LeftMotorBackward,HIGH);
  digitalWrite(RightMotorBackward,HIGH);
  digitalWrite(LeftMotorForward,LOW);
  digitalWrite(RightMotorForward,LOW);
}

/* TURN RIGHT */
void TurnRight(){
  digitalWrite(LeftLED,LOW);
  digitalWrite(LeftMotorForward,HIGH); 
  digitalWrite(RightMotorForward,LOW);
  digitalWrite(LeftMotorBackward,LOW);
  digitalWrite(RightMotorBackward,HIGH);
  digitalWrite(RightLED,HIGH);
}

/* TURN LEFT */
void TurnLeft(){
  digitalWrite(RightLED,LOW);
  digitalWrite(RightMotorForward,HIGH);  
  digitalWrite(LeftMotorForward,LOW);
  digitalWrite(LeftMotorBackward,HIGH);
  digitalWrite(RightMotorBackward,LOW);
  digitalWrite(LeftLED,HIGH);
}

/* STOP */
void MotorStop(){
  digitalWrite(LeftLED,LOW);
  digitalWrite(RightLED,LOW);
  digitalWrite(LeftMotorBackward,LOW);
  digitalWrite(RightMotorBackward,LOW);
  digitalWrite(LeftMotorForward,LOW);
  digitalWrite(RightMotorForward,LOW);
}

Credits

Muhammad_Munir

Muhammad_Munir

77 projects • 48 followers
I am Arduino programmer, also expertise in ESP32 and 8266 wifi modules.

Comments