/* Pat McMahon -V24 NEC Mini Remote - 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 NEC 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=In 2&3,Right=In 4&1" 10-9-6-5 Buzzer 11 Pat's V24 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 Mini NEC. Modified Ai code by Pat McMahon (V24) 29/9/2024, REMOVED"default: stopMotors(); break;" I removed this as the mini NEC remote only worked intermittely with it in the code. */ #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 0xFF18E7: forward(); break; // Replace with actual code for forward case 0xFF4AB5: backward(); break; // Replace with actual code for backward case 0xFF10EF: turnLeft(); break; // Replace with actual code for left turn case 0xFF5AA5: turnRight(); break; // Replace with actual code for right turn case 0xFF38C7: stopMotors(); break; // Replace with actual code for stop case 0xFFA25D: controlLights(true, false, false); break; // Replace with actual code for front lights case 0xFF629D: controlLights(false, true, false); break; // Replace with actual code for middle lights case 0xFFE21D: controlLights(false, false, true); break; // Replace with actual code for back lights case 0xFF6897: controlHorn(true); break; // Replace with actual code for horn on case 0xFFB04F: controlHorn(false); break; // Replace with actual code for horn off //default: stopMotors(); break;//I removed this as the mini NEC remote only worked intermittely with it in the code. } } } 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); }