having trouble with making a car moved by a joystick please help!

I used 2 5v dc motors with a joystick module (x and y in code) here is the code:
motors are pins 9,10
(Code posted with code tags. Moderator)

int x = A0;
int y = A1;
int r1;
int r2;
int m1;
int m2;
int rm = 9;
int lm = 10;
int m3;
int m4;


void setup() {
  Serial.begin(9600);
  pinMode (x, INPUT);
  pinMode (y, INPUT);
  pinMode (rm, OUTPUT);
  pinMode (lm, OUTPUT);
}


void loop() {
  r1 = analogRead(x);
  r2 = analogRead(y);


  m1 = map(r1, 523, 1023, 0, 255);
  m2 = map(r1, 0, 500, 0, 255);
  m3 = map(r2, 523, 1023, 0, 255);
  m4 = map(r2, 0, 500, 0, 255);
  Serial.println(m1);
  Serial.println(m2);
  Serial.println(m3);
  Serial.println(m4);
  Serial.println("");
  delay(1000);

  if (r1 < 523 and r1>500) {


  }
  if (r1 < 500) {
    analogWrite(rm, m2);
    analogWrite(lm, m2);
  }
  if (r1 > 523) {
  }


  if (r2 < 500) {
    analogWrite(rm, m4);
    analogWrite(lm, 0);
  }
  if (r2 > 523) {
    analogWrite(rm, 0);
    analogWrite(lm, m3);
  }
  if (m1 > 255) {
    m1 = 255;
  }


  if (m2 > 255) {
    m2 = 255;
  }


  if (m3 > 255) {
    m3 = 255;
  }


  if (m4 > 255) {
    m4 = 255;
  }

  if (m1 < 0) {
    m1 = 0;
  }


  if (m2 < 0) {
    m2 = 0;
  }


  if (m3 < 0) {
    m3 = 0;
  }


  if (m4 < 0) {
    m4 = 0;
  }
}

wired_car_wth_joy_stick_no_h_brige.ino (898 Bytes)

Post your code, post your schematic, describe your trouble.

You have one output per motor so the motors only go forward, right?

This might be a good starting point:

const byte xPin = A0;
const byte yPin = A1;
const byte rmPin = 9;
const byte lmPin = 10;


void setup()
{
  Serial.begin(9600);


  // pinMode (xPin, INPUT);  // NOT used for analogRead()!
  // pinMode (yPin, INPUT);


  // pinMode (rmPin, OUTPUT);  // NOT used for analogWrite()!
  // pinMode (lmPin, OUTPUT);
}




void loop()
{
  int xValue = analogRead(xPin);
  int yValue = analogRead(yPin);


  int Speed = map(xValue, 523, 1023, 0, 255);  // Forward on joystick adds speed
  Speed = constrain(Speed, 0, 255);


  int TurnFactor =  (yValue / 2) - 255;  // -255 = full left, +255 = full right
  if (TurnFactor * TurnFactor < 100)
    TurnFactor = 0;  // Turn factor is between -10 and +10 so make it zero


  int lmSpeed = constrain(Speed - TurnFactor, 0, 255);
  int rmSpeed = constrain(Speed + TurnFactor, 0, 255);


  analogWrite(rmPin, rmSpeed);
  analogWrite(lmPin, lmSpeed);
}

hey i used another code with the same circut with a 9v ac to dc adapter bet the jumpper wires i connercted to it keep melting i.d.k why but it happend three times now .is it too much? , I will try to use 4 1.5 v battery but is it enogh?

(I am using 2 5v motors ,l298n h brige ,arduino uno ... and maybe I will use hc-06)

How would we know?

Did you read reply #1, second part of the question asked?

Have you read the instructions for posting in every forum section - particularly point no. 7?

did you read #8 he said you can attach your code if you want and i did 8) 8)

You can attach your code if it is too big to post. Yours isn't.

Or of course you can attach it if you want people to ignore your questions...and there you have succeeded.

Steve