I am trying to control a motor using a remote with Arduino Mega. The motor turns on when I press the button on the remote but when I release the button, it continues to move. Does anyone know how to stop the motor spinning when I release the button on the remote?

  • 1
    IR remote? Those generally don't have the concept of button release.
    – Majenko
    Jun 6 '19 at 23:35
  • 1
    do you actually have code to turn the motor off? .... a lot of people assume that if the motor turns on when a button is pressed, that it will magically turn off when the button is released
    – jsotola
    Jun 7 '19 at 0:45
  • 1
    share you sketch here.
    – Vaibhav
    Jun 7 '19 at 3:32
  • You won't get answer more precise than Majenko's, until you share the code in question. Though it is a good answer.
    – chrisl
    Jun 7 '19 at 7:14

For an infra-red remote control you generally can't. Those don't normally have the concept of button release.

Normally there are two kinds of buttons on a remote:

  • Burst code
  • Repeat code

The first sends a short burst of the same code. This allows for a function to be run once per button press. The second sends the same code over and over again constantly until you release it.

For the repeat code buttons you can use that to your advantage. You program your Arduino to run the motor for a short period. That period needs to be slightly longer than the time between each code reception. Then it can appear that it's responding to the release of the button.

For example, if your remote sends codes 5 times per second then whenever you receive a code you start the motor. If you haven't received a code for more than say 300ms then stop the motor.

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