Arduino IR Receiver and BTS7960

Hello,
I am currently working on a small project with an infrared receiver and a BTS7960 DC motor controller. The motor controller is connected to an external 24V DC power supply. The arduino is connected to my PC. I have two different programs. The first is only for testing the function of the motor. The second program is for activating the motor with the IR receiver. The only reason I am using two different programs, is to compare the outputs RPWM, LPWM and PWM (R_EN and L_EN) and to show everyone that the motor works fine with the first program.

The program to test the function of the motor works fine. The motor spins and I have no problems whatsoever. However, once I try using the second programm the motor does not spin. I am getting good readings for RPWM, LPWM and PWM. I do not know what I am doing wrong.

I have tried debugging the code. While trying out different things I found out that once I deactivate "receiver.enableIRIn();" the motor spins fine. I have tried removing the 5V supply voltage to the IR receiver once the signal has been received and decoded. That made no difference. At the moment I am helpless. Maybe somebody has encountered a similar problem?

CODE 1 (Motor spins):

#define RPWM 9
#define LPWM 10
#define PWM 11
#define SPEEDPWM 200




void setup() {
  Serial.begin(9600);
  Serial.println("START");
  pinMode(RPWM, OUTPUT);
  pinMode(LPWM, OUTPUT);
  pinMode(PWM, OUTPUT);


}


void motor_clockwise() {

  digitalWrite(LPWM, LOW);
  digitalWrite(RPWM, HIGH);
  analogWrite(PWM, SPEEDPWM);
  Serial.println("Clockwise Activated");

}


void motor_counterclockwise() {

  digitalWrite(RPWM, LOW);
  digitalWrite(LPWM, HIGH);
  analogWrite(PWM, SPEEDPWM);
  Serial.println("Counterclockwise Activated");
}



void loop() {
  // put your main code here, to run repeatedly:

  for (int counter = 0; counter < 3; counter++){
  motor_clockwise();
  Serial.print("LPWM:");
  Serial.println(digitalRead(LPWM));
  Serial.print("RPWM:");
  Serial.println(digitalRead(RPWM));
  Serial.print("PWM:");
  Serial.println(analogRead(PWM));
  Serial.print("\n\nThis is the code without IR Library! The motor works fine with this code.");
  }

  delay(500000000);     //To show that RPWM, LPWM and PWM do not have to be in a loop. Keeps serial monitor clean


}

Serial monitor Code1:

START
Clockwise Activated
LPWM: 0 
RPWM:1
PWM: 416
This is the code without IR Library! The motor works fine with this code. Clockwise Activated LPWM: 0
RPWM:1
PWM: 416
This is the code without IR Library! The motor works fine with this code. Clockwise Activated LPWM: 0
RPWM:1
PWM: 415
This is the code without IR Library! The motor works fine with this code.

Code 2 (Motor doesnt work):

#include <IRremote.h>     //Infrarot Libraries
#include <IRremoteInt.h>

#define LPWM 9            //Makros für PINs des Motor, sowie Makro für SPEEDPWM = Geschwindigkeit Motor (0-255)
#define RPWM 10
#define PWM 11
#define SPEEDPWM 100

int MY_RECV_PIN = 13;        //Receiver PIN 13 für IR
IRrecv receiver(MY_RECV_PIN); 
decode_results results;   //Decode results to results

int i;


void setup() {
  receiver.enableIRIn();    //Activates IR receiver Input

  Serial.begin(9600);       //Baud rate für serial communication
  Serial.println("Start");
  pinMode(RPWM, OUTPUT);    //pinMode configuration for OUTPUT (Motor),Input (IR)
  pinMode(LPWM, OUTPUT);
  pinMode(PWM, OUTPUT);


}

void clockwise(){         //Motor clockwise function
  digitalWrite(LPWM, LOW);
  digitalWrite(RPWM, HIGH);
  analogWrite(PWM, SPEEDPWM);
  Serial.println("Motor clockwise function activated");
}

void counterclockwise(){    //Motor counterclockwise function
  digitalWrite(RPWM, LOW);
  digitalWrite(LPWM, HIGH);
  analogWrite(PWM, SPEEDPWM);
  Serial.println("Motor counterclockwise function activated");
  
}

//void stop_motor(){
//  Serial.println("Motor Stop function activated");
//  digitalWrite(RPWM, LOW);
//  digitalWrite(LPWM, LOW);
//  analogWrite(PWM, 0);
//}


void loop() {

    if (receiver.decode(&results)) {
     Serial.println(results.value);
     receiver.resume();
    
        if (results.value == 16722135 or results.value == 324312031){
            clockwise();
            Serial.println("IR message has been decoded and accepted");
            Serial.print("LPWM:");
            Serial.println(digitalRead(LPWM));
            Serial.print("RPWM:");
            Serial.println(digitalRead(RPWM));
            Serial.print("PWM:");
            Serial.println(analogRead(PWM));
            Serial.print("\n\n\nIn this example the motor does not work. I have not found the reason.");
         
        }
         
     
   
    }

}

Serial monitor Code2:

Start
16722135
Motor clockwise function activated
IR message has been decoded and accepted
LPWM: 0 RPWM:1
PWM: 500
In this example the motor does not work. I have not found the reason.16722135 Motor clockwise function activated
IR message has been decoded and accepted
LPWM: 0
RPWM: 1
PWM: 362
In this example the motor does not work. I have not found the reason. 4294967295

Thanks for any help in advance :smiley:
I am running IRremote on version 2.2.3. Most newer versions do not seem to work with my receiver.

If you follow the forum guide lines on posting code you probably get many more users interested in helping you. Follow toe Forum guidelines and use the </>?

Missed the "code" button yesterday. Now it should be better

You can't analogRead from a digital pin (11).
Replace that line with:

Serial.println(SPEEDPWM);

Just remembered, seems like the IRremote library uses timer 2 which controls PWM on pins 3 and 11, try another pwm pin (5 or 6) instead of 11.

1 Like

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