Hi everyone, I'm working on a robot car for a circus show that I am producing. This car will be a vase that has a personality and will follow around performers etc.. I am very new to robotics and have heavily leaned on chatgpt to help make this thing and also watched a lot of youtube videos (I don't know anyone using this stuff personally to help me). I'm feeling much more up to speed but still feel lost. I feel like I'm missing something very simple. Hoping to get some guidance on this project here in this community.
Here is what I have :::
Arduno Uno
VNH5019 dual motor drive shield
FS-i6X transmitter remote control
FS-iA6B receiver
12v LIFePO4 battery
D24V50F5 step down voltage regulator for 5v
37D Metal gearmotors 12v 50:1 gear ratio
Mecanum wheels.
The plan is 12v supplies power to the step down and the motor drivers, 5v supplies power to the receiver and the Arduino through the shield. 12v out to left side motors and right side motors. Tank style. Shared grounds for everything.
PWM CH1 and CH2 going to D2 and D3 sent through the shield.
Seems pretty standard from what I have seen out there.
I've tried wiring it using PPM through CH1/PPM on the receiver and changing the settings in the remote. I've tried Ibus and using those settings. I've tried wiring it all the different ways I've seen on youtube and using their codes that they provide. Nothing has worked.
I have put a code in that makes all the wheels spin forward that overrides the RX and TX and that works perfect when supplying 12v power. When running the codes and looking at the serial monitor of the numbers of CH1 Ch2 I only get only 1 channel at a time. I can see by the values that when I swap the wires on the Arduino side or the receiver side that the data is being sent and received. I have also plugged in a little servo and checked all channels. All seem to work.
So excited to be learning this stuff but feeling a bit stuck. Any help would be appreciated.
I've tried to include a "sketch" of my circuit and also one of the hundreds of codes I've run through my poor little board.
// Basic PWM RC Car Tank Drive (Proven Version)
// Motor 1 (Right side)
const int M1INA = 2;
const int M1INB = 4;
const int M1PWM = 9;
// Motor 2 (Left side)
const int M2INA = 7;
const int M2INB = 8;
const int M2PWM = 10;
// Receiver input pins
const int ch1Pin = 2; // CH1 (Right stick)
const int ch2Pin = 3; // CH2 (Left stick)
void setup() {
Serial.begin(9600);
// Setup motor pins
pinMode(M1INA, OUTPUT);
pinMode(M1INB, OUTPUT);
pinMode(M1PWM, OUTPUT);
pinMode(M2INA, OUTPUT);
pinMode(M2INB, OUTPUT);
pinMode(M2PWM, OUTPUT);
// Setup receiver pins
pinMode(ch1Pin, INPUT);
pinMode(ch2Pin, INPUT);
}
void loop() {
// Read PWM signals with a 25ms timeout
int rightPulse = pulseIn(ch1Pin, HIGH, 25000);
int leftPulse = pulseIn(ch2Pin, HIGH, 25000);
// Safety check
if (rightPulse == 0 || leftPulse == 0) {
stopMotors();
return;
}
// Map 1000-2000us pulse width to motor speed -255 to 255
int rightSpeed = map(rightPulse, 1000, 2000, -255, 255);
int leftSpeed = map(leftPulse, 1000, 2000, -255, 255);
// Deadband to prevent noise near center
if (abs(rightSpeed) < 20) rightSpeed = 0;
if (abs(leftSpeed) < 20) leftSpeed = 0;
// Set motors
setMotor(M1PWM, M1INA, M1INB, rightSpeed); // Right side motors
setMotor(M2PWM, M2INA, M2INB, leftSpeed); // Left side motors
// Debug output
Serial.print("Right: ");
Serial.print(rightSpeed);
Serial.print("\tLeft: ");
Serial.println(leftSpeed);
delay(10); // Small stability delay
}
void setMotor(int pwmPin, int inAPin, int inBPin, int speed) {
if (speed > 0) {
digitalWrite(inAPin, HIGH);
digitalWrite(inBPin, LOW);
analogWrite(pwmPin, speed);
} else if (speed < 0) {
digitalWrite(inAPin, LOW);
digitalWrite(inBPin, HIGH);
analogWrite(pwmPin, -speed);
} else {
digitalWrite(inAPin, LOW);
digitalWrite(inBPin, LOW);
analogWrite(pwmPin, 0);
}
}
void stopMotors() {
digitalWrite(M1INA, LOW);
digitalWrite(M1INB, LOW);
analogWrite(M1PWM, 0);
digitalWrite(M2INA, LOW);
digitalWrite(M2INB, LOW);
analogWrite(M2PWM, 0);
}
