Pages: [1] 2 3   Go Down
Author Topic: Arduino Robot  (Read 2400 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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
« Last Edit: February 29, 2012, 05:09:35 am by AWOL » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 20
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try a different remote.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just a matter of moving the code around...
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so is everyone going to write your code for you?

Code:
#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
  }
}
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

random... but yeah, for what?
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 1
Posts: 486
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can you press all the other buttons and make left/down etc show up in serial? it should still work without the motor controller.
Logged

http://dduino.blogspot.com all my Arduino/electronic projects!!!

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26495
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What do your serial debug prints tell you?
Logged

"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.

Pages: [1] 2 3   Go Up
Jump to: