DC motor controlled by Joystick using Arduino & L298N Motor driver - Wired Connection


Circuit Diagram:



Required Components:


Arduino uno/nano - 1 Nos
Battery - 1 Nos
DC Motor - 2 Nos
L298N Motor Driver - 1 Nos
Joystick - 1 Nos


Program Code:

int joystrick1 = A1;
int joystrick2 = A2;
int val1;
int val2;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
int val1 = analogRead(joystrick1);
int val2 = analogRead(joystrick2);

if(val1 > 1 && val1 < 490){
val1 = map(val1, 1, 490, 255, 0);

analogWrite(6,val1);
analogWrite(5,0);
}

if(val1 > 530 && val1 < 1023){
val1 = map(val1, 530, 1023, 0, 255);

analogWrite(5,val1);
analogWrite(6,0);
}

if(val1 > 491 && val1 < 529){
val1 = map(val1, 491, 529, 0, 0);

analogWrite(5,val1);
analogWrite(6,val1);
}

if(val2 > 1 && val2 < 490){
val2 = map(val2, 1, 490, 255, 0);

analogWrite(10,val2);
analogWrite(9,0);
}

if(val2 > 530 && val2 < 1023){
val2 = map(val2, 530, 1023, 0, 255);

analogWrite(9,val2);
analogWrite(10,0);
}

if(val2 > 491 && val2 < 529){
val2 = map(val2, 491, 529, 0, 0);

analogWrite(9,val2);
analogWrite(10,val2);
}
Serial.println(val1);
Serial.println(val2);
}

Video:


Comments

  1. Replies
    1. can you tell us why cs i want to refer at this website

      Delete
  2. I got the thing to work but you can't follow the digital model, you have to follow the model that the creator made, Only issue I have is that one direction doesn't work with one of the motors. I'm sure I put a wire or messed up the coding somewhere. They just needed to be clearer on what you actually have to build for it to work.

    ReplyDelete

Post a Comment

Popular posts from this blog

Servo motor controlled by Joystick using Arduino & Transceiver - Wireles...

DC motor controlled by Joystick using Arduino & L298N Motor driver - Wireless Connection

DC motor controlled by Gyro MPU 6050 using Arduino & L298N Motor driver - Wired Connection