Motor Controller design with IR2104, IRF540N controlled by Arduino

 I have earlier shown how to design motor controller with IR2110 MOSFET driver IC. This motor controller circuit is a diy alternative to motor controller shields like the L298N motor shield and L293D motor shield which is popularly used for RC cars and robotics. Here I have designed a motor controller circuit designed with IR2104 mosfet driver ICs. 

The difference between IR2104 or IR2110 is the following. The IR2104 and IR2110 are both high- and low-side MOSFET half bridge driver ICs designed to drive N-channel MOSFETs in half-bridge or full-bridge configurations, but they differ significantly in features and applications. The IR2104 is a simpler and more compact driver that is typically used for basic half-bridge circuits and operates with a single input control logic for both high and low sides, with a built-in dead-time to prevent shoot-through. It is easier to use in basic motor control applications but offers less flexibility. In contrast, the IR2110 is a more advanced driver that provides independent inputs for the high-side and low-side MOSFETs, allowing for more flexible control schemes such as complementary PWM. The IR2110 also supports higher current drive capability (up to 2A), has better isolation, and is more suitable for high-performance applications like full-bridge inverters, class D amplifiers, or advanced motor drives. In summary, use the IR2104 for simpler, compact designs, and the IR2110 when you need full control, higher power handling, or more advanced timing coordination.

Circuit Diagram of IR2104 Motor Controller

Below is circuit diagram of motor controller designed with IR2104 and IRF540N driven by Arduino.

motor controller designed with IR2104 and IRF540N

Circuit Operation

The motor controller circuit uses two IR2104 half-bridge driver ICs to control a full H-bridge circuit composed of four IRF540N N-channel MOSFETs, enabling bidirectional control of a 12V DC motor. Each IR2104 drives one high-side and one low-side MOSFET pair, with gate resistors (27Ω) and fast 1N4148 diodes to ensure proper switching performance and reduce electromagnetic interference. The 1N5819 Schottky diodes act as flyback diodes, protecting the MOSFETs from voltage spikes generated by the motor’s inductive load during switching. An Arduino reads two direction control buttons connected to digital pins 2 and 3, and a potentiometer for speed control connected to analog pin A0; it outputs PWM signals on pins 9 and 10 to the IR2104 inputs to modulate motor speed and selects the rotation direction by activating one half-bridge at a time. The shutdown (SD) pins of both IR2104s are tied together and controlled via Arduino pin 5 to enable or disable the driver ICs. This configuration provides efficient, safe, and flexible motor control suitable for various embedded applications.

Arduino Program

Arduino code for controlling the motor is as follows.
// Pin Definitions
const int dir1Pin = 2;     // Direction control button 1 (e.g., Forward)
const int dir2Pin = 3;     // Direction control button 2 (e.g., Reverse)
const int enPin = 5;       // IR2104 SD pin (active HIGH to enable)
const int pwmPinA = 9;     // PWM signal for IR2104 #1 (High-side or Low-side)
const int pwmPinB = 10;    // PWM signal for IR2104 #2 (High-side or Low-side)
const int potPin = A0;     // Potentiometer for speed control

void setup() {
  // Set direction control pins as input with pull-up
  pinMode(dir1Pin, INPUT_PULLUP); 
  pinMode(dir2Pin, INPUT_PULLUP);

  // Output pins to control IR2104 and motor
  pinMode(enPin, OUTPUT);
  pinMode(pwmPinA, OUTPUT);
  pinMode(pwmPinB, OUTPUT);

  // Enable both IR2104s (shared SD pin)
  digitalWrite(enPin, HIGH); 
}

void loop() {
  // Read direction buttons
  int dir1 = digitalRead(dir1Pin);
  int dir2 = digitalRead(dir2Pin);

  // Read potentiometer value (0–1023)
  int potValue = analogRead(potPin);

  // Map pot value to PWM range (0–255)
  int pwmValue = map(potValue, 0, 1023, 0, 255);

  // Motor direction logic
  if (dir1 == LOW && dir2 == HIGH) {
    // Forward: A = PWM, B = 0
    analogWrite(pwmPinA, pwmValue);
    analogWrite(pwmPinB, 0);
  } 
  else if (dir1 == HIGH && dir2 == LOW) {
    // Reverse: A = 0, B = PWM
    analogWrite(pwmPinA, 0);
    analogWrite(pwmPinB, pwmValue);
  } 
  else {
    // Stop: both inputs LOW or both HIGH
    analogWrite(pwmPinA, 0);
    analogWrite(pwmPinB, 0);
  }
}

The Arduino code reads the states of two direction control buttons connected to pins 2 and 3, and a potentiometer on analog pin A0 to determine the desired motor direction and speed. It maps the potentiometer input to a PWM value between 0 and 255 to control motor speed. Based on the button inputs, the code activates one half-bridge at a time by outputting PWM signals on pins 9 or 10, which drive the IR2104 driver inputs connected to the MOSFET gates. If the forward button is pressed, the code sends PWM to the first half-bridge and turns off the second; if the reverse button is pressed, it reverses this logic. When neither or both buttons are pressed, the motor is stopped by turning off both PWM outputs. The enable pin connected to the IR2104 shutdown pins is set HIGH to activate the drivers, allowing smooth, direction-controlled speed modulation of the motor.

Video demonstration

The following video demonstrates how the Motor Controller designed with IR2104 and IRF540N driven by Arduino works.



Post a Comment

Previous Post Next Post