Building an RC Car at Home Using Arduino
Are you an electronics enthusiast who loves remote-controlled cars? In this step-by-step guide, we will show you how to create your very own RC car using readily available components such as Arduino ATmega 2560, an L298 motor driver, a 3-cell 18650 battery holder, Flysky FS-i6 transmitter, an FS-iA6B receiver. With a little bit of creativity and technical know-how, you'll be zooming around in your custom-built RC car in no time.
Section 1: Gathering the Components
3. 3-cell 18650 Battery Holder: Provides the necessary power to drive the motors and Arduino board.
4. Flysky FS-i6 Transmitter: A reliable and feature-rich transmitter for controlling your RC car remotely.
Section 2: Assembling the Chassis
2. Attach the motors to the chassis using brackets and screws. Ensure they are firmly secured to avoid any unnecessary vibrations.
Section 3: Wiring the Electronics
2. Connect the motors to the motor driver. Make sure to follow the correct polarity (positive and negative) for each motor.
3. Wire the FS-iA6B receiver to the Arduino board, allowing it to receive signals from the transmitter. Again, consult the datasheets for pinout information.
Section 4: Programming the Arduino
4. Upload the code to your Arduino board and make any necessary adjustments or fine-tuning.
Code:
*/
#include <IBusBM.h>
// Create iBus Object
IBusBM ibus;
// Channel Values
int rcCH1 = 0; // Left - Right
int rcCH2 = 0; // Forward - Reverse
int rcCH3 = 0; // Acceleration
int rcCH5 = 0; // Spin Control
bool rcCH6 = 0; // Mode Control
// LED Connection
#define carLED 13
// Motor A Control Connections
#define pwmA 3
#define in1A 5
#define in2A 4
// Motor B Control Connections
#define pwmB 9
#define in1B 7
#define in2B 8
// TB6612FNG Standby Pin
#define stby 6
// Motor Speed Values - Start at zero
int MotorSpeedA = 0;
int MotorSpeedB = 0;
// Motor Direction Values - 0 = backward, 1 = forward
int MotorDirA = 1;
int MotorDirB = 1;
// Control Motor A
void mControlA(int mspeed, int mdir) {
// Determine direction
if (mdir == 0) {
// Motor backward
digitalWrite(in1A, LOW);
digitalWrite(in2A, HIGH);
} else {
// Motor forward
digitalWrite(in1A, HIGH);
digitalWrite(in2A, LOW);
}
// Control motor
analogWrite(pwmA, mspeed);
}
// Control Motor B
void mControlB(int mspeed, int mdir) {
// Determine direction
if (mdir == 0) {
// Motor backward
digitalWrite(in1B, LOW);
digitalWrite(in2B, HIGH);
} else {
// Motor forward
digitalWrite(in1B, HIGH);
digitalWrite(in2B, LOW);
}
// Control motor
analogWrite(pwmB, mspeed);
}
// Read the number of a given channel and convert to the range provided.
// If the channel is off, return the default value
int readChannel(byte channelInput, int minLimit, int maxLimit, int defaultValue) {
uint16_t ch = ibus.readChannel(channelInput);
if (ch < 100) return defaultValue;
return map(ch, 1000, 2000, minLimit, maxLimit);
}
// Read the channel and return a boolean value
bool readSwitch(byte channelInput, bool defaultValue) {
int intDefaultValue = (defaultValue) ? 100 : 0;
int ch = readChannel(channelInput, 0, 100, intDefaultValue);
return (ch > 50);
}
void setup()
{
// Start serial monitor for debugging
Serial.begin(115200);
// Attach iBus object to serial port
ibus.begin(Serial1);
// Set all the motor control pins to outputs
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(in1A, OUTPUT);
pinMode(in2A, OUTPUT);
pinMode(in1B, OUTPUT);
pinMode(in2B, OUTPUT);
pinMode(stby, OUTPUT);
// Set LED pin as output
pinMode(carLED, OUTPUT);
// Keep motors on standby for two seconds & flash LED
digitalWrite(stby, LOW);
digitalWrite(carLED, HIGH);
delay (1000);
digitalWrite(carLED, LOW);
delay (1000);
digitalWrite(stby, HIGH);
}
void loop() {
// Get RC channel values
rcCH1 = readChannel(0, -100, 100, 0);
rcCH2 = readChannel(1, -100, 100, 0);
rcCH3 = readChannel(2, 0, 155, 0);
rcCH5 = readChannel(4, -100, 100, 0);
rcCH6 = readSwitch(5, false);
// Print values to serial monitor for debugging
Serial.print("Ch1 = ");
Serial.print(rcCH1);
Serial.print(" Ch2 = ");
Serial.print(rcCH2);
Serial.print(" Ch3 = ");
Serial.print(rcCH3);
Serial.print(" Ch5 = ");
Serial.print(rcCH5);
Serial.print(" Ch6 = ");
Serial.println(rcCH6);
// Set speeds with channel 3 value
MotorSpeedA = rcCH3;
MotorSpeedB = rcCH3;
// Set Mode with channel 6 value
if (rcCH6) {
// Spin Mode
// Turn on LED
digitalWrite(carLED, HIGH);
// Get Direction from channel 5 value
if (rcCH5 >= 0) {
//Clockwise
MotorDirA = 0;
MotorDirB = 1;
Serial.println("Clockwise");
} else {
//Counter-Clockwise
MotorDirA = 1;
MotorDirB = 0;
Serial.println("Counter-Clockwise");
}
// Add Motorspeed to channel 5 value
MotorSpeedA = MotorSpeedA + abs(rcCH5);
MotorSpeedB = MotorSpeedB + abs(rcCH5);
} else {
// Normal Mode
// Turn off LED
digitalWrite(carLED, LOW);
// Set forward/backward direction with channel 2 value
if (rcCH2 >= 0) {
//Forward
MotorDirA = 1;
MotorDirB = 1;
Serial.println("Forward");
} else {
//Backward
MotorDirA = 0;
MotorDirB = 0;
Serial.println("Backward");
}
// Add channel 2 speed
MotorSpeedA = MotorSpeedA + abs(rcCH2);
MotorSpeedB = MotorSpeedB + abs(rcCH2);
// Set left/right offset with channel 1 value
MotorSpeedA = MotorSpeedA - rcCH1;
MotorSpeedB = MotorSpeedB + rcCH1;
}
// Ensure that speeds are between 0 and 255
MotorSpeedA = constrain(MotorSpeedA, 0, 255);
MotorSpeedB = constrain(MotorSpeedB, 0, 255);
//Drive Motors
mControlA(MotorSpeedA, MotorDirA);
mControlB(MotorSpeedB, MotorDirB);
// Print speed values to serial monitor for debugging
Serial.print("Motor A Speed = ");
Serial.print(MotorSpeedA);
Serial.print(" | Motor B Speed = ");
Serial.println(MotorSpeedB);
// Slight delay
delay(50);
}
Section 5: Testing and Fine-Tuning
1. Power up your RC car by connecting the battery.
2. Turn on the transmitter and ensure it is bound to the receiver.3. Gradually apply the throttle on the transmitter and observe the response of the RC car.
4. Test the steering functionality and make any adjustments if needed.
5. Fine-tune the code and electronics as required to optimize the performance of your RC car.
Reference Video:
Conclusion:
Congratulations! You have successfully built your very own RC car using Arduino ATmega 2560, L298 motor driver, 3-cell 18650 battery holder, Flysky FS-i6 transmitter, and FS-iA6B receiver. With your newfound knowledge, you can continue to experiment, modify, and improve your RC car further. Get ready to enjoy endless hours of exhilarating remote-controlled fun, exploring different terrains and challenging your driving skills. Remember to always prioritize safety while operating your RC car, especially in public areas or when interacting with other vehicles.
In addition to the basic build, there are several advanced modifications and enhancements you can consider:
1. Suspension System: Install a suspension system to improve the car's stability and handling on uneven surfaces. This will allow your RC car to navigate through rough terrains with ease.2. LED Lights: Add LED lights to your RC car to enhance its appearance and enable night-time driving. You can install headlights, taillights, and even underbody lights to give your car a stylish and eye-catching look.
3. Wireless Camera: Incorporate a wireless camera module into your RC car to capture exciting videos or explore hard-to-reach areas. This will give you a first-person view (FPV) experience, allowing you to control your car while seeing through its perspective.
4. Smartphone Integration: Use Bluetooth or Wi-Fi connectivity to link your RC car to a smartphone app. This will enable you to control your car using your phone's touchscreen, access additional features, and even record telemetry data.
5. Custom Body Shell: Design and 3D print a custom body shell for your RC car to give it a unique appearance. You can create your own designs or find existing models online that match your preferences.
6. Performance Upgrades: Upgrade the motors, battery, or motor driver to enhance the speed, torque, and overall performance of your RC car. Just make sure the upgraded components are compatible with your existing setup.
Remember, the joy of building and modifying an RC car lies in experimentation and personalization. Don't be afraid to explore different ideas, incorporate your own creativity, and share your experiences with the RC car enthusiast community.
As you continue your RC car journey, stay updated with the latest developments in Arduino programming, motor control, and wireless communication. By staying informed and actively engaging with the RC community, you'll find endless possibilities to expand your knowledge and take your RC car projects to new heights.
So, what are you waiting for? Unleash your inner engineer, grab your tools, and embark on an exciting adventure of building and customizing your very own Arduino-based RC car!
No comments