comptek4
Published © GPL3+

IR Remote Control Car - Updated

This is a project I built from an item I found on Instructables author nipon4666 that I tweaked to correct an issue with high speed motors

BeginnerFull instructions provided9,214
IR Remote Control Car - Updated

Things used in this project

Hardware components

WINGONEER New Style Infrared IR Wireless Remote Control Sensor Module Kits for Arduino
×1
SainSmart L298N Dual H Bridge Stepper Motor Driver
×1
4WD Robot Car Chassis Kit
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Wire Diagram

Code

IR Remote control car

C#
#include <IRremote.h>

char command;
int receiver_pin = 4;   //Connect the output pin of IR receiver at pin 4
int vcc = 5;            //VCC for IR sensor
int gnd = 6;            //GND for IR sensor

int statusled = 13;

IRrecv irrecv(receiver_pin);

decode_results results;


// connect motor controller pins to Arduino digital pins
// motor A
int enA = 8;
int in1 = 12;
int in2 = 11;
// motor B
int enB = 7;
int in3 = 10;
int in4 = 9;


void setup()

{
Serial.begin(9600);

irrecv.enableIRIn();

pinMode(statusled,OUTPUT);

digitalWrite(statusled,LOW);

// set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(vcc, OUTPUT);
  pinMode(gnd, OUTPUT);
  
// Initializing vcc pin high
  digitalWrite(vcc, HIGH);



}

void loop() {

if (irrecv.decode(&results)) {

digitalWrite(statusled,LOW);

irrecv.resume();

if (results.value == 0xFF18E7){ // type button 2 forward robot control

 // this function will run the motors in both directions at a fixed speed
 Serial.println("Button 2");
  // turn on motor A
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);



}else if(results.value == 0xFF10EF){ // type button 4 turn left robot control 

 // this function will run motor A in forward directions  motor B stop
  Serial.println("Button 4");
  // turn on motor A
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);
  

}else if(results.value == 0xFF30CF){ // type button 1 rotate left robot control 

 // this function will run motor A in forward directions  motor B in backward directions
  Serial.println("Button Turn Right");
  // turn on motor A
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);
  

}else if(results.value == 0xFF5AA5){ // type button 6 turn right robot control 

// this function will  stop motor A  run motor B in forward directions 
 Serial.println("Button Turn Left");
  // turn on motor A
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);

}else if(results.value == 0xFF7A85){ // type button 3 rotate right robot control 

// this function will run motor A  in backward directions  motor B in forward directions 
  // turn on motor A
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);

} else if(results.value == 0xFF4AB5){ // type button 8 backward robot control

// this function will run motor A and motor B in backward directions 
  // turn on motor A
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);



}else if(results.value == 0xFF38C7){ // type button 5 stop robot control 


// this function will stop both motor A and motor B 
  // turn on motor A
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enA, 100);
  // turn on motor B
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
  // set speed to 200 out of possible range 0~255
  analogWrite(enB, 100);
  


}

}

}

Credits

comptek4

comptek4

0 projects • 10 followers

Comments