This project demonstrates a DC motor speed and direction control system implemented on an ESP32 using MicroPython. It showcases the application of Object-Oriented Programming (OOP), Single Responsibility Principle (SRP), and the Command Design Pattern to build a modular, reusable, and maintainable architecture.
- Motor Control: Speed and direction control using PWM signals.
- Potentiometer Input: Real-time duty cycle adjustment (0–1023).
- RPM Feedback: Pulse counting from an IR sensor with real-time RPM calculation.
- Command Pattern: Flexible command execution for motor operations (Clockwise, Counter-Clockwise, Stop).
- SRP Implementation: Each class has a single responsibility for clarity and maintainability.
- LED Indicator: Displays system run/stop state.
- ESP32 Development Board
- DC Motor
- L298N Motor Driver
- IR Sensor / Encoder (for pulse counting)
- Encoder Disk (perforated disk with multiple holes)
- Potentiometer (speed control input)
- LED (status indication)
- 12V Battery (power supply for motor)
Motor
: Handles motor speed, direction, and stop functionality.LEDstate
: Controls LED indicator.Command
Classes: Encapsulate motor operations.MotorController
&LedController
: Execute commands.PulseCounter
: Counts pulses from IR sensor.SpeedCalculator
: Converts pulses into RPM.Potentiometer
: Reads analog input and maps it to PWM duty cycle.ShowSpeed
: Displays current RPM.
- The potentiometer sets the PWM duty cycle to adjust motor speed.
- The IR sensor reads the rotation of the encoder disk (with multiple holes).
- The
PulseCounter
andSpeedCalculator
compute real-time RPM. - The
MotorController
executes commands (Clockwise, Counter-Clockwise, Stop). - The LED indicates motor status (ON/OFF).
- The 12V battery powers the motor through the L298N driver.
Stopping
Running in clockwise direction...
T:0.4 D:512
Motor Speed: 120 RPM
...
Stopping...
Running in counter clockwise direction...
T:0.6 D:768
Motor Speed: 135 RPM