JoyStick Controlled Car

 


Remote controlled and autonomous cars fascinate everyone. And being able to understand their working, and most importantly, being able to make them is a wonderful skill and experience. Therefore, in this project, we will learn to make a joystick-controlled car using Arduino. 

Joy Stick Working Mechanism 



The Joy stick we'll be using is similar to one in your gaming controllers. We can move it horizontally and vertically. Additionally, it has a push button. The horizontal and vertical displacements of joysticks are tracked using VRx and VRy pins respectively. And the state of push-button, 1 or 0 is tracked via SW pin. The image below explains in more detail how the output of the joystick changes with a change in the joystick's movement. 


Hardware Assembly of Car

Coming to hardware of car, it can be divided into two parts, assembly of chassis and components and circuit patching. You may refer to video at the end of article to get visual representation of assembly and circuit patching.

Hardware Required

• Joy Stick
• Motor Driver
• 2 Motors
• 9V battery
• Chassis
• Wheels
• Jumper Cables
• Arduino UNO

Assembly


Circuit Patching





Software- Arduino IDE

int xVal; //X values from joystick
int yVal; //Y values from joystick
//Motor pins
int in1 = 8;
int in2 = 9;
int in3 = 6;
int in4 = 7;
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT); //JoyStick
pinMode(A1, INPUT);
pinMode(in1, OUTPUT); // Motors
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}
void loop() {
xVal= analogRead(A0);
yVal= analogRead(A1);
Serial.print(" Y is...");
Serial.println(yVal); //prints Y values
Serial.print(" X is...");
Serial.println(xVal);
if((600>xVal && xVal>400) && (600>yVal && yVal>400))
{
Serial.print("Stop");
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
else if( (600>xVal && xVal>400) && yVal < 511) // forward
{
Serial.print("Forward");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
else if((600>xVal && xVal>400) && yVal > 511) //backward
{
Serial.print("Backward");
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
else if(xVal > 511 &&(600>yVal && yVal>400)) //right
{
Serial.print("Right");
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
else if (xVal < 511 && (600>yVal && yVal>400))//left
{
Serial.print("Left");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
}

DEMO

By assembling hardware as shown above, patching the circuit correctly, and uploading the code through Arduino IDE your car shall be ready to work, just like ours was. To see how it worked refer to the video below. 




It's really exciting to make your 1st car, and it's even more fun when it works properly without any errors or bugs. In case you encounter some error, feel free to share the error with us in comments section. We'll help you resolve it. 

Comments

Popular Posts

How To Make Line Follower Using Three IR Sensor | Arduino Line Following Car

How To Make Line Follower Car with Speed Control | 6 IR Sensor Arduino Line Following Car