/* Pat McMahon -V27 REmote M (AIWA)- IR Only -29/9/2024 Code from Ai CHATGP asking the following;- "Using the arduino IDE write code for a 2WD/4WD wheel robot to be run with the M IR Remote with connections IR=pin 2,in1=10,in2=9,in3=6,in4=5, front lights=3,middle lights=13, back lights=4,horn=11 with forward=In 4&2,backwards=In 3&1,Left=2&3,Right=In4&1" 10-9-6-5 Buzzer 11 Pat's V27 Final Ai-IR Only Combo 2/4 Wheel Drive Finger On to Run, "OK" centre button to Stop. This IR Sketch is controlled by IR Remote M. There was a conflict using PWM pin 11 when you combined both BT & IR, IR Library Timer conflicts with analogWrite with pin 11? Modified by Pat McMahon (V11) 6/7/2024, in1=10,in2=9,in3=6,in4=5, added Front pin 3, Middle extra pin 13,Back Lights pin 4,HORN pin 11. */ #include // Pin definitions const int irPin = 2; const int in1 = 10; const int in2 = 9; const int in3 = 6; const int in4 = 5; const int frontLightPin = 3; const int middleLightPin = 13; const int backLightPin = 4; const int hornPin = 11; // Create IR receiver object IRrecv irrecv(irPin); decode_results results; // Function prototypes void setupMotors(); void stopMotors(); void forward(); void backward(); void turnLeft(); void turnRight(); void handleIR(); void controlLights(bool front, bool middle, bool back); void controlHorn(bool state); void setup() { // Initialize serial communication for debugging Serial.begin(9600); // Initialize IR receiver irrecv.enableIRIn(); // Initialize motor, light, and horn pins setupMotors(); pinMode(frontLightPin, OUTPUT); pinMode(middleLightPin, OUTPUT); pinMode(backLightPin, OUTPUT); pinMode(hornPin, OUTPUT); } void loop() { // Check for IR input handleIR(); } void setupMotors() { pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); stopMotors(); } void stopMotors() { digitalWrite(in1, LOW); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, LOW); } void forward() { digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } void backward() { digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } void turnLeft() { digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, HIGH); digitalWrite(in4, LOW); } void turnRight() { digitalWrite(in1, HIGH); digitalWrite(in2, LOW); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); } void handleIR() { if (irrecv.decode(&results)) { unsigned long value = results.value; irrecv.resume(); // Replace these values with the actual IR codes from your remote ( I replaced with my Remote M Codes) switch (value) { case 0x2F0: forward(); break; // Replace with actual code for forward case 0xAF0: backward(); break; // Replace with actual code for backward case 0x2D0: turnLeft(); break; // Replace with actual code for left turn case 0xCD0: turnRight(); break; // Replace with actual code for right turn case 0xA70: stopMotors(); break; // Replace with actual code for stop case 0xF38: controlLights(true, false, false); break; // Replace with actual code for front lights case 0x738: controlLights(false, true, false); break; // Replace with actual code for middle lights case 0x338: controlLights(false, false, true); break; // Replace with actual code for back lights case 0x5EE9: controlLights(false, false, false); break; // Replace with actual code for back lights case 0xB38: controlHorn(true); break; // Replace with actual code for horn on case 0xCE9: controlHorn(false); break; // Replace with actual code for horn off //default: stopMotors(); break; I removed this from the code to make it work. } } } void controlLights(bool front, bool middle, bool back) { digitalWrite(frontLightPin, front ? HIGH : LOW); digitalWrite(middleLightPin, middle ? HIGH : LOW); digitalWrite(backLightPin, back ? HIGH : LOW); } void controlHorn(bool state) { digitalWrite(hornPin, state ? HIGH : LOW); }