This project demonstrates how to control DC motors using L289N and L293D motor driver ICs with the STM32F103C6 microcontroller.
- The setup integrates advanced control techniques including:
- Timers & PWM – for speed regulation
- ADC – to read a potentiometer for analog speed control
- UART – for real-time monitoring and debugging
- Button inputs – for motor direction and mode selection
Motor Driver ICs
- L289N: Dual H-bridge driver, controls 2 DC motors or 1 stepper motor, up to 1A/channel, requires external control logic, works at 4.5V–36V.
- L293D: Dual H-bridge driver, controls 2 DC motors or 1 stepper motor, up to 600mA/channel, has built-in control logic and internal voltage regulator, operates at 4.5V–36V.
Circuit Overview
- L298N Control – Dual H-Bridge motor driver interface
- L293D Control – Bidirectional motor driver interface
- ADC – Read analog sensor values
- TIM2 (PWM) – Generate pulse width modulation signals
- UART1 – Serial communication for data exchange
- Target MCU: STM32F103C6Tx
- Clock Configuration: System clock = 8 MHz
- GPIO:
-
PA6 → Mode Selector (L289N/L293D)
-
PB6–PB11 → Control buttons
-
PB14, PB15, PA3 → L289N control
-
PB12, PB13, PA2 → L293D control
- TIM2 PWM Setup:
-
Enable TIM2
-
Channels: Enable PWM on CH3 and CH4
-
Prescaler = 800
-
Period = 1000
-
Pulse = 500 (adjustable for speed)
- ADC1:
-
Enable IN9 (Potentiometer input)
-
Mode: Continuous Conversion
- USART1:
-
Baud Rate = 9600
-
Mode = Asynchronous
-
Word Length = 8 Bits
-
Stop Bits = 1
-
Parity = None
- Generate code and open in STM32CubeIDE.
- Initialize all peripherals: GPIO, ADC, TIM2 (PWM), UART.
- Start ADC conversion and PWM outputs.
- Implement logic:
-
ADC:
Read potentiometer → map value to PWM duty cycle.
-
PWM:
Adjust motor speed (0–100%).
-
Buttons:
Change motor direction (CW/CCW), enable/disable motors, select fixed speeds (25%, 50%, 75%).
-
UART:
Send live feedback of ADC values and motor status.
- Create a new project.
- Add components:
-
STM32F103C6 MCU
-
L289N driver
-
L293D driver
-
DC Motors
-
Potentiometer (ADC input)
-
Control Buttons (SPDT switches)
-
Power supply (VCC, GND)
-
Virtual Terminal (UART debug)
-
Oscilloscope (optional for PWM analysis)
- Wire connections according to CubeMX configuration.
- Load the compiled .hex firmware into the STM32 MCU.
- Run the simulation and observe:
-
Motor speed changes with potentiometer.
-
Direction changes with button press.
-
UART logs motor status in Virtual Terminal.
If you have any questions or suggestions don't hesitate to leave a comment below
Comments