Hi, I am working on a class project for my Mechatronics class and am having circuit problems.
I am trying to control a robot using two BLDC motors, BLDC motor drivers, and an Arduino Uno.
BLDC Motor Driver Specs and Diagram:
https://myosuploads3.banggood.com/products/20190508/20190508220426SKU600181WS55-1801.pdf
Here is the connection diagram:
The arduino is powered using an external battery that came with it in a kit in which I have used many times without issue. The motor drivers are being powered by a power supply of around 23-24 V (I did not include in the picture, but before the splice there are Voltage step downs that will reduce 36V/48V down to 24V, but it does not matter as our testing power supply only reaches 24V).
The motor drivers turn on and work fine, and the arduino is powered and able to upload code. The problem occurs when both the motor drivers are turned on and the arduino is on and code is running (we only had both on once code was uploaded already). In the first two instances, the motors were moving but eventually stopped. Then after a few moments the lights on the arduino went out. The third instance there was no motor motion and moments later the lights went out too. For all three arduinos when powered separately with external battery, the LEDs work fine but the RESET button does not work. We then tried uploading code to the arduinos and the computer detects their COMs but displays “Uploading” forever. Eventually it ends and displays a long error concerning “avrdude.”
There must be something wrong with my circuits/connections, or code that is killing them. Here is my code:
#include <Arduino.h>
#include <avr/wdt.h>
#include "DeviceDriverSet_xxx0.h"
// #define Max_Distance 200 // in centimeters
#define SV1 7 // Motor1 Direction
#define SV2 6 // Motor2 Direction
#define ALM1 5 // Motor1 Speed
#define ALM2 4 // Motor2 Speed
#define EN1 3 // Driver1 On/Off
#define EN2 2 // Driver2 On/Off
// #define FR1 __ // Motor1 Forward/Reverse // Will use if ALM does not work
// #define FR2 __ // Motor2 Forward/Reverse
DeviceDriverSet_ULTRASONIC myUltrasonic;
int (n); // Min distance from obstacle by sensor in cm
int (tempda_f);
int (tempda_l);
int (tempda_r);
void setup() {
Serial.begin(9600);
myUltrasonic.DeviceDriverSet_ULTRASONIC_Init();
pinMode (EN1, OUTPUT); // Will use if declaring EN pins is not enough
pinMode (EN2, OUTPUT);
pinMode(SV1, OUTPUT);
pinMode(SV2, OUTPUT);
pinMode(ALM1, OUTPUT);
pinMode(ALM2, OUTPUT);
// pinmode(FR1, OUTPUT)
// pinmode(FR2, OUTPUT)
digitalWrite(EN1, LOW);
digitalWrite(EN2, LOW);
}
void Stop() {
digitalWrite(SV1, HIGH); // May or may not need here
digitalWrite(SV2, HIGH); // May or may not need here
analogWrite(ALM1, LOW);
analogWrite(ALM2, LOW);
}
void Forward() {
digitalWrite(SV1, HIGH);
digitalWrite(SV2, HIGH);
analogWrite(ALM1, 100); // Can change speed if needed
analogWrite(ALM2, 100);
}
void Backward() {
digitalWrite(SV1, LOW);
digitalWrite(SV2, LOW);
analogWrite(ALM1, 100);
analogWrite(ALM2, 100);
}
void Right() { // May need to change label if reversed
digitalWrite(SV1, HIGH);
digitalWrite(SV2, LOW);
analogWrite(ALM1, 100);
analogWrite(ALM2, 100);
}
void Left() { // May need to change label if reversed
digitalWrite(SV1, LOW);
digitalWrite(SV2, HIGH);
analogWrite(ALM1, 100);
analogWrite(ALM2, 100);
}
// void loop() {
// n = 10; // Minimum distance from sensor to obstacle in cm
// if (tempda_f <= n) { // If front sensor is less than or equal to n, stop
// Stop();
// delay(1000); // Can choose to get rid of delay if result is smoother motion
// if (tempda_l > tempda_r) { // If left sensor distance is greater than right sensor, go left
// Left();
// }
// else { // If not, go right
// Right();
// }
// }
// else { // If not, go forward
// Forward();
// }
// }
// // Preset Test motion without sensors:
// void loop() {
// delay(5000);
// Forward();
// delay(3000);
// Stop();
// delay(2000);
// Right();
// delay(1000);
// Stop();
// delay(2000);
// Left();
// delay(2000);
// Stop();
// delay(2000);
// Backward();
// delay(3000);
// Stop();
// delay(2000);
// }
void loop() {
Forward();
}
There are two other code files but they are only for the the eventual usage of ultrasonic sensors, but before we tried those we just wanted to see if we could get it to run simple direction commands. The only command we tested was the final void loop() Forward. Some of the code is for ultrasonic sensors but that is not of concern right now. (Note: EN must be LOW to initialize driver).
What I think it may be is too many Amps, or something going on with the GND from drivers to arduino, or the code. I made sure they were all outputs though so nothing should be coming in. Also, although the motor drivers work off of 10V and the arduino can only output 5V, other groups have no problem controlling the drivers from direct wiring from arduino to drivers.
I don’t have many arduinos left and I don’t know how to figure out the problem without testing with more. Help would be greatly appreciated.