How to use DC motor with IRremote?

I am trying to control a DC motor with an IR remote but it won't work, suggestions please.

#include "IRremote.h"
#define ENABLE 5
#define DIRA 3
#define DIRB 4
int RECV_PIN = 2; // the pin where you connect the output pin of IR sensor
IRrecv irrecv(RECV_PIN);
decode_results results;
int i;

void setup() {
IrReceiver.enableIRIn();
pinMode(ENABLE,OUTPUT);
pinMode(DIRA,OUTPUT);
pinMode(DIRB,OUTPUT);
Serial.begin(9600);
}

void loop() {
if(results.value == 16753245){
Serial.println("One way, then reverse");
delay(500);
digitalWrite(ENABLE,HIGH); // enable on
for (i=0;i<5;i++) {
digitalWrite(DIRA,HIGH); //one way
digitalWrite(DIRB,LOW);
delay(500000);
digitalWrite(DIRA,LOW); //reverse
digitalWrite(DIRB,HIGH);
delay(500);
}
digitalWrite(ENABLE,LOW); // disable
delay(2000);
}
}

look at some of the other threads using IRremote

where do you call IrReceiver.decode() and .resume()?

and make sure you have the IR stuff working before complicating it with motor control

Where do you expect results.value being assigned?
See the IRremote examples.

@scientificcrabs, please edit your opening post, select all code and click the </> button to apply code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.

This is always vague; in future, please provide a clear description of what you expect the code to do and what it actually does.

That code was written for an older version of the IRremote library. It may not work properly if you have the latest version of the library installed.

Thanks, for the help, how to I add the new version of the IR library?

You already have the new version!
Install the old version (if available) using Manage Libraries in the IDE.

Better update your code to use the new library version. If you don't know how to do that then play around with the examples coming with your actual library.

The IRremote library github pagee has instructions on how to change older version code to work with the new library version.

Thanks for the new library, it works perfectly now!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.