Arduino Uno Code as BLDC Motor Controller with MOSFET IRF540N and IC IR2101

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!

how did you wire the HallA HallB and HallC thingy ?

directly from my BLDC Motor to Arduino UNO's output pin number 7,6 and 5

even if you connect them proper it would not work.

i did power it on and my BLDC Motor started to rotating automatically, so does that mean my Arduino UNO has nothing to do with it?

Is the pot set to 0?

These pin names are meaningless. What are the six pins connected to?

yes because it's a hand throttle it goes back to 0 when i'm not use it.

those pins are connected from Arduino UNO as High output 2,3,4 and Low output 9,10,11 to IC IR2101.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.