Skip to content

Abdelkarim13/Motor-Speed-control-Based-OOP-Design-Pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Motor Speed Control Project

Overview

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.

Features

  • 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.

Components Used

  • 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)

Code Structure

  • 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.

How It Works

  1. The potentiometer sets the PWM duty cycle to adjust motor speed.
  2. The IR sensor reads the rotation of the encoder disk (with multiple holes).
  3. The PulseCounter and SpeedCalculator compute real-time RPM.
  4. The MotorController executes commands (Clockwise, Counter-Clockwise, Stop).
  5. The LED indicates motor status (ON/OFF).
  6. The 12V battery powers the motor through the L298N driver.

Example Output

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages