first robot part 2

i have the code writen that one joystick is controling two motors but now how to wire everythink so that it will work(i dont have my arduino uno jet ) all help is appreciated

/*
Simple motor control with square limit joystick

      Y(1023)
    |---------|
    |---------|
X(0)|---512---|X(1023)
    |---------|
    |---------|
       Y(0)
       
 Left Motor Forward/Reverse = LMF/LMR
 Right Motor Forward/Reverse = RMF/RMR
*/

const byte LMF = 3;
const byte LMR = 5;
const byte RMF = 6;
const byte RMR = 9;

const byte Xpot = A0;
const byte Ypot = A1; 

volatile unsigned int X = 512, Y = 512; // pot values default 512 for center
unsigned int Xspeed = 0, Yspeed = 0; //motor speed default 0 for full stop
const int Xdeadzone = 5, Ydeadzone = 5; //amount of slack needed for pot values

void setup(){
  pinMode(LMF, OUTPUT);
  pinMode(LMR, OUTPUT);
  pinMode(RMF, OUTPUT);
  pinMode(RMR, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  X = analogRead(Xpot);
  Y = analogRead(Ypot);

  if (X >= (512 + Xdeadzone))//Forward
  { 
    Xspeed = (X - 512) / 2; // 0 - 255
    if(Y > (512 + Ydeadzone)) //Left
    {
      Yspeed = (Y - 512) / 2;
      analogWrite(LMF, Xspeed - Yspeed); analogWrite(RMF, Xspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
    else if (Y < (512 - Ydeadzone)) //Right
    {
      Yspeed = (512 - Y) / 2;
      analogWrite(LMF, Xspeed); analogWrite(RMF, Xspeed - Yspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
    else
    {
      analogWrite(LMF, Xspeed); analogWrite(RMF, Xspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
  }

  else if (X <= (512 - Xdeadzone))//Reverse
  { 
    Xspeed = (512 - X) / 2;
    if(Y > (512 + Ydeadzone)) //Left
    {
      Yspeed = (Y - 512) / 2;
      //digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
      analogWrite(LMR, Xspeed - Yspeed); analogWrite(RMR, Xspeed);
    }
    else if (Y < (512 - Ydeadzone)) //Right
    {
      Yspeed = (512 - Y) / 2;
      //digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
      analogWrite(LMR, Xspeed); analogWrite(RMR, Xspeed - Yspeed);
    }
    else
    {
      //digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
      analogWrite(LMR, Xspeed); analogWrite(RMR, Xspeed);
    }
  }

  else // X is between 512 +- deadzone
  {
    if(Y > (512 + Ydeadzone)) // zero point turn Left
    {
      digitalWrite(LMF, LOW); analogWrite(RMF, Yspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
    else if(Y < (512 - Ydeadzone))// zero point turn Right
    {
      analogWrite(LMF, Yspeed); digitalWrite(RMF, LOW);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW); 
    }
    else
    { // Full stop
      digitalWrite(LMF,LOW);
      digitalWrite(RMF,LOW);
      digitalWrite(LMR,LOW);
      digitalWrite(RMR,LOW);
    }
  }
}

could it work with a simple motors like this or not?

That tiny motor that makes your phone vibrate draws more than twice what an AVR can safely supply. Do not connect a motor directly to an output pin.

i would connect it to a breadboard but would that motor work? or do i need a stepper motor

would this work

whit this code

/*
Simple motor control with square limit joystick

      Y(1023)
    |---------|
    |---------|
X(0)|---512---|X(1023)
    |---------|
    |---------|
       Y(0)
       
 Left Motor Forward/Reverse = LMF/LMR
 Right Motor Forward/Reverse = RMF/RMR
*/

const byte LMF = 3;
const byte LMR = 5;
const byte RMF = 6;
const byte RMR = 9;

const byte Xpot = A0;
const byte Ypot = A1; 

volatile unsigned int X = 512, Y = 512; // pot values default 512 for center
unsigned int Xspeed = 0, Yspeed = 0; //motor speed default 0 for full stop
const int Xdeadzone = 5, Ydeadzone = 5; //amount of slack needed for pot values

void setup(){
  pinMode(LMF, OUTPUT);
  pinMode(LMR, OUTPUT);
  pinMode(RMF, OUTPUT);
  pinMode(RMR, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  X = analogRead(Xpot);
  Y = analogRead(Ypot);

  if (X >= (512 + Xdeadzone))//Forward
  { 
    Xspeed = (X - 512) / 2; // 0 - 255
    if(Y > (512 + Ydeadzone)) //Left
    {
      Yspeed = (Y - 512) / 2;
      analogWrite(LMF, Xspeed - Yspeed); analogWrite(RMF, Xspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
    else if (Y < (512 - Ydeadzone)) //Right
    {
      Yspeed = (512 - Y) / 2;
      analogWrite(LMF, Xspeed); analogWrite(RMF, Xspeed - Yspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
    else
    {
      analogWrite(LMF, Xspeed); analogWrite(RMF, Xspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
  }

  else if (X <= (512 - Xdeadzone))//Reverse
  { 
    Xspeed = (512 - X) / 2;
    if(Y > (512 + Ydeadzone)) //Left
    {
      Yspeed = (Y - 512) / 2;
      //digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
      analogWrite(LMR, Xspeed - Yspeed); analogWrite(RMR, Xspeed);
    }
    else if (Y < (512 - Ydeadzone)) //Right
    {
      Yspeed = (512 - Y) / 2;
      //digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
      analogWrite(LMR, Xspeed); analogWrite(RMR, Xspeed - Yspeed);
    }
    else
    {
      //digitalWrite(LMF, LOW); digitalWrite(RMF, LOW);
      analogWrite(LMR, Xspeed); analogWrite(RMR, Xspeed);
    }
  }

  else // X is between 512 +- deadzone
  {
    if(Y > (512 + Ydeadzone)) // zero point turn Left
    {
      digitalWrite(LMF, LOW); analogWrite(RMF, Yspeed);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW);
    }
    else if(Y < (512 - Ydeadzone))// zero point turn Right
    {
      analogWrite(LMF, Yspeed); digitalWrite(RMF, LOW);
      //digitalWrite(LMR, LOW); digitalWrite(RMR, LOW); 
    }
    else
    { // Full stop
      digitalWrite(LMF,LOW);
      digitalWrite(RMF,LOW);
      digitalWrite(LMR,LOW);
      digitalWrite(RMR,LOW);
    }
  }
}

The way you would connect the motor is either in an H-Bridge Configuration, or by using a transistor to act as a switch. The later is just simply finding a transistor large enough to handle the current (generally an N-Chan or NPN), and connect: the Source or emitter to ground the Collector or Drain to one end of the motor, The other end of the motor to your VCC (You'll probably want an external power supply for this) The base or gate to your arduino through a resistor to one of the PWM pins, and make sure the arduino is also connected to ground.

Don't forget the kickback diode.

mirith

could you draw that for me because i'm not american and english is not my first language and yes i will use externall power supply please help me this is the last thing that need to be done before i start building.

First off, that code looks "iffy" to me, mainly because the comments seem a bit off; the comments show the x-potentiometer and the y-potentiometer arranged as would be expected, but further comments talk about the x-potentiometer pins controlling forwards/backwards movement and the y-potentiometer pins controlling left/right movement. Furthermore, the PWM outputs seem like they wouldn't match up to what the controls are meant for.

All that said, I haven't explored it too in-depth to really know what is going on, other than I can see that the code was meant for h-bridge control of two motors (likely differential steering arrangement - but then again, not sure!), not for controlling servos as in your second diagram (heck, the pin assignments don't even match up).

The fact that you have posted a piece of code and two different diagrams that are either wrong or won't work with that piece of code, and the fact that you are unable to see this, leads me to believe you are just pulling random bits of junk from the internet and hoping some of it will somehow work together - without being able to understand how and why it will or won't work together.

If you wrote the code you originally posted, you would know that it was meant to control an h-bridge, and you would have indicated this on your diagram. You would have also known that it wouldn't work with a servo, which you show on your second diagram.

Either you didn't write the code or draw the diagrams, or you are really confused about how everything is supposed to work in regards to this project...

in the first part you told me to google it and i found this code (not shure that it works) now im trying to figure how to wire it.
P.S im not building this robot right now im planing it first when i have all the facts then im going to build it so instead of criticizing me help me. pictures are from the net.

it seems you are trying to do too much in one go. BEFORE you even try to use a joystick, can you make a simple program that drives a motor ? eg. 2 seconds forward, 2 seconds reverse, then stop. have you understood what a H-bridge does yet ?

im tottaly new here thats why im searching for codes from other people for this kind of robot

thegrid: in the first part you told me to google it and i found this code (not shure that it works) now im trying to figure how to wire it.

Well - so I did - and you found the code here (you should have mentioned this in your post):

http://forum.arduino.cc/index.php?topic=157967.30

...but you can't expect to take that code (which again, I am not sure will work - even using an h-bridge control system - but I haven't rigorously inspected the code or tried it out, so I have little to base that on), randomly found, and expect it to work with another diagram on the internet you randomly find.

Just finding things on the internet won't help you - you need to also have an understanding of what is what, and how it works - before applying it to anything.

thegrid: P.S im not building this robot right now im planing it first when i have all the facts then im going to build it so instead of criticizing me help me. pictures are from the net.

Yeah - I know the pictures are from the net.

The code you found in that Arduino thread appears to be meant to control two h-bridges arranged in a differentially steered robot platform configuration (similar to the video you originally posted in your first thread).

So - you are going to need to learn about h-bridges and how they are connected to the Arduino. You are also going to need to learn how PWM works on the Arduino, and which pins you can use (because I can almost guarantee that you won't necessarily find an example of using an h-bridge with two motors that is using the same pins for control as the sample code you posted) - so you can modify that sample code.

The first diagram you posted in this thread will not work because it will burn out pins in your Arduino - you need to use an h-bridge.

The second diagram you posted -could- work with the code you posted, if you updated the code to use the Servo library instead of PWM output for an h-bridge. It wouldn't be easy to do, but it could be done. To do so will require you to really understand the Servo library, how it works with servos, and how that example code you posted works with an h-bridge and PWM output to turn the motors, so you know how to update it. I can't tell you how to do this; while I could if I studied everything really closely, I am not going to do this, as I am not getting paid for such a project - just rest assured that I know it can be accomplished, if you put your mind and energies toward it.

Finally - on that second schematic - I noticed that one of the pins of the joystick lead to the TX pin on the Arduino; whether or not this would cause problems with serial comms to/from the Arduino, would depend on what pin that it is wired to on the joystick, among other factors (for what you want to do, you probably don't even need the joystick part of that circuit, since you want to do it wirelessly from your computer, right?).

thegrid: im tottaly new here thats why im searching for codes from other people for this kind of robot

yes, that's not a problem - but when you search for codes, you need to know what they are for.

i ask again since you haven't replied this; have you understood what a H-bridge does yet ?

since you want to do it wirelessly from your computer, right?

no i dont want to do it wirelessly

i ask again since you haven't replied this; have you understood what a H-bridge does yet ?

no not yet didnt do my research

could i use the 360 servos instead of motors to power the robot it would be easier?

thegrid: ... ...

i ask again since you haven't replied this; have you understood what a H-bridge does yet ?

no not yet didnt do my research

you have a lot to find out then - you won't get the right code if you don't know the basics - the joystick part should be straightforward after that.

thegrid: could i use the 360 servos instead of motors to power the robot it would be easier?

if you're used to working with all kinds of servos, it might be easier - i'm a newbie myself and only used servos as per the Sweep example. for continuous rotation, i'm using DC motors - that means H-bridge.

i build model planes and boats so i have a lot of experience with servos but no experience with arduino. im changing the plan to use servos (im not building a fast robot so servos will be ok and they are stronger than motors) but first im going to learn the basics but im still open for help and ideas.