0% found this document useful (0 votes)
10 views4 pages

IR Remote Control Car

The document is an Arduino code for controlling a robot using an IR remote. It defines motor control pins and sets up the IR receiver to interpret commands from the remote, allowing the robot to move forward, backward, turn left, turn right, and stop based on specific button presses. The code includes setup and loop functions to handle the motor operations and IR signal decoding.

Uploaded by

sifa.s.s.9895
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

IR Remote Control Car

The document is an Arduino code for controlling a robot using an IR remote. It defines motor control pins and sets up the IR receiver to interpret commands from the remote, allowing the robot to move forward, backward, turn left, turn right, and stop based on specific button presses. The code includes setup and loop functions to handle the motor operations and IR signal decoding.

Uploaded by

sifa.s.s.9895
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#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()

{
[Link](9600);

[Link]();

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 ([Link](&results)) {

digitalWrite(statusled,LOW);
[Link]();

if ([Link] == 0xFF18E7){ // type button 2 forward robot control

// this function will run the motors in both directions at a fixed speed
[Link]("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([Link] == 0xFF10EF){ // type button 4 turn left robot control

// this function will run motor A in forward directions motor B stop


[Link]("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([Link] == 0xFF30CF){ // type button 1 rotate left robot control

// this function will run motor A in forward directions motor B in backward


directions
[Link]("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([Link] == 0xFF5AA5){ // type button 6 turn right robot control

// this function will stop motor A run motor B in forward directions


[Link]("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([Link] == 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([Link] == 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([Link] == 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);

}
}

You might also like