Hello everyone so i finally make my custom controller for BLDC Motor working using MOSFET IRF540N as power circuit and IC IR2101 as switching device controlled by Arduino UNO. The thing is when i power it on, my BLDC start moving automatically before i even use my throttle. I suspect this is something wrong with my code, can someone help me? here's my code.
const int HallApin = 7;
const int HallBpin = 6;
const int HallCpin = 5;
const int potPin = A0;
int HallAState = 0;
int HallBState = 0;
int HallCState = 0;
const int D2pin = 2;
const int D3pin = 3;
const int D4pin = 4;
const int D9pin = 9;
const int D10pin = 10;
const int D11pin = 11;
int Kecepatan;
void setup() {
pinMode (HallApin, INPUT);
pinMode (HallBpin, INPUT);
pinMode (HallCpin, INPUT);
pinMode (potPin, INPUT);
pinMode (D2pin, OUTPUT);
pinMode (D3pin, OUTPUT);
pinMode (D4pin, OUTPUT);
pinMode (D9pin, OUTPUT);//pwm
pinMode (D10pin, OUTPUT);//pwm
pinMode (D11pin, OUTPUT);//pwm
Serial.begin(115200);
}
void loop() {
Kecepatan = analogRead(potPin);
Kecepatan = map(Kecepatan, 0, 1023, 0, 255);
HallAState = digitalRead(HallApin);
HallBState = digitalRead(HallBpin);
HallCState = digitalRead(HallCpin);
if (HallAState == HIGH && HallBState == LOW && HallCState == HIGH) {
digitalWrite(D2pin, LOW);
digitalWrite(D3pin, HIGH);
digitalWrite(D4pin, LOW);
analogWrite(D9pin, Kecepatan);
digitalWrite(D10pin, LOW);
digitalWrite(D11pin, LOW);
}
else if (HallAState == HIGH && HallBState == LOW && HallCState == LOW) {
digitalWrite(D2pin, LOW);
digitalWrite(D3pin, LOW);
digitalWrite(D4pin, HIGH);
analogWrite(D9pin, Kecepatan);
digitalWrite(D10pin, LOW);
digitalWrite(D11pin, LOW);
}
else if (HallAState == HIGH && HallBState == HIGH && HallCState == LOW) {
digitalWrite(D2pin, LOW);
digitalWrite(D3pin, LOW);
digitalWrite(D4pin, HIGH);
digitalWrite(D9pin, LOW);
analogWrite(D10pin, Kecepatan);
digitalWrite(D11pin, LOW);
}
else if (HallAState == LOW && HallBState == HIGH && HallCState == LOW) {
digitalWrite(D2pin, HIGH);
digitalWrite(D3pin, LOW);
digitalWrite(D4pin, LOW);
digitalWrite(D9pin, LOW);
analogWrite(D10pin, Kecepatan);
digitalWrite(D11pin, LOW);
}
else if (HallAState == LOW && HallBState == HIGH && HallCState == HIGH) {
digitalWrite(D2pin, HIGH);
digitalWrite(D3pin, LOW);
digitalWrite(D4pin, LOW);
digitalWrite(D9pin, LOW);
digitalWrite(D10pin, LOW);
analogWrite(D11pin, Kecepatan);
}
else if (HallAState == LOW && HallBState == LOW && HallCState == HIGH) {
digitalWrite(D2pin, LOW);
digitalWrite(D3pin, HIGH);
digitalWrite(D4pin, LOW);
digitalWrite(D9pin, LOW);
digitalWrite(D10pin, LOW);
analogWrite(D11pin, Kecepatan);
}
};
Note: "Kecepatan" variable is "Speed" variable i used in this code.
Thanks!