1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Arduino ir remote truck

Discussion in 'Arduino' started by be80be, Nov 30, 2017.

  1. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,869
    Likes:
    144
    Location:
    morristown,tn
    Figured I share code I did to control a toy dump truck.

    Code is for NEC 1 remote
    Code (text):

    nt enablePin = 5;
    int in1Pin = 10;
    int in2Pin = 11;
    int enablePin1 = 6;
    int in3Pin = 8;
    int in4Pin = 9;
    #include "IRLibDecodeBase.h"
    #include "IRLibSendBase.h"
    #include "IRLib_P01_NEC.h"
    #include "IRLibCombo.h"
    #include "IRLibRecv.h"
    #include "IRLibRecvLoop.h"
    #include "IRLibRecvPCI.h"
    #include "IRLibFreq.h"
    IRrecv myReceiver(2);//receiver on pin 2
    IRdecode myDecoder;//Decoder object

    void setup()
    {
      pinMode(in1Pin, OUTPUT);
      pinMode(in2Pin, OUTPUT);
      pinMode(in3Pin, OUTPUT);
      pinMode(in4Pin, OUTPUT);
      pinMode(enablePin, OUTPUT);
      pinMode(enablePin1, OUTPUT);
      myReceiver.enableIRIn(); // Start the receiver
    }

    void loop() {
      if (myReceiver.getResults()) {
        if(myDecoder.decode()){
        if (myDecoder.protocolNum == NEC) {
          switch (myDecoder.value) {
            case 0xFF50AF:  //up
              digitalWrite(in3Pin, LOW);
              digitalWrite(in4Pin, HIGH);
              digitalWrite(enablePin1, HIGH);
              break;
            case 0xFF7887:  //down
              digitalWrite(in3Pin, HIGH);
              digitalWrite(in4Pin, LOW);
              digitalWrite(enablePin1, HIGH);
              break;
           case 0xFFA05F:  //forward
            digitalWrite(in1Pin,LOW);
            digitalWrite(in2Pin, HIGH);
            digitalWrite(enablePin,HIGH);
              break;
           case 0xFF40BF:  //backward
            digitalWrite(in1Pin,HIGH);
            digitalWrite(in2Pin, LOW);
            digitalWrite(enablePin,HIGH);
              break;
            case 0xFF02FD:  //backward
            digitalWrite(enablePin1, LOW);
            digitalWrite(enablePin,LOW);
              break;
          }
         
        }
       }
      myReceiver.enableIRIn(); //Restart the receiver
     }
    }
     
    If you want the whole thing I'll post the motor controller too. It's still in my head LOL
     

Share This Page