The IR vehicle is a simple project, a car with Arduino, that receives an infrared signal from a remote control to control 2 servomotors.
IR vehicle material list
- Arduino Uno.
- IR receiver module KY-022.
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/Receptor-IR-frente-1.jpg)
- IR remote control.
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/IR-remote-control-1.jpg)
- 2 Li-Ion 3.7V/2600mAh rechargeble batteries.
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/batteries-1-1024x573.png)
- A switch with 3 terminals and 1 pole.
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/switch-1.png)
- Wires for connection between components.
- 2 SM-S4303R Springrc servomotors, which can turn 360º, like a common motor. Only servos with this feature can be used in this project.
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/servomotor-1.png)
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/schematics-1.png)
Wheels that fit on servos were 3D printed.
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/wheels1-1.png)
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/wheels2-1-1024x510.png)
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/used-PCI-2.png)
![](https://www.electricalelibrary.com/wp-content/uploads/2024/01/IR-car-destaque-1.png)
Algorithm
This code uses commands seen in 3 and 8 parts of Arduino tutorial.
#include <IRremote.h>
#include <Servo.h>
#define IR_RECEIVE_PIN 8
Servo servo1,servo2;
int posservo1,posservo2;
void setup(){
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN);
servo1.attach(5);
servo2.attach(6);
servo1.write(90);
servo2.write(90);
}
void loop(){
if (IrReceiver.decode()) {
IrReceiver.resume();
Serial.println(IrReceiver.decodedIRData.command);
}
if(IrReceiver.decodedIRData.command==22){
servo1.write(60);
}
else if(IrReceiver.decodedIRData.command==12){
servo1.write(90);
}
else if(IrReceiver.decodedIRData.command==8){
servo1.write(140);
}
else if(IrReceiver.decodedIRData.command==90){
servo2.write(70);
}
else if(IrReceiver.decodedIRData.command==94){
servo2.write(90);
}
else if(IrReceiver.decodedIRData.command==13){
servo2.write(130);
}
}