L293D with ir help

I am using the robojax l293d motor sheild with ir but cannot get it to work.
Everything is printing to the serial monitor when its supposed to, the motors run without the ir code, but the motors are not running when their supposed to.
I am 99% sure that it is the code. Please, give me the edits I need to make.

  • Thanks!
#include <AFMotor.h>
#include <IRremote.h>

AF_DCMotor m1(1);//define motor 1 as m1
AF_DCMotor m2(2);//define motor 2 as m2
int IR_RECEIVE_PIN = 19;
void setup() {
    m1.setSpeed(0);//motor 1 is turned off to turn on change 0, to 255
  m2.setSpeed(0);//motor 2 is turned off  
    Serial.begin(9600);
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
    IrReceiver.begin(IR_RECEIVE_PIN);
    Serial.print(F("Ready to receive IR signals at pin "));
    Serial.println(IR_RECEIVE_PIN);
}

void loop() {

    /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded result is in the IrReceiver.decodedIRData structure.
     *
     * E.g. command is in IrReceiver.decodedIRData.command
     * address is in command is in IrReceiver.decodedIRData.address
     * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
     */
    if (IrReceiver.decode()) {

        // Print a short summary of received data
        IrReceiver.printIRResultShort(&Serial);
        if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
            // We have an unknown protocol here, print more info
            IrReceiver.printIRResultRawFormatted(&Serial, true);
        }


        /*
         * !!!Important!!! Enable receiving of the next value,
         * since receiving has stopped after the end of the current received data packet.
         */
        IrReceiver.resume(); // Enable receiving of the next value
                 Serial.println(IrReceiver.decodedIRData.command);
        Serial.println();
        /*
         * Finally, check the received data and perform actions according to the received command
         */
        if (IrReceiver.decodedIRData.command == 12) {
          Serial.println("Motors on");
  uint8_t i;
  
  Serial.println("Motor 1 FORWARD 100% speed");
  m1.run(FORWARD);
  m1.setSpeed(speed(100));
  Serial.println("m4 FORWARD 100%");
 m2.run(FORWARD);
 m2.setSpeed(speed(100));  
  delay(3000);
  

  
  m1.run(RELEASE);
  Serial.println("M1 RELEASE");
 m2.run(RELEASE);
  Serial.println("m4 RELEASE");  
  delay(3000); 

  

  Serial.println("M1 BACKWARD 80%");
  m1.run(BACKWARD );
  m1.setSpeed(speed(80));
  Serial.println("m4 BACKWARD 60%");
 m2.run(BACKWARD );
 m2.setSpeed(speed(60));


  delay(3000);

  
 delay(3000);
  m1.run(RELEASE);
  Serial.println("M1 RELEASE");
  m2.run(RELEASE);
  Serial.println("m4 RELEASE");  
  delay(3000);   
  Serial.println("=============");
        }
    }
}
int speed(int b)
{
  return map(b, 0, 100, 0, 255);
}

So, what shows up on Serial Monitor when you run your sketch and press your buttons? Please copy and paste all of the text from Serial Monitor.

consider pasting a schematic, not a frizzy thing with links to the technical information on the hardware parts. I would also suggest start from the beginning and just make the motor operate properly first. Doing this will eliminate most of the potential hardware problems.

I have tested the motor with the motor driver on its own dozens of times and will send out the hardware specifications and schematics later!

What platform are you running this on, and why do you think 19 is the correct receive pin?

Did you do this with the same pin assignments you are using in your project. Did the micro actually control it?

I am using arduino ide and I thought that pin 19 would definnetly be available

Yes, and yes.

I believe there is a conflict with the timers used to generate the motor pwm and the timer used for the IR receive.
My thinking is that they are both using Timer2.

I think if you use motor3 and motor4 you will use Timer0 at some higher frequency and loose the millis() timing.

The read me for the IRremote library
https://github.com/Arduino-IRremote/Arduino-IRremote
has a section about changing the timer used by the library.

I think you want to modify the library file on your computer. You will need to find the library file called
private/IRTimer.hpp and change this section to use Timer1 instead of Timer2.

* Plain AVR CPU's, no boards
 ***************************************/
// Arduino Duemilanove, Diecimila, LilyPad, Mini, Fio, Nano, etc
// ATmega328
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328PB__) || defined(__AVR_ATmega168__)
#  if !defined(IR_USE_AVR_TIMER1) && !defined(IR_USE_AVR_TIMER2)
//#define IR_USE_AVR_TIMER1   // send pin = pin 9
#define IR_USE_AVR_TIMER2     // send pin = pin 3
#  endif

Change these two lines.

#define IR_USE_AVR_TIMER1   // send pin = pin 9
//#define IR_USE_AVR_TIMER2     // send pin = pin 3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.