Labs / Bipes + MicroPython / 8 Actuators (Outputs / Actuators)

8.9 Want to Get Your Car Moving? Let the Drive Motor Spin! —— Optocoupler-Isolated MOSFET Single-Motor Driver Module

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Young makers, today let’s unlock a "little steward that can safely drive motors" ⚙️!

Previously, when we used ordinary modules to drive motors, high currents might damage the development board. This optocoupler-isolated MOSFET single-motor drive module acts like a "security firewall" installed on the development board: it can not only drive the motor to run, but also protect the development board from being burned out by high currents — it’s extremely reliable ✨!

1. Module Introduction

Want to get your motor running but worried that a large current will burn out your development board? This module is your "safety solution"!

It is a isolated motor drive module whose core is the combination of "optocoupler + MOS tube":

Compared with ordinary motor drive modules, it has the following features:

In graphical programming, these blocks are commonly used:

In practical projects, it is often used for the following purposes:

Popular Science: What is Optocoupler Isolation?

An optocoupler acts like a "bridge that transmits signals via light": the electrical signal from the development board is converted into light, which passes through an insulating layer, and then converted back into an electrical signal to be sent to the MOSFET. In this way, the circuits of the development board and the motor are completely isolated from each other, so the high current of the motor will not interfere with the development board, thoroughly eliminating the risk of burning it out.

2. Wiring Instructions

To get a motor running safely, the first step remains the same: connect the wires correctly!

8.9 Want to Get Your Car Moving? Let the Drive Motor Spin! —— Optocoupler-Isolated MOSFET Single-Motor Driver Module

We connect the optocoupler-isolated MOSFET single-motor drive module to the digital interface DIO0 of the development board, and the corresponding relationship is as follows:

Development Board Pins

Module Pins

Description

Pin 6

DOUT

MCU outputs PWM waveforms

Pin 7

NC

-

-

VIN Terminal +

Power Supply +

-

VIN terminal -

Power Supply -

-

VOUT terminal

Motor

📌 Note

3. Example: The motor stops after rotating for 5 seconds

Experimental Objective: Make the motor run at a stable speed for 5 seconds and then stop automatically, so as to intuitively experience the safety control effect of "optocoupler isolation + MOS drive".

Little Thoughts in Daily Life: When you press the forward button on a remote-controlled car, the motor spins to move the car forward, and it stops once you release the button — this follows a similar control logic. Now let's build our own "safe and controllable small motor"!

The graphical program is as follows:

8.9 Want to Get Your Car Moving? Let the Drive Motor Spin! —— Optocoupler-Isolated MOSFET Single-Motor Driver Module

Building Block Assembly Steps:

  1. Starting Motor (PWM Output)
    • Drag in PWM #6 block;
    • Selected Pin: Pin 9 / GPIO6 (corresponding to DIO0 interface);
    • Set the Frequency to 1000 (the frequency for stably driving the motor);
    • Set Duty to 50000 (medium duty cycle, corresponding to medium rotational speed);
  2. Set rotation duration
    • Drag in the delay block and set it to 5 seconds → make the motor rotate continuously for 5 seconds;
  3. Stop the motor (turn off PWM)
    • Drag in another PWM #6 block;
    • Pin retention Pin 9 / GPIO6;
    • Frequency remains 1000;
    • Set Duty to 0 → Turn off the output, and the motor stops rotating.

Experimental Effect:

Graphical blocks will be automatically converted into MicroPython code, and the running results will be displayed:

8.9 Want to Get Your Car Moving? Let the Drive Motor Spin! —— Optocoupler-Isolated MOSFET Single-Motor Driver Module

Directly importable building blocks:

Motor.xml 2 KB

Tips

  1. If the motor does not rotate:
    • Check whether the pins are selected correctly (Pin 9 / GPIO6) and whether the wiring is secure;
    • Verify that the 5V power supply is normal and check whether the motor is stuck by foreign objects;
    • Try increasing the duty cycle (e. g., 60000) to raise the motor speed.
  2. What should I do if the motor speed is unstable?
    • Ensure that Frequency is set to around 1000, which is a stable frequency for driving DC motors;
    • Check whether the motor is worn out or the supply voltage is stable.
  3. Advanced Gameplay:
    • Equipped with a sliding rheostat module, the PWM duty cycle is controlled via the rheostat value to realize "manual motor speed regulation";
    • Equipped with a line-tracking module, the car will automatically stop the motor when it touches a black line, making it a "line-tracking car".

✨ Interactive Quick Question

  1. Think about it: Why can optocoupler isolation protect the development board? What are the risks if you directly use the pins of the development board to drive the motor without an optocoupler?
  2. Try this: Change Duty from 50000 to 65535 (the maximum duty cycle) and see whether the motor speed increases or decreases. Then change it to 30000 to experience different speed effects.

Summary

  1. The optocoupler-isolated MOSFET single-motor drive module is a safety-type motor drive module that achieves safety control through optocoupler isolation combined with MOSFET driving;
  2. It can completely isolate the development board from the motor circuit, preventing the development board from being damaged by high current, and meanwhile drive the motor to rotate stably.
  3. The basic usage is simple control following the sequence of "PWM start → delay → PWM stop", while the advanced usages include speed regulation and intelligent control;
  4. It is a core module for power projects such as small cars and robots, featuring high safety and reliability.