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?
closed as too broad by Duncan C, Juraj, MichaelT, Dmitry Grigoryev, esoterik Jun 20 at 1:42
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
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.