Go Down

Topic: Arduino Robot (Read 2721 times) previous topic - next topic

ygobi

Feb 27, 2012, 02:00 am Last Edit: Feb 29, 2012, 11:09 am by AWOL Reason: 1
Hi, I'm trying to create this project I found on fritzing and I'm having issues. Project: http://fritzing.org/projects/ir-obot/
When ever I press right on my remote it freezes and on the serial monitor, the hex value is always 0. This only happens when I press right on the remote. I've tried different buttons on the remote and it just wont work. The IRremote library worked great and it always works. Thats what I used to get the HEX values.Anyone wanna help?

Please reply,
Gobi
P.S. I've never received my motor shield yet, just testing out the code.

Code: [Select]
#include <IRremote.h>
#include <IRremoteInt.h>

// Robot With IR remote
// by Neil Hendrick
//

//this imports the IR Library (must be present in libraries folder)
int dirbpinB = 13; // Direction pin for motor B is Digital 13
int speedbpinB = 11; // Speed pin for motor B is Digital 11 (PWM)
int dirbpinA = 12; // Direction pin for motor A is Digital 12
int speedbpinA = 3; // Speed pin for motor A is Digital 3 (PWM)
int speed = 100;
int dir = 0;
int RECV_PIN = 10;    // IR receiver
IRrecv irrecv(RECV_PIN);
decode_results results;
 
void setup()
{
pinMode(dirbpinB, OUTPUT);
pinMode(dirbpinA, OUTPUT);
   7
Serial.begin(9600); //begin serial connection, prints output to your PD
irrecv.enableIRIn(); // Start the receiver

}

void loop(){ //start loop
   if (irrecv.decode(&results)) {
   if (results.value == 0xBEEC847B) { //UP forward
digitalWrite(dirbpinB, 1); // set direction
digitalWrite(dirbpinA, 1); // set direction
analogWrite(speedbpinB, speed); // set speed (PWM)
analogWrite(speedbpinA, speed); // set speed (PWM)
   }// close UP
    else if (results.value == 0xBEECA45B) { //DOWN backward
digitalWrite(dirbpinB, 0); // set direction
digitalWrite(dirbpinA, 0); // set direction
analogWrite(speedbpinB, speed); // set speed (PWM)
analogWrite(speedbpinA, speed); // set speed (PWM)
    }
    else if (results.value == 0xBEEC44BB) { //LEFT
digitalWrite(dirbpinB, 1); // set direction
digitalWrite(dirbpinA, 1); // set direction
analogWrite(speedbpinB, speed); // set speed (PWM)
analogWrite(speedbpinA, 50); // set speed (PWM)
    }
    else if (results.value == 0xBEEC24DB) { //RIGHT
digitalWrite(dirbpinB, 1); // set direction
digitalWrite(dirbpinA, 1); // set direction
analogWrite(speedbpinB, 50); // set speed (PWM)
analogWrite(speedbpinA, speed); // set speed (PWM)
    }
    else if (results.value == 0xBEECC43B) { //STOP *
analogWrite(speedbpinB, 0); // set speed (PWM)
analogWrite(speedbpinA, 0); // set speed (PWM)
    }
    else if (results.value == 0xBEECCA35) { // Spin Left RW
digitalWrite(dirbpinB, 1); // set direction
digitalWrite(dirbpinA, 0); // set direction
analogWrite(speedbpinB, speed); // set speed (PWM)
analogWrite(speedbpinA, speed); // set speed (PWM)
    }
    else if (results.value == 0xBEEC2AD5) { //Spin Right FF
digitalWrite(dirbpinB, 0); // set direction
digitalWrite(dirbpinA, 1); // set direction
analogWrite(speedbpinB, speed); // set speed (PWM)
analogWrite(speedbpinA, speed); // set speed (PWM)
    }
   Serial.println(results.value, HEX); //sends the IR code to computer so you can see what codes you are sending
   irrecv.resume(); // Receive the next value  
   
   }//close first IF "if (irrecv.decode(&results)){"
} //close loop


Moderator edit: CODE TAGS

rNmScale

Which remote are you using ? I am guessing its protocol is not yet supported by the IRLib

rNmScale

Try a different remote.

ygobi

Nope, I also tried a Sony remote which I'm sure that is supported. Do you think its because I didn't plugin my motor shield yet? Its coming in the mail and its going to take days or weeks.

sirbow2

hmm looks like it should work... but this is how i did it: http://dduino.blogspot.com/2012/01/ir-tv-remote-controlled-arduino-robot.html
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

