I'm trying to make a remote-controlled fan by controlling a motor using vs1838b IR receiver. I programmed the board to turn on the DC motor when I pressed 0 on the remote control and turn off the DC motor when I pressed 1 on the remote control. The motor turned on after I pressed 0 but does not turn off when I pressed 1. I used the serial monitor to check the inputs received by the board from the IR receiver.
16724175 is the input received when I pressed 1 on the remote control. I pressed 1 multiple time and the board received it without any problem. The problem begins after I pressed 0 and the motor starts turning. The board received random values after the motor starts turning and never receive the next input. This means I cannot stop the motor after I press 1 as what I have programmed.
I really can't find any solution to my problem so I'm here to seek help. Thanks.
It's a bad idea to run a motor from the Arduino 5V pin which can't supply high currents. It's even worse if you're also running an IR receiver from the same pin.
What type of motor is it? If it's a DC brushed motor do you have interference suppressing capacitor(s) on it. Try it with a separate supply for the motor e.g. 4xAA batteries.
I agree with @slipstick, it is likely that it is a combination of the motor pulling the Vcc voltage down and the motor noise. A separate supply and 0.1 uF ceramic caps across the motor supply and from each supply terminal to ground can help.
Probably has nothing to do with your problem, but I should mention:
What version of the IRremote library do you have installed? The newer versions (>3.0) do not use the decode_results struct. See the IRremote GitHub page.
Since the decoded values are now in IrReceiver.decodedIRData and not in results any more, remove the line decode_results results or similar.
Thanks. @slipstick@groundFungus .The solution works!!! I use a 0.1uF capacitor to block the motor noise and it works fine. I also update my code to the latest IR remote library version.
The IR receivers are persnickity about power being 5v and solid. Any sag will reduce the success rate nearly to zero. The little LEDs will flicker, but it won't trigger properly.
Remember the Arduino, if USB powered is only at 4.3v because of the built in anti backflow diode that keeps an externally powered Arduino from attempting to bring up the PC.
The Arduino only has 200mA of drive total. A USB adapter can supply ~2A, but the board can only pass thru thar same 200mA. Figure your average LED for 20mA each. A few flashy-blinkys and you're pushing the limit without doing anything real. Solidify your power and the erratic behavior should stop. I've tested this on at least six different sensors from three or four vendors with & w/o buffering - all with the same results. Im to the point that the first component I buy is a 20W (5VDC @ 4A) power supply to keep everything solid. I also solder my power leads to buss bars.
It looks messy, but everything has reliable power. Those IO shields have enough pins, but a single dupont doesn't hold worth a damn. Solid, soldered connections are called for if you project is actually going to be used instead of just a "proof of concept" breadboard build.