Hello everybody,
I am trying to run an old RC car using an arduino UNO with a L298p motor-shield and a 2.4 ghz receiver (4.5-6V). The power supply is a 9.6V 2000mAh NIMH battery pack.
The problem that I am encountering is that the car goes crazy (motors change direction rapidly...or go wide open) when a fully charged battery pack is being used. When the arduino is connected to a computer via USB everything works, and when the battery level drops to around 3/4 charge everything works.
I have tried to put 330 ohm resistors in series with the receiver's signal to the arduino. I have also put a capacitor across the power supply and across the motors being used. Neither of these seemed to make a difference. I checked the voltage on the 5v rail on the motor shield and it was reading around 6.7 V when the battery was full charged, and under 6.3 V when everything starts to work correctly. I thought maybe the receiver was getting to much voltage, so I tried powering it with a separate 4.5 V power supply. This didn't help solve the sporadic motor movement, but it did allow me to look at the raw input data from the receiver using the serial monitor. The throttle signal read between 600 and 6000, and the usually values are 1000-2000;
I don't know a whole lot about circuits, so any advice is welcome.
Is it common to have a large amount of noise in the receiver's signal that requires filtering, or is there a quick hardware fix?
Simple Arduino Program for the RC Car:
int E1 = 10;
int M1 = 12;
int E2 = 11;
int M2 = 13;
void setup() {
Serial.begin(9600);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(E1, OUTPUT);
pinMode(E2, OUTPUT);
}
void loop() {
int throttle = pulseIn(A1, HIGH); // Input from reciever for throttle control.
int RCsteerIN = pulseIn(A0, HIGH); // Input from reciever for steering control.
int rcAngle = -.0591 * RCsteerIN + 177.99; // Converts input signal to degrees.
int potIN = analogRead(A5); // Input from steering potentometer.
int potAngle = -.102 * potIN + 143.39; // Converts pot input to steering angle.
int steerWS = abs(rcAngle - potAngle) * 9; // Simple proportional controller
// Serial.print(throttle);
// Serial.print("\n");
// delay(500); // For debugging
//Throttle Control
if (throttle > 1610) { // FORWARD;
int ws = .7 * throttle - 1124.8;
if (ws > 255) {
ws = 255;
}
// Serial.print(ws);
// Serial.print("\n");
digitalWrite(M2, HIGH);
analogWrite(E2, ws);
}
else if (throttle < 1410) { // REVERSE
int ws = -.44 * throttle + 624.5;
if (ws > 255) {
ws = 255;
}
// Serial.print(ws);
// Serial.print("\n");
digitalWrite(M2, LOW);
analogWrite(E2, ws);
}
else {
int ws = 0;
analogWrite(E2, ws);
// Serial.print(ws);
// Serial.print("\n");
}
//// Steering Control
if (rcAngle - potAngle > 2) { // Turn Left
digitalWrite(M1, HIGH);
analogWrite(E1, steerWS);
}
else if (rcAngle - potAngle < -2 // Turn Right
) { // Turn Right
digitalWrite(M1, LOW);
analogWrite(E1, steerWS);
}
else {
analogWrite(E1, 0);
}
}