Sensored brushless DC motor control with Arduino

There are two types of BLDC motors: sensored and sensorless. Sensored BLDC motor uses hall effect sensors to detect rotor position where as the sensorless BLDC motor uses another technique which is BEMF (back electromotive force). This topic shows how to drive a sensored BLDC motor using an Arduino UNO board. The BLDC motor used in this project is just a PC CD-ROM motor (spindle motor).

The BLDC motor (sensored or sensorless) is a 3 phase DC motor which means it has 3 winding on the stator core. Two coils are energized at a time to create a rotating electric field. This method is fairly easy to implement, but to prevent the permanent magnet rotor from getting locked with the stator, the excitation on the stator must be sequenced in a specific manner while knowing the exact position of the rotor magnets.

3 Phase BLDC motor coils

To drive this motor we need a 3-phase bridge, the basic elements of it are the 6 MOSFETs. General circuit schematic diagram of the 3-phase bridge is shown below:

3 Phase bridge for BLDC motor control

The sensored BLDC motor has 3 hall effect sensors (A, B and C) to sense rotor position, these sensors are placed as shown in the following picture. The motor which I used in this project has pinout as shown below (other motors may have a different pinout).
In this motor each hall effect sensor has 4 pins: VCC (H+), GND (H-) and two outputs (some sensors come with 3 pins: VCC, GND and output).

CD-ROM BLDC motor pin configuration

Since I have 4-pin hall effect sensors, I added an analog comparator (I used LM339N quad comparator IC) to each one so each sensor outputs (2 outputs: + and -) are connected to the inputs (2 inputs: non-inverting and inverting) of the comparator as shown in the circuit schematic below, finally I got 3 outputs from the 3 hall effect sensors.

Each sensor outputs a digital high for 180 electrical degrees and outputs a digital low for the other 180 electrical degrees. The following figure shows the relationship between the sensors outputs and the required motor drive voltages for phases A, B and C.

3 Phase BLDC motor phases

According to the hall effect sensors, the 3-phase bridge is controlled as shown in the following table:

brushless dc motor driving sequence

Components Required:

  • Arduino board
  • Sensored brushless DC motor
  • 6 x 06N03LA N-type mosfet (or equivalent)  – datasheet
  • 3 x IR2104S gate driver IC  – datasheet
  • LM339N (or LM339) quad comparator IC  – datasheet
  • 10k ohm (or less) potentiometer
  • 3 x 10k ohm resistor
  • 7 x 100 ohm resistor
  • 3 x IN4148 diode
  • 3 x 10uF capacitor
  • 3 x 2.2uF capacitor
  • 12V source
  • Breadboard
  • Jumper wires

Sensored brushless DC motor control with Arduino circuit:
The overall circuit diagram is shown below.

Arduino BLDC motor control circuit

(All grounded terminals are connected together).

In the circuit there are three IR2104S gate driver IC, each one is used to drive one high side mosfet and one low side mosfet, the switching between the high side and the low side is done according to the control lines which are: IN and SD. The figure below shows input and output timing diagram:

ir2104s timing

The 10k potentiometer is used to control the brushless DC motor speed, it is controlled using PWM technique (pwming high sides only). Any time there is one active high side mosfet and one active low side mosfet, that means always there is one active PWM pin (Arduino pin 2, 4 or 6).

The table below summarizes the active Arduino pins according to the hall effect senors states (pins: 8, 9, and 10):

arduino bldc motor driving sequence table

Sensored brushless DC motor control with Arduino code:
In this project I implemented a simple software PWM code because I had needed an active PWM signal on pin 2, 4 or 6 (only one is active at a time), for that I used Timer2 module and I configured it with a prescaler of 1/8 which means the PWM signal frequency is about 7.8KHz ( equal to: 16MHz/(8 * 256) ) and 8-bit resolution.

The ADC module is configured to read from channel 0 only.

Arduino interrupt on change is activated for pins 8, 9 and 10 (hall effect sensors inputs) for better commutation.

PORTB are Arduino uno pins: 8 … 13.
PORTD are Arduino uno pins: 0 … 7.

The video below shows a hardware circuit of the project:

Related project:
CD-ROM Sensored BLDC motor control with Arduino


  1. This article is great. I like it very much
    But I have a liite question. You say Arduino pins 2, 4 and 6 as PWM capable but I find only pins 3,5,6,9,10,11 are PWM cable.
    This is clear from the picture of the UNO in your schematic.
    Could you kindly explain me this discrepancy.

    1. Actually I am using bldc controlling in order to obtain regenerative braking ; would this program be enough to get regenerative braking voltage

  2. Hi,

    I am trying to make a 5 phase BLDC motor controller and your 3 phase example is by far the best I’ve seen! Is it possible for me to implement code like this to make a 5 phase controller?

    I also want to add that I am quite the noob with arduino and although I understand the read/write parts of the code, I do not understand how to enable and assign the interrupt pins using this port manipulation method and the software PWM section.

    I looked around and could not find a good enough tutorial using data port manipulation.

    Will you please explain this to me?


  3. Thank you for your contributions, this very illustrative and schematic project, you learn from your projects, they serve as guides and inspirations.
    a question I would like to know how to adapt this project to a hall sensor of three terminals, what change should be made to use the sensor hall three terminals, thank you for your ingenuity and creativity

    1. @ william Its 120 phase difference between hall sensors. In this post Note that Hall states retain for 180 deg, But the difference between each hall is 120

  4. Hi. Thanks for sharing this project. It was a good inspiration.
    I noticed that you have the SOIC IR2102 mounted into some sort of socket … What are those sockets and where can I buy them ?

    1. They are IR2104S, soldered in SOP to DIP converter PCBs. The sockets are just pin headers, you can get them from online shopping websites (Aliexpress, ebay …).

  5. Thank you for this beautiful and efficient jewel of a code.
    it was very inspiring for me.


  6. Thank you so much for your excellent tutorial. Do you know how can we reverse the direction of the motor ? I appreciate your help.

  7. I am building this circuit with the following modifications. I am using 9v to power the circuit, but using higher voltages where power is gated by the MOSFETs for higher power motors. The two input voltages will share a common ground. Do you foresee any difficulties with this approach?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.