Controller:
const int accel(0);
const int steer(1);
void setup() {
// SETUP CODE:
Serial.begin(9600);
}
void loop() {
// MAIN CODE:
int accelVal(map(analogRead(accel), 0, 1023, -255, 255));
int steerVal(map(analogRead(steer), 0, 1023, 45, 135));
Serial.print(accelVal);
Serial.print(",");
Serial.println(steerVal);
}
Car:
#include <Servo.h>
Servo steering;
const int motorF(11);
const int motorB(10);
void setup() {
// SETUP CODE:
Serial.begin(9600);
pinMode(motorF, OUTPUT);
pinMode(motorB, OUTPUT);
steering.attach(9);
}
void loop() {
// MAIN CODE:
if (Serial.available()) {
String values(Serial.readStringUntil('\n'));
values.trim();
char vals[10];
values.toCharArray(vals, 10);
int accel(atoi(strtok(vals, ",")));
int steer(atoi(strtok(NULL, ",")));
if (accel < 0) {
accel = 0 - accel;
analogWrite(motorF, 0);
analogWrite(motorB, accel);
} else if (accel == 0) {
analogWrite(motorF, 0);
analogWrite(motorB, 0);
} else {
analogWrite(motorF, accel);
analogWrite(motorB, accel);
}
steering.write(steer);
}
}
Parts:
Receiver:
Servo motor (x1)
DC motor (any quantity will work; use a double shaft motor if using only one motor)
HC-05 Bluetooth module.
L293D motor driver
Transmitter:
X-axis 1-dimensional joystick
Y-axis 1-dimensional joystick
HC-05 Bluetooth module
Note: You can use a single 2-dimensional joystick, but the two 1-dimensional joystick configuration is recommended for a better user experience.
To make the car, make sure you give forward motor output by connecting pin 11, and give backward motor output with pin 10 to the motor driver. Connect the motor(s) to the driver to spin in two directions. You can use a setup with more motors in parallel, though a single motor setup, utilizing a double-shaft motor, is recommended. Connect your servo motor to pin 9, and make sure that 90 degrees on the servo motor corresponds to the wheels of the car pointing straight ahead. Connect the HC-05 Bluetooth module’s RX to the TX of the Arduino, and the TX to the RX of the Arduino. Additionally, for safety, you can opt to add a voltage divider to safely operate the HC-05 with a 1kΩ resistor between the Arduino TX and HC-05 RX, and a 2kΩ resistor between the HC-05 RX and the ground.
To make the controller, hook up the Y-axis to analog pin 0, and the X-axis to analog pin 1, and in the same manner from above, connect the HC-05 to the Arduino, and make sure everything is grounded properly.
Additionally, make sure that the two HC-05 Bluetooth modules are paired in a master-slave configuration.
Happy building!