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.
- IR remote control.
- 2 Li-Ion 3.7V/2600mAh rechargeble batteries.
- A switch with 3 terminals and 1 pole.
- 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.
Wheels that fit on servos were 3D printed.
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);
}
}