IR remote control dc motor issue

Hi,

Just seem to be having an issue getting my motor to turn on when using a IR remote. I am using a BTS7960 43A moter driver board and have confirmed board is working and there is no issues using this following test code:

// Arduino code for the H_BRIDGE

int LPWM = 11; // H-bridge leg 1 ->LPWM purple wire
int enL = 12; // H-bridge enable pin 1 -> L_EN yellow wire


int RPWM = 3; // H-bridge leg 2 ->RPWM grey wire
int enR = 2; // H-bridge enable pin 2 -> R_EN brown wire

void setup()
{
  Serial.begin (9600);
  pinMode(LPWM, OUTPUT);
  pinMode(RPWM, OUTPUT);
  pinMode(enL, OUTPUT);
  pinMode(enR, OUTPUT);

  digitalWrite(enL, HIGH);
  digitalWrite(enR, HIGH);
}

void loop()
{
  analogWrite(RPWM,200); //pwm value

}

But when I try add the code into my IR remote program the motor does not turn on. The lcd is displaying the correct command when the button is pressed but the motor will not work. I cannot figure out why it does not work in the IR remote program as shown below. Any help would be appreciated.

#include <IRremote.h>
#include <LiquidCrystal.h>
const int pin_RS = 8; 
const int pin_EN = 9; 
const int pin_d4 = 4; 
const int pin_d5 = 5; 
const int pin_d6 = 6; 
const int pin_d7 = 7; 

const int pin_BL = 10; 
int receiver = A5; // Signal Pin of IR receiver to Arduino Digital Pin A5

int LPWM = 11; // H-bridge leg 1 ->LPWM purple wire
int enL = 12; // H-bridge enable pin 1 -> L_EN yellow wire


int RPWM = 3; // H-bridge leg 2 ->RPWM grey wire
int enR = 2; // H-bridge enable pin 2 -> R_EN brown wire

IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
LiquidCrystal lcd( pin_RS,  pin_EN,  pin_d4,  pin_d5,  pin_d6,  pin_d7);

void setup()   
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  lcd.begin(16, 2);
  Serial.println("READY"); 
   pinMode(LPWM, OUTPUT);
  pinMode(RPWM, OUTPUT);
  pinMode(enL, OUTPUT);
  pinMode(enR, OUTPUT);

  digitalWrite(enL, HIGH);
  digitalWrite(enR, HIGH);

 
}


void loop()  
{
 
  if (irrecv.decode(&results)) // have we received an IR signal?

  {
    translateIR(); 
    irrecv.resume(); // receive the next value
  }  
}


void translateIR() // takes action based on IR code received

// describing Remote IR codes 

{
  switch(results.value)
  {
  case 321: //change zero to your IR remote UP button number
  lcd.setCursor(0,0);      
  lcd.print("PWM SPEED = 50");
   lcd.setCursor(0,1);
  lcd.print("DIR: CW");
   analogWrite(RPWM,50); //pwm value

  
  break;
  
  case 2369: //change zero to your IR remote LEFT button number
  lcd.setCursor(0,0);      
   lcd.print("PWM SPEED = 200");
   lcd.setCursor(0,1);
   lcd.print("DIR: CW");
   analogWrite(RPWM,200); //pwm value
   
  break;
  
 
  
  default: 
  lcd.clear();
  lcd.print(" other button   ");

  }

  delay(500); // Do not get immediate repeat


}

i can't find any problems.

here's some code you can add to help you confirm things work the way you expect. customize it for your needs. Add a command to turn on the motor the same way you do with an IR code.

// pcRead - debugging using serial monitor

const char version [] = "PcRead 200416a";

int debug = 0;

// ---------------------------------------------------------
// toggle output bit
void
pinToggle (
    int pin)
{
    static int  bits = 0;
    int     bit = 1 << pin;

    if (debug)  {
        Serial.print ("pinToggle: ");
        Serial.println (pin);
    }

    if (bits & bit)  {
        digitalWrite (pin, LOW);
        bits &= ~bit;
    }
    else {
        digitalWrite (pin, HIGH);
        bits |= bit;
    }
}

// ---------------------------------------------------------
// toggle output bit
int
readString (
    char *s,
    int   maxChar )
{
    int  n = 0;

    Serial.print ("> ");
    do {
        if (Serial.available()) {
            int c    = Serial.read ();

            if ('\n' == c)
                break;

            s [n++] = c;
            if (maxChar == n)
                break;
        }
    } while (true);

    return n;
}

