Ir reciever not working after motor starts

i am using arduino uno r3 , l293d ic nd ir remote nd sensor(vs1838b) i am new to electronics i have created a circuit in which when i press [2 ->frwd ,8->bckwrd ,4->left ,6->right ,5->stop]. my circuit is working absoultely fine but when i press any button out of [2,4,6,8] nd motor starts running my ir reciever starts showing random number in serial monitor and does not take any input from remote i have to disconnect the power supply to reset it i am using 2 motors
my code-:


#include <IRremote.h>
int ir=11;
int enA=3;
int enB=10;
int i1=4;
int i2=5;
int i3=9;
int i4=8;
String z;

void setup() {
Serial.begin(9600);
IrReceiver.begin(ir,ENABLE_LED_FEEDBACK);
pinMode(enA,OUTPUT);
pinMode(enB,OUTPUT);
pinMode(i1,OUTPUT);
pinMode(i2,OUTPUT);
pinMode(i3,OUTPUT);
pinMode(i4,OUTPUT);

}

void loop() {

if(IrReceiver.decode())
{
Serial.println(IrReceiver.decodedIRData.decodedRawData,HEX);

switch(IrReceiver.decodedIRData.decodedRawData){
case 0xE41B7F80:
digitalWrite(enA,HIGH);
digitalWrite(enB,HIGH);
digitalWrite(i1,HIGH);
digitalWrite(i2,LOW);
digitalWrite(i3,HIGH);
digitalWrite(i4,LOW);
break;

case 0x1FEF00F:
 analogWrite(enA,255);

analogWrite(enB,255);
digitalWrite(i1,LOW);
digitalWrite(i2,HIGH);
digitalWrite(i3,LOW);
digitalWrite(i4,HIGH);
break;

case 0x1FE30CF:
 analogWrite(enA,255);
analogWrite(enB,255);
digitalWrite(i1,HIGH);
digitalWrite(i2,LOW);
digitalWrite(i3,LOW);
digitalWrite(i4,HIGH);
break;

case 0x1FE708F:
 analogWrite(enA,255);
analogWrite(enB,255);
digitalWrite(i1,LOW);
digitalWrite(i2,HIGH);
digitalWrite(i3,HIGH);
digitalWrite(i4,LOW);
break;

case 0xF20D7F80:
 analogWrite(enA,255);
analogWrite(enB,255);
digitalWrite(i1,LOW);
digitalWrite(i2,LOW);
digitalWrite(i3,LOW);
digitalWrite(i4,LOW);
break;
}

IrReceiver.resume();

}
}


here is the picture of circuit its working on simulator but not working in real life model and everything is exact same i have not used any resistors or capacitors.

Which IR codes are associated with each of these buttons ?

The IRremote library uses a timer and an interrupt for receiving IR. You seem to be using PWM (analogWrite()) which also uses a timer. If they use the SAME timer, there will be a conflict.

1 Like

1st case is frwd
2nd case is bck
3rd case is left
4th case is right
5th case is stop

ir reciever signal pin is using pin 11.but i amnot using analogWrite() function. shall i change the pin?
i am only using analogWrite() for enable1 and enable 2 for l293d ic.

PWM on Pin 3 is generated by Timer2. IRremote, by default, uses Timer2 for timing. There is your conflict.

To fix it, move enA to a PWM pin that is not 3 or 11 (Timer2). The safest solution is to move them both to Pins 5 and 6 (Timer0). Timer0 is the millis() timer so it is unlikely that any future addition will cause a new timer conflict.

1 Like

Okay i will try then tell btw thanx for your help.