This is Arduino RC control car, the sketch tested good in a small motor, but burned two 60A drivers when put into 24V,500W motors, need help to find out whats wrong?
#include <VirtualWire.h>
//motor A connected between A01 and A02
//motor B connected between B01 and B02
int STBY = 2; //standby // mod: was 10 --2 ??
int count;
//Motor A
int PWMA = 9; //Speed control // need mod: was 3 change into 9
int AIN1 = 8; //Direction // was 9
int AIN2 = 7; //Direction
//Motor B
int PWMB = 10; //Speed control // need mod: was 5 change into 10
int BIN1 = 5; //Direction // was 6
int BIN2 = 4; //Direction ///was 16 put into p7 cause of Arduino uno no p16.
const boolean FORWARD = HIGH;
const boolean REVERSE = LOW;
float speed_Max = 252; //pwm usually goes from was:0-255 ////0-255 changed into 0-252
float speed_Min = 0;
float analogInput_Max = 1023;
float analogInput_Min = 0;
float analogInput_Middle_X = 515;//ideally it would be analogInput_Max / 2
float analogInput_Middle_Y = 495;//ideally it would be analogInput_Max / 2
float deadBand = 0;
float middleMax = (analogInput_Max / 2) + deadBand;
float middleMin = (analogInput_Max / 2) - deadBand;
boolean pastDirection = FORWARD;
void setup()
{
// Configure Timer 2 for PWM @ 14 kHz.
TCCR2A = 0; // undo the configuration done by...
TCCR2B = 0; // ...the Arduino core library
TCNT2 = 0; // reset timer
TCCR2A = _BV(COM2A1) // non-inverted PWM on ch. A
| _BV(COM2B1) // same on ch; B
| _BV(WGM20); // mode 10: ph. correct PWM, TOP = ICR1
TCCR2B = (TCCR2B & 0b11111000) | 0x01; //3.92116 [kHz] //** use this code got 3.9khz but joystick works not too good
{
Serial.begin(9600); // Debugging only
Serial.println("setup"); //Prints "Setup" to the serial monitor
vw_set_rx_pin(6); //Sets pin D12 as the RX Pin
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
pinMode(23, OUTPUT); //Relay one ////M1 added 2 was 2 -- 4
pinMode(25, OUTPUT); //Relay two
pinMode(27, OUTPUT); //Relay four
pinMode(29, OUTPUT); //Relay five
pinMode(31, OUTPUT); //Relay sex
pinMode(33, OUTPUT); //Relay seven
pinMode(35, OUTPUT); //Relay eight
pinMode(37, OUTPUT); //Relay three
pinMode(39, OUTPUT); //Relay three
pinMode(41, OUTPUT); //Relay eight
pinMode(43, OUTPUT); //Relay three
pinMode(45, OUTPUT); //Relay three
digitalWrite(23, HIGH);
digitalWrite(25, HIGH);
digitalWrite(27, HIGH);
digitalWrite(29, HIGH);
digitalWrite(31, HIGH);
digitalWrite(33, HIGH);
digitalWrite(35, HIGH);
digitalWrite(37, HIGH);
digitalWrite(39, HIGH);
digitalWrite(41, HIGH);
digitalWrite(43, HIGH);
digitalWrite(45, HIGH);
}
pinMode(STBY, OUTPUT); //// pin: the number of the pin whose mode you wish to set; mode: INPUT, OUTPUT, or INPUT_PULLUP.
pinMode(PWMA, OUTPUT);
pinMode(AIN1, OUTPUT);
pinMode(AIN2, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(BIN1, OUTPUT);
pinMode(BIN2, OUTPUT);
}
void loop() {
button(); //// disable 'button', no work. remove '//' enable, button works good
joystick(); //// disable 'joystick', no work. remove '//' enable, joystick works good, but no motor control yet
}
void joystick() {
uint8_t buf[VW_MAX_MESSAGE_LEN]; // This declares a variable array. instead of 7 variables buf1, buf2 etc...
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
int column = 0;
String message;
int commands[30];
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
//DEBUG:
//Serial.print(char(buf[i]));
if (char(buf[i]) == '|') {
commands[column] = message.toInt();
message = "";
column++;
} else {
message += char(buf[i]);
}
}
//one more time to capture the last value since the message does not end with |
commands[column] = message.toInt();
// DEBUG
// Serial.print("X: ");
// Serial.print(commands[0]);
// Serial.print(" Y: ");
// Serial.println(commands[1]);
motorControl(commands[0], commands[1]);
}
}
void move(int motor, int speed, boolean direction) {
digitalWrite(STBY, HIGH); //disable standby
if (motor == 1) {
digitalWrite(AIN1, direction);
digitalWrite(AIN2, !direction);
analogWrite(PWMA, speed);
} else {
digitalWrite(BIN1, !direction);
digitalWrite(BIN2, direction);
analogWrite(PWMB, speed);
}
}
void motorControl(float x, float y) {
boolean currentDirection = y >= analogInput_Middle_Y;
//map(value, fromLow, fromHigh, toLow, toHigh);
if (currentDirection == REVERSE) {
y = map(y, analogInput_Middle_Y, analogInput_Min, speed_Min, speed_Max) ;
} else {
y = map(y, analogInput_Middle_Y, analogInput_Max, speed_Min, speed_Max);
}
int subtractFromLeft = map(x, analogInput_Middle_X, analogInput_Min, speed_Min, y);
int subtractFromRight = map(x, analogInput_Middle_X, analogInput_Max, speed_Min, y);
if (subtractFromRight < 0) {
subtractFromRight = 0;
}
if (subtractFromLeft < 0) {
subtractFromLeft = 0;
}
int Throttle_RIGHT = y - subtractFromRight;
int Throttle_LEFT = y - subtractFromLeft;
boolean currentDirection_LEFT = currentDirection;
boolean currentDirection_RIGHT = currentDirection;
if (Throttle_LEFT < 1 && Throttle_RIGHT > 1) {
currentDirection_LEFT = !currentDirection;
Throttle_LEFT = Throttle_RIGHT;
}
if (Throttle_RIGHT < 1 && Throttle_LEFT > 1) {
currentDirection_RIGHT = !currentDirection;
Throttle_RIGHT = Throttle_LEFT;
}
move(1, Throttle_LEFT, currentDirection_LEFT);
move(2, Throttle_RIGHT, currentDirection_RIGHT);
}
void button()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
int c = (buf[i]);
Serial.print(c);
Serial.print(" ");
if (c == 65 ) {
digitalWrite(23, !digitalRead(23)); //// A--RELAY A1
}
if (c == 66 ) {
digitalWrite(25, !digitalRead(25)); //// B--RELAY A2
}
if (c == 67 ) {
digitalWrite(27, !digitalRead(27)); //// C--RELAY B1
}
if (c == 68 ) {
digitalWrite(29, !digitalRead(29)); //// D--RELAY B2
}
/*
if (c == 69 ) {
digitalWrite(37, !digitalRead(37)); //// E--
}
if (c == 70 ) {
digitalWrite(39, !digitalRead(39)); //// F--
}
*/
if (c == 71 ) {
digitalWrite(31, !digitalRead(31)); //// G--RELAY C1
}
if (c == 72 ) {
digitalWrite(33, !digitalRead(33)); //// H -- RELAY C2
}
if (c == 73 ) {
digitalWrite(43, !digitalRead(43)); //// I --
}
if (c == 74 ) {
digitalWrite(35, !digitalRead(35)); //// J --
}
if (c == 75 ) {
digitalWrite(37, !digitalRead(37)); //// K --
}
if (c == 76 ) {
digitalWrite(39, !digitalRead(39)); //// L --
}
if (c == 77 ) {
digitalWrite(41, !digitalRead(41)); //// M --
}
if (c == 78 ) {
digitalWrite(35, !digitalRead(35)); //// N --
}
}
count++;
// Serial.print(count);
Serial.println("");
digitalWrite(13, false);
}
}
My new driver is came, I just scare to use it, heard that DC motor will draw upto 300A at the start, what should I do to reduce the start current?