ygobi

That project uses servos, I got no servos. I want to use a motor shield. How can I possibly do that?

sirbow2

just a matter of moving the code around...
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

ygobi

I'm a beginner, can you please help me move the code around so I can use it with an Arduino?

sirbow2

so is everyone going to write your code for you?

Code: [Select]
#include <IRremote.h>
long int Buttons[7] = {
  3203171451,  //0Up  in decimal
  3203179611,  //1Down 
  3203155131,  //2Left  //
  3203146971,  //3right  //
  3203187771,  //stop  //
  3203189301,  //spin left RW //
  3203148501  //spin right ff
};

//-----IR-Stuff---------------------------------------------------//
int RECV_PIN = 10;
IRrecv irrecv(RECV_PIN);
decode_results results;
int BtnPressed = 0;
//----------------------------------------------------------------// 

//robotstuff
int dirbpinB = 13; // Direction pin for motor B is Digital 13
int mtrspeedbpinB = 11; // mtrspeed pin for motor B is Digital 11 (PWM)
int dirbpinA = 12; // Direction pin for motor A is Digital 12
int mtrspeedbpinA = 3; // mtrspeed pin for motor A is Digital 3 (PWM)
int mtrspeed = 100;
int dir = 0;

void setup()
{
  Serial.begin(9600);
 
  pinMode(dirbpinB, OUTPUT);
  pinMode(dirbpinA, OUTPUT);
 
  irrecv.enableIRIn(); // Start the receiver
}

void dump(decode_results *results)
{
  if (results->decode_type == NEC)
  {
    unsigned long store = (results->value);
    //Serial.println(store);
    for(int x=0; x<7; ++x)
    {
      if(store == Buttons[x])
      {
        BtnPressed = x;
       // Serial.println(x);
      }
    }
  }
}

void loop()
{
  if (irrecv.decode(&results))
  {
    dump(&results);
    if(BtnPressed == 0) //up
    {
      Serial.println("up");
      digitalWrite(dirbpinB, 1); // set direction
      digitalWrite(dirbpinA, 1); // set direction
      analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM)
    }
    else if(BtnPressed == 1) //down
    {
      Serial.println("down");
      digitalWrite(dirbpinB, 0); // set direction
      digitalWrite(dirbpinA, 0); // set direction
      analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM)
    }
    else if(BtnPressed == 2) //left
    {
      Serial.println("left");
      digitalWrite(dirbpinB, 1); // set direction
      digitalWrite(dirbpinA, 1); // set direction
      analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, 50); // set mtrspeed (PWM)
    }
    else if(BtnPressed == 3) //right
    {
      Serial.println("right");
      digitalWrite(dirbpinB, 1); // set direction
      digitalWrite(dirbpinA, 1); // set direction
      analogWrite(mtrspeedbpinB, 50); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM)
    }
    else if(BtnPressed == 4) //stop
    {
      Serial.println("stop");
      analogWrite(mtrspeedbpinB, 0); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, 0); // set mtrspeed (PWM)
    }
    else if(BtnPressed == 5) //Spin Left RW
    {
      Serial.println("Spin Left");
      digitalWrite(dirbpinB, 1); // set direction
      digitalWrite(dirbpinA, 0); // set direction
      analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM)
    }
    else if(BtnPressed == 6) //Spin Right FF
    {
      Serial.println("Spin Right");
      digitalWrite(dirbpinB, 0); // set direction
      digitalWrite(dirbpinA, 1); // set direction
      analogWrite(mtrspeedbpinB, mtrspeed); // set mtrspeed (PWM)
      analogWrite(mtrspeedbpinA, mtrspeed); // set mtrspeed (PWM)
    }
    irrecv.resume(); // Receive the next value
  }
}
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

ygobi

Well, no. I'm very pleased that you helped me write this code. Thank you so much. I'm still learning how to do this so it will take a while. But thank you!

iamnarendra

u knw softserial.... ? if so...pls tell me how to use it....

sirbow2

random... but yeah, for what?
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

ygobi

Hey, sorry for the late post, the code still doesn't work. I'm still not sure how to fix this problem. The code you gave me has the same problem. When ever I press right, it gets stuck and doesn't work. On the serial monitor it just shows right. Do I need a motor shield? I'm still waiting for it in the mail.

sirbow2

can you press all the other buttons and make left/down etc show up in serial? it should still work without the motor controller.
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

AWOL

What do your serial debug prints tell you?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up