Go Down

Topic: Malfunctioning of DC motors in IR communication using Arduino leonardo (Read 215 times) previous topic - next topic

vasu1992

Im using Arduino leonardo for IR reception. I'm able to receive the transmitted data. but, when i want to control the dc motors using transmitted data,only one side motors are working. please help me out from this situation.
Thanks,
vasu dev mukku

Robin2

How can we help when you have given no useful information.

Post your program
Post your wiring schematic
Post a link to the datasheet for the motors you are using
Post a link to the motor drivers you are using
Tell us what motor power supply you are using (volts and amps).
Tell us what sort of IR transmitter you are using

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

vasu1992

Sorry,I'm using NEC protocol remote as IR transmitter,(Normal remote)
i have used Ken Shirriff's IRremote library: https://github.com/z3t0/Arduino-IRremote
For robot details: https://www.dfrobot.com/product-426.html
 Without IR communications the motors working is normal.The robot is able to move forward and reverse, but when i want to control movement of motors with IR Remote, only left side motors are running, but right side motors are not functioning.But, i can able to read the transmitted data from remote.And left side motors are working according to received data. but not right side motors.
schematic:https://github.com/Arduinolibrary/DFRobot_ROB0050_Miniq-4WD-Robot/blob/master/miniQ%204WD%20V2.pdf?raw=true
this is Receiver demo code on MINIQ 4WD Line following robot.

Code: [Select]


#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>


#define EN1 6//pin for run the right motor
#define IN1 7//pin for control right motor direction
#define EN2 5//pin for run the left motor
#define IN2 12//pin for control left motor direction

#define FORW 0//go forward
#define BACK 1//go back

#define IR_IN  17//IR receiver pin
IRrecv irrecv(IR_IN);
decode_results results;

int count;//count the motor speed pulse

void Motor_Control(int M1_DIR,int M1_EN,int M2_DIR,int M2_EN)//control motor
{
  //////////M1////////////////////////
  if(M1_DIR==FORW)//M1 motor direction
    digitalWrite(IN1,FORW);//forward
  else
    digitalWrite(IN1,BACK);//back
  if(M1_EN==0)
    analogWrite(EN1,LOW);//stop
  else
    analogWrite(EN1,M1_EN);//set speed

  ///////////M2//////////////////////
  if(M2_DIR==FORW)
    digitalWrite(IN2,FORW);
  else
    digitalWrite(IN2,BACK);
  if(M2_EN==0)
    analogWrite(EN2,LOW);
  else
    analogWrite(EN2,M2_EN);
}

void dump(decode_results *results)
{
 if(results->value==0x00fd00ff)
  {
    //Motor_Control(FORW,0,FORW,0);//停止   
  }
  if(results->value==0x00fd807f)
  {
    Motor_Control(FORW,100,FORW,100);//前进
  }
 if(results->value==0x00fd906f)
 {
    Motor_Control(BACK,100,BACK,100);//后退
  }
  if(results->value==0x00fd20df)
  {
    Motor_Control(FORW,100,BACK,100);//左转
  }
  if(results->value==0x00fd609f)
  {
    Motor_Control(BACK,100,FORW,100);//右转
  }
}

void setup()
{
  pinMode(5,OUTPUT);//init the motor driver pins
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(12,OUTPUT);
 
  irrecv.enableIRIn();
}
void loop()
{
  Motor_Control(FORW,0,FORW,0);//run motor
  while(1)
  {
   if(irrecv.decode(&results))
   {
      dump(&results);
      irrecv.resume();
   }
  }
}




thanks,
vasu dev mukku

Robin2

but when i want to control movement of motors with IR Remote, only left side motors are running, but right side motors are not functioning.But, i can able to read the transmitted data from remote.
Where in the program in Reply #2 is the code that allows you to see the IR data that is received?

And please post the program that shows that both motors work without the IR code.

What is the purpose of the Lego library that does not seem to be used?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

