Arduino + adafruit driver + ir sensor and remote

Hi sir/madam,
I’m here to ask some help from you.i’m doing a project by using arduino R3 with the adafruit motor shield and ir sensor to control the direction of the motor and the speed of the motor with ir remote. i new from the programming, and i couldn’t find any problem on my code.So here i posted my code.hope that you could help me up. And is there any sample code for my project ?

#include <AFMotor.h>
#include <IRremote.h>

AF_DCMotor motor(2);
int receiver = 2;
IRrecv irrecv(receiver);
decode_results results;

void setup()
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println(“Motor test!”);

// turn on motor

void loop()

if (irrecv.decode(&results)) // have we received an IR signal?

uint8_t i;

if (results.value == 0xFF629D){
for (i=0; i<255; i++) {

else if (results.value == 0xFFA857){
for (i=0; i<255; i++) {

else if (results.value == 0xFF02FD){

You should tell us what's happening. Does the code not compile? If so with what errors? Does it compile but not run as you expect?- if so what's it doing wrong, or not doing.....

it can be error..but when i give the instuction,its not working at all..

How do you know these codes 0xFF629D, 0xFFA857 are what your remote sends. Did you use the sketch from Ken Shirriff or similar that shows what your remote buttons do?

Do your ticks and tocks and techs print?

the code which is alrdy decode by the IRdemo in the arduino software..only print tick..other all no..

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

Some comments:

  • The moderators of this forum will want you to use code blocks like above - so that your code is easy to read.
  • You seemed to leave out the irrecv.resume() in your code (see above from the IRremote examples), which means you will only receive the first signal!
  • If that doesn't solve it for you, post how you connected your IR receiver to the Arduino - which pins etc !
  • You could also take(or just comment) out the motor stuff and try to get the infrared code tested/working on its own & when you are successful, merge the motor code back in! of luck :slight_smile:

ok..will try it later..Thanks for helping !

Did the adafruit driver will clash with ir receiver or not ? Still cant work..

I had a similar problem and came across your post here. The solution for me was to connect my two DC motors to ports 3 & 4 of the Adafruit motor shield (v1). I'm also using the IR remote library by Ken Shirriff and in IRremoteInt.h he states:

// Uncomment the timer you wish to use on your board.  If you
// are using another library which uses timer2, you have options
// to switch IRremote to use a different timer.

and later

#define IR_USE_TIMER2     // tx = pin 3

It appears that on the Uno the PWM timer on digital pin # 3 is being used by the IRremote library as well as the motor shield (when you activate DC Motor #2 or Stepper #1 FAQ | Adafruit Motor Shield | Adafruit Learning System)

If you found another solution please let me know.

BTW you are thinking along the correct lines by connecting the data line from the IR receiver to pin #2 because digital pin 11 is used by the motor shield when you activate DC Motor #1 or Stepper #1.