Go Down

Topic: Arduino + adafruit driver + ir sensor and remote (Read 1 time) previous topic - next topic

jacklim

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
  motor.setSpeed(200);
  motor.run(RELEASE);
  irrecv.enableIRIn();
}

void loop()
{

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

  {
    {
  uint8_t i;
 
  if (results.value == 0xFF629D){
  Serial.print("tick");
 
  motor.run(FORWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i); 
    delay(50);
}}

  else if (results.value == 0xFFA857){
  Serial.print("tock");

  motor.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor.setSpeed(i); 
    delay(50);
}}

else if (results.value == 0xFF02FD){
  Serial.print("tech");
  motor.run(RELEASE);
  delay(1000);
}}}}

JimboZA

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.....
"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

jacklim

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

JimboZA

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?

"Could you do the egg bacon spam and sausage without the spam then? "

No PMs for help please.
DO NOT power servos from Arduino 5V: give them their own power and connect the grounds.

jacklim

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

AnalysIR

Code: [Select]
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!



...best of luck :)
Visit our Blog about Infrared Remote Control >>>> http://www.AnalysIR.com/blog/  Twitter: @AnalysIR
First Read this PDF=> 10 common pitfalls with Infrared Remote Control >>> http://bit.ly/1cvd0at

jacklim

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

jacklim

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

MarioL

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:

Code: [Select]

// 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

Code: [Select]

#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 http://learn.adafruit.com/adafruit-motor-shield/faq)

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.

Go Up