vasu1992


Where in the program in Reply #2 is the code that allows you to see the IR data that is received?
---For reading IR Received data, i have used Serial Monitor to check(using Serial.println) inside the
    function.




This is without IR and it works fine.


Code: [Select]



#define EN1 6//pin for run the right motor
#define IN1 7//pin for control right motor direction
#define EN2 5//pin for run the left motor
#define IN2 12//pin for control left motor direction

#define FORW 0//go forward
#define BACK 1//go back


void Motor_Control(int M1_DIR,int M1_EN,int M2_DIR,int M2_EN)//control motor
{
  //////////M1////////////////////////
  if(M1_DIR==FORW)//M1 motor direction
    digitalWrite(IN1,FORW);//forward
  else
    digitalWrite(IN1,BACK);//back
  if(M1_EN==0)
    analogWrite(EN1,LOW);//stop
  else
    analogWrite(EN1,M1_EN);//set speed

  ///////////M2//////////////////////
  if(M2_DIR==FORW)
    digitalWrite(IN2,FORW);
  else
    digitalWrite(IN2,BACK);
  if(M2_EN==0)
    analogWrite(EN2,LOW);
  else
    analogWrite(EN2,M2_EN);
}



void setup()
{
  pinMode(5,OUTPUT);//init the motor driver pins
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(12,OUTPUT);
 
 
}
void loop()
{
  Motor_Control(FORW,0,FORW,0);//run motor
  delay(10000);
   Motor_Control(FORW,100,FORW,100);//前进
    delay(10000);
    Motor_Control(BACK,100,BACK,100);//后退
 delay(10000);
 
    Motor_Control(FORW,100,BACK,100);//左转
   delay(10000);

    Motor_Control(BACK,100,FORW,100);
  delay(10000);
}





What is the purpose of the Lego library that does not seem to be used?
 -This comes with the IR remote library.

--For IR reception i have to use D17 pin which is pin 8 in processor and that pin is used in one of motor driving circuit.
Can you please see the schematic :   https://github.com/Arduinolibrary/DFRobot_ROB0050_Miniq-4WD-Robot/blob/master/miniQ%204WD%20V2.pdf?raw=true

i thought maybe problem with the IR receiver pin! I don't have any clue.

Robin2

Where in the program in Reply #2 is the code that allows you to see the IR data that is received?
---For reading IR Received data, i have used Serial Monitor to check(using Serial.println) inside the
    function.
The program in Reply #2 does not have Serial.print() statements. Please post the version of the program that includes them.


I don't know what you mean by D17 and Pin8. Just use the standard Arduino pin reference numbers. You obviously cannot use the same pin for two purposes.

You may find that your problem arises because the IR activity is using one of the HardwareTimers that is needed to produce PWM signals for the motor. Read the details of analogWrite() in the Reference section.


...R
Two or three hours spent thinking and reading documentation solves most programming problems.

vasu1992

You may find that your problem arises because the IR activity is using one of the HardwareTimers that is needed to produce PWM signals for the motor. Read the details of analogWrite() in the Reference section.

- I think the problem is with this section only, because left side motors are working when i use IR activity. But not the right side motors.How can i change HarwareTimer to another pin in that IRremote Library? Is it possible to change Timer through programming.
from the header file of IRremote library this is the processor configuration of Leonardo board. i have tried changing all timers, but same result.

-----/// Teensy 2.0
#elif defined(__AVR_ATmega32U4__)
//#define IR_USE_TIMER1   // tx = pin 14
//#define IR_USE_TIMER3   // tx = pin 9
#define IR_USE_TIMER4_HS  // tx = pin 10
----??




thanks,
vasudev mukku.

Robin2

-----/// Teensy 2.0
Does this mean you are using a Teensy rather then an Uno or a Mega and have not told us?

If so, please tell us ALL about what you are trying to do and post a COMPLETE program.


And you did not respond to my questions in Reply #5

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up