DIY Projects

DIY Project: Car Kits Controlled by Mobile Using Arduino

Introduction

Are you a fan of DIY projects and have a passion for cars? If so, you’re in for a treat! In this blog post, we will guide you through a step-by-step process of creating your own car kit controlled by a mobile device using Arduino.

Materials Needed

Building the Circuit

The first step in this project is to assemble the hardware. Start by connecting the HC-05 Bluetooth module to the Arduino Uno. Connect the TX pin of the Bluetooth module to the RX pin of the Arduino and vice versa. Next, connect the motor driver to the Arduino. Connect the IN1, IN2, IN3, and IN4 pins of the motor driver to the digital pins of the Arduino. Finally, connect the motors of the 4-wheel car kit to the motor driver.

Writing the Code

Now that the circuit is set up, it’s time to write the code. Open the Arduino IDE and create a new sketch. First, include the SoftwareSerial library and define the RX and TX pins for the Bluetooth module. Next, create variables for the motor pins and set them as outputs. In the setup function, initialize the serial communication and set the motor pins as outputs. In the loop function, read the data from the Bluetooth module and control the motors accordingly. You can use the Serial.read() function to read the data and the digitalWrite() function to control the motors.

[sourcecode language=”Arduino”]
#include<SoftwareSerial.h>
#define IN1 12
#define IN2 11
#define IN3 10
#define IN4 9
//#define EN1 6
//#define EN2 5
SoftwareSerial mySerial(2, 3); // RX, TX

String data;
int btVal;

void setup()
{
//Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
//pinMode(EN1, OUTPUT);
//pinMode(EN2, OUTPUT);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
//analogWrite(EN1,63);
//analogWrite(EN2,63);
mySerial.begin(9600);
}

void loop()
{
while (mySerial.available())
{
{
data = mySerial.readStringUntil('\n');
//Serial.print(str);
}

btVal = (data.toInt());
//Serial.print("BlueTooth Value ");
//Serial.println(btVal);

&amp;amp;amp;amp;amp;nbsp;

switch (btVal)
{
case 1:
//Serial.println("Forward");
forward();
break;

case 2:
//Serial.println("Reverse");
reverse();
break;

case 3:
//Serial.println("Left");
left();
break;

case 4:
//Serial.println("Right");
right();
break;

case 5:
//Serial.println("Stop");
stoprobot();
break;

}

}

if (mySerial.available() &amp;amp;amp;amp;lt; 0)
{
//Serial.println("No Bluetooth Data ");
}

}

void forward()
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}

void reverse()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}

void left()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}

void right()
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}

void stoprobot()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
[/sourcecode]

 

Testing and Troubleshooting

Once you have uploaded the code to the Arduino, you can test the car kit. Connect the Arduino to a power source and pair your mobile device with the HC-05 Bluetooth module. Open a serial terminal app on your mobile device and send commands to control the car. If the car is not responding as expected, double-check the wiring and code for any errors.

Conclusion

Congratulations! You have successfully created your own car kit controlled by a mobile device using Arduino. This project combines your love for DIY projects and cars, allowing you to have a unique and fun experience. Now it’s time to take your car for a spin and impress your friends with your technical skills!

Leave a Reply

Your email address will not be published. Required fields are marked *