I control my 48 volt BLDC motor with the Kelly driver, I can move the motor by making the necessary connections with the accelerator pedal, but I want to move my motor with my Arduino code instead of the accelerator pedal.I connect the 3 phase cable from my BLDC motor to my drive I connect my hall sensor cables and GND and 5v pins to both my drive and Arduino I connect the hall sensor A, B and C cables to both my drive and Arduino. To move it with the code, instead of connecting the accelerator pedal directly from my Arduino, I connect one to the GND drive, one to the 5v and signal D9 digital pin.But my engine is not moving with my code, I'm waiting for your ideas on what I need to do.
const int hallA = 2;
const int hallB = 3;
const int hallC = 4;
const int motorPWM = 9;
volatile int count = 0;
unsigned long lastTime = 0;
float rpm = 0;
unsigned long lastInterruptTime = 0;
void setup() {
pinMode(hallA, INPUT);
pinMode(hallB, INPUT);
pinMode(hallC, INPUT);
pinMode(motorPWM, OUTPUT);
attachInterrupt(digitalPinToInterrupt(hallA), hallInterrupt, RISING);
attachInterrupt(digitalPinToInterrupt(hallB), hallInterrupt, RISING);
attachInterrupt(digitalPinToInterrupt(hallC), hallInterrupt, RISING);
Serial.begin(9600);
}
void loop() {
unsigned long currentTime = millis();
if (currentTime - lastTime >= 1000) {
rpm = (count / 3.0) * 60.0;
lastTime = currentTime;
count = 0;
Serial.print("RPM: ");
Serial.println(rpm);
Serial.print("Hall A: ");
Serial.println(digitalRead(hallA));
Serial.print("Hall B: ");
Serial.println(digitalRead(hallB));
Serial.print("Hall C: ");
Serial.println(digitalRead(hallC));
analogWrite(motorPWM, 200); // Set a PWM value to control motor speed
}
}
void hallInterrupt() {
unsigned long currentInterruptTime = millis();
if (currentInterruptTime - lastInterruptTime > 10) {
count++;
lastInterruptTime = currentInterruptTime;
}
}