// -----------------------------------------------------------------------------
// process single character commands from the PC
#define MAX_CHAR  10
char s [MAX_CHAR] = {};

void
pcRead (void)
{
    static int  analogPin = 0;
    static int  val = 13;

    if (Serial.available()) {
        int c = Serial.read ();

        switch (c)  {
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            val = c - '0' + (10 * val);
            break;

        case 'A':
            analogPin = val;
            Serial.print   ("analogPin = ");
            Serial.println (val);
            val = 0;
            break;

        case 'D':
            debug ^= 1;
            break;

        case 'I':
            pinMode (val, INPUT);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" INPUT");
            val = 0;
            break;

        case 'O':
            pinMode (val, OUTPUT);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" OUTPUT");
            val = 0;
            break;

        case 'P':
            pinMode (val, INPUT_PULLUP);
            Serial.print   ("pinMode ");
            Serial.print   (val);
            Serial.println (" INPUT_PULLUP");
            val = 0;
            break;


        case 'a':
            Serial.print   ("analogRead: ");
            Serial.println (analogRead (val));
            val = 0;
            break;

        case 'c':
            digitalWrite (val, LOW);
            Serial.print   ("digitalWrite: LOW  ");
            Serial.println (val);
            val = 0;
            break;

        case 'p':
            analogWrite (analogPin, val);
            Serial.print   ("analogWrite: pin ");
            Serial.print   (analogPin);
            Serial.print   (", ");
            Serial.println (val);
            val = 0;
            break;

        case 'r':
            Serial.print   ("digitalRead: pin ");
            Serial.print   (val);
            Serial.print   (", ");
            Serial.println (digitalRead (val));
            val = 0;
            break;

        case 's':
            digitalWrite (val, HIGH);
            Serial.print   ("digitalWrite: HIGH ");
            Serial.println (val);
            val = 0;
            break;

        case 't':
            Serial.print   ("pinToggle ");
            Serial.println (val);
            pinToggle (val);
            val = 0;
            break;

        case 'v':
            Serial.print ("\nversion: ");
            Serial.println (version);
            break;

        case '\n':          // ignore
            break;

        case '"':
            while ('\n' != Serial.read ())     // discard linefeed
                ;

            readString (s, MAX_CHAR-1);
            Serial.println (s);
            break;

        case '?':
            Serial.println ("\npcRead:\n");
            Serial.println ("    [0-9] append to #");
            Serial.println ("    A # - set analog pin #");
            Serial.println ("    D # - set debug to #");
            Serial.println ("    I # - set pin # to INPUT");
            Serial.println ("    O # - set pin # to OUTPUT");
            Serial.println ("    P # - set pin # to INPUT_PULLUP");
            Serial.println ("    a # - analogRead (pin #)");
            Serial.println ("    c # - digitalWrite (pin #, LOW)");
            Serial.println ("    p # -- analogWrite (analogPin, #)");
            Serial.println ("    r # - digitalRead (pin #)");
            Serial.println ("    s   - digitalWrite (pin #, HIGH)");
            Serial.println ("    t   -- toggle pin # output");
            Serial.println ("    v   - print version");
            Serial.println ("    \"   - read string");
            Serial.println ("    ?   - list of commands");
            break;

        default:
            Serial.print ("unknown char ");
            Serial.println (c,HEX);
            break;
        }
    }
}

// -----------------------------------------------------------------------------
void
loop (void)
{
    pcRead ();
}

// -----------------------------------------------------------------------------
void
setup (void)
{
    Serial.begin(115200);

    Serial.println (version);
}

Hi,

So what exactly am I doing with that code you posted I have no idea what it. Sorry this is my 2nd day doing programming and just trying to understand the things I am reading and examples I am finding

boostn98021556:
Sorry this is my 2nd day doing programming and just trying to understand the things I am reading and examples I am finding

and asking for help as soon as things don't work after your "2nd day".

It's a forum that what it's for to be able to get information so you can piece the puzzle together quicker it's called using your available resources efficiently .

Moderator edit : removed offensive language. DO NOT DO THAT AGAIN or there may be consequences beyond the language being removed