I'm learning electronics and trying to understand why my IR receiver spits out random codes when my motor is on.

I have a basic setup with this:

  • Arduino
  • Power supply set to 5V
  • IR sensor receiver module
  • PN2222A transistor that turns the motor on/off
  • 3-6V motor

When the motor is off, my IR sensor detect all my commands sent with an IR remote and works well. But at the moment I send the command to turn on the motor, the motor turns on and the IR receiver starts to blink and send random codes.

This tells me that, because the motor is draining power, the receiver acts weirdly. In fact, when I connect the motor directly to the tracks of my breadboard, I have the same problem (without transistor and connections in between).

Edit: Schematic added enter image description here

What is the cause of this behavior? A change in the amperage received by the IR receiver? Is this something else?

Should I add a capacitor (how many farads?) Should I add a resistor (how many ohms?)

Note: I'm actually learning it, so please, don't tell me to go back to school and learn all the laws and formulas, I'm on it. Be constructive and guide me in your responses.

  • 3
    \$\begingroup\$ Can you draw a quick schematic with our built in schematic tool on our website? I'm a little skeptical on how you're wiring everything up, particularly, your motor. \$\endgroup\$
    – user103380
    Commented Sep 24, 2019 at 17:13
  • \$\begingroup\$ Here is my very first schematic. \$\endgroup\$ Commented Sep 24, 2019 at 18:08
  • 1
    \$\begingroup\$ This looks like a Fritzing layout... I don't like looking at these but thankfully only have two things wired up to Arduino. There's a few things I've spotted that are improperly configured. 1) You don't have anything driving the load of the BJT. You need 5V going to the collector. 2) Your transistor is backwards, if you really are using the PN2222 (and not the P2N2222). You grounded your collector. I believe you want to ground the emitter instead. 3) That black wire on your motor should be grounded along with your collector. 4) Where's your flywheel diode? \$\endgroup\$
    – user103380
    Commented Sep 24, 2019 at 18:37
  • 1
    \$\begingroup\$ Also, you should really consider an external battery for your motor and (once you hook it properly) BJT. You're limiting how much voltage you're providing for your infrared sensor. Not only that, think about how much current you're drawing with both the motor and the sensor on the same 5V rail. \$\endgroup\$
    – user103380
    Commented Sep 24, 2019 at 18:42
  • 1
    \$\begingroup\$ @KingDuken: double-check your data sheets. If it's a PN2222, the emitter is grounded, and he's pulling the motor lead to ground using its collector. \$\endgroup\$
    – TimWescott
    Commented Sep 24, 2019 at 19:35

1 Answer 1


Motors are noisy, and they dump noise onto their power supply rails. You've done nothing to isolate the IR receiver from that noise.

You should have a capacitor from +5V to ground. You probably want a "bulk" cap of 100uF or so, in parallel with a 100nF cap (and there's more than one way to do this "right", so don't be surprised at comments).

You should isolate the IR receiver from that noise. If you're truly running the motor from a separate +5V supply, and intend to continue to do so, then power the IR receiver from the Arduino's +5V supply. Better, if the receiver is rated for 3.3V operation, power it from the Arduino's 3.3V supply for better isolation. Either way, put a 100nF cap in parallel with the receiver's power supply pins, right at the receiver package.

While you're at it, put in that catch diode that @KingDuken mentioned. That's a diode, rated for your motor current (i.e., not something too wimpy) from the transistor collector to the motor's +5V supply. Orient it so that it's reverse biased when the motor is on -- that way, when you shut the motor off suddenly, the inductive kickback won't destroy your transistor.

  • \$\begingroup\$ Thank you for the explanation about the noise. This can explained the strange behavior. So theses caps will absorb that noise? I can isolate it for now but I want to go forward and manage everything from a single power supply (still need to understand how to manage the voltage and current properly). I will check for the diode. It's a new component that was not in my kit. \$\endgroup\$ Commented Sep 24, 2019 at 19:55
  • 2
    \$\begingroup\$ The caps will absorb some of the noise. It's better actively isolate the electronics from the motor, preferably with a voltage regulator. Think of your motor as a line of overloaded dump trucks rumbling by, and your processor and sensor as a table laid with fine china and white linen. The further you can get that table from the edge of the road, the better off you are. \$\endgroup\$
    – TimWescott
    Commented Sep 24, 2019 at 20:12
  • \$\begingroup\$ I love this metaphor. It's really help to understand. Now we are talking about motor but is there a way to measure that noise? Maybe I will found a new component that may generate some noise too. \$\endgroup\$ Commented Sep 24, 2019 at 21:14
  • 1
    \$\begingroup\$ The noise is AC current noise -- the motor doesn't pull a constant amount of current, mostly because of bouncing brushes, but also because the back-EMF of a motor isn't constant with rotation. Because real voltage sources aren't perfectly stiff, the changing motor current yanks the supply voltage around. That AC voltage impressed on the +5V supply gets into your sensitive electronics, and problems happen. You can measure the effect by looking at the +5V supply voltage with an oscilloscope, or by looking at the motor current with a series resistor in the transistor emitter lead. \$\endgroup\$
    – TimWescott
    Commented Sep 24, 2019 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.