Hi. I am making a car which contains 4 9V motors... these motos are attached to the adafruit l293D motor shield which is on top of the arduino. the motor shield is receiving 12 V dc from a 3 lion cells all connected in series.. i am using the FlySky CT6B as a method of wireless communication. when throttling the motor Shield heats up to extreme tempratures...
Here is my code -
#include <AFMotor.h>
//initial motors pin
AF_DCMotor mlf(1);
AF_DCMotor mlb(2);
AF_DCMotor mrb(3);
AF_DCMotor mrf(4);
const unsigned long minPulseWidth = 1231; // Example: replace with your minCh1
const unsigned long maxPulseWidth = 1876; // Example: replace with your maxCh1
const int ch1Pin = 10;
const int ch2Pin = 9;
unsigned long ch1Value;
unsigned long ch2Value;
int steer;
int throttle;
int deadzone = 10;
int motorDirection = 1;
void setup() {
Serial.begin(9600);
pinMode(ch1Pin, INPUT);
pinMode(ch2Pin, INPUT);
mlf.run(RELEASE);
mlb.run(RELEASE);
mrf.run(RELEASE);
mrb.run(RELEASE);
}
void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
mrf.setSpeed(abs(rightMotorSpeed));
mrb.setSpeed(abs(rightMotorSpeed));
mlf.setSpeed(abs(leftMotorSpeed));
mlb.setSpeed(abs(leftMotorSpeed));
if (rightMotorSpeed < 0)
{
mrf.run(BACKWARD);
mrb.run(BACKWARD);
}
else if (rightMotorSpeed > 0)
{
mrf.run(FORWARD);
mrb.run(FORWARD);
}
else
{
mrf.run(RELEASE);
mrb.run(RELEASE);
}
if (leftMotorSpeed < 0)
{
mlf.run(BACKWARD);
mlb.run(BACKWARD);
}
else if (leftMotorSpeed > 0)
{
mlf.run(FORWARD);
mlb.run(FORWARD);
}
else
{
mlf.run(RELEASE);
mlb.run(RELEASE);
}
}
void loop() {
// Read pulse width of channel 1 in microseconds
ch1Value = pulseIn(ch1Pin, HIGH);
ch2Value = pulseIn(ch2Pin, HIGH);
// Check if pulseIn() returns 0 (indicating a timeout)
if (ch1Value == 0) {
// If no valid signal is read, set mappedCh1 to 0 or a safe default
steer = 0;
} else {
// Map ch1Value from actual min/max range to -255 to 255
steer = map(ch1Value, minPulseWidth, maxPulseWidth, -100, 100);
// Constrain the mapped value to make sure it's within -255 to 255
steer = constrain(steer, -100, 100);
}
if (ch2Value == 0) {
// If no valid signal is read, set mappedCh1 to 0 or a safe default
throttle = 0;
} else {
// Map ch1Value from actual min/max range to -255 to 255
throttle = map(ch2Value, minPulseWidth, 1890, -100, 100);
// Constrain the mapped value to make sure it's within -255 to 255
throttle = constrain(throttle , -100, 100);
}
if(steer > -20 && steer < deadzone ){
steer = 0;
}
if(throttle > -deadzone && throttle < deadzone ){
throttle = 0;
}
int rightMotorSpeed = 0;
int leftMotorSpeed = 0;
if (throttle < 0){
motorDirection = -1;
} else{
motorDirection = 1;
}
if (steer == 0) {
// No steering input, both motors get the same speed
rightMotorSpeed = abs(throttle);
leftMotorSpeed = abs(throttle);
} else {
// Adjust motor speeds for turning
rightMotorSpeed = abs(throttle) - steer;
leftMotorSpeed = abs(throttle) + steer;
}
rightMotorSpeed = constrain(rightMotorSpeed, -100, 100);
leftMotorSpeed = constrain(leftMotorSpeed, -100, 100);
rotateMotor(rightMotorSpeed * motorDirection, leftMotorSpeed * motorDirection);
Serial.print(rightMotorSpeed * motorDirection);
Serial.print(" - ");
Serial.println(leftMotorSpeed * motorDirection);
Serial.println(throttle);
delay(100);
}
what could be the issue????
Extra info---- When throttling the motor shield becomes very hot but as soon as i stop throtting, within 10-15 seconds it cools down
i need this car for a competition of speed so too much head could be fatal