Control PID Motor - Arduino

Control PID Motor - Arduino

How to Easily Create a PID Controller for a Motor with Arduino

Circuit Assembly

  • The video introduces the project of creating a PID controller for a motor using Arduino, emphasizing the simplicity of the process.
  • Components required include an Arduino, two push buttons (with 10k resistors), and an optical sensor to measure motor speed. Connections are specified for pins 4 and 5 on the Arduino.
  • A capacitor is needed to filter noise from the sensor, along with an H-Bridge module connected to control motor outputs. Power supply requirements are also mentioned.

Control System Overview

  • A block diagram illustrates the control system setup: input set point, control block (Arduino), plant (motor), and feedback from the optical encoder.
  • The error is calculated by subtracting the measured value from the set point, which is crucial for PID control adjustments.

PID Control Formula

  • The PID control formula in differential equations is presented: K_P cdot e + K_I cdot int e + K_D cdot de/dt .
  • It explains that this equation must be transformed into discrete time domain suitable for implementation in Arduino.

Discretization Process

  • Steps include applying zero-order hold and Z-transform to obtain a discrete-time PID equation incorporating constants K_P, K_I, K_D .

Implementation in Code

  • The final form of the controller equation is derived for use within code: it relates current controller value to previous values and errors over sampling time.

Variable Initialization

  • In Arduino code setup, variables such as period, previousTime, and RPM calculations are initialized alongside constants for PID tuning.

Main Loop Functionality

  • The main loop includes conditions to calculate RPM based on pulse frequency and apply exponential filtering to reduce sensor noise.

User Interaction

  • Button presses increment or decrement set points by 10 units. An interrupt function counts pulses each time there’s a positive edge detected.

PID Control Implementation

PID Calculation and Output Limits

  • The error is calculated as the set point minus the filtered RPMs. The PID value is computed using a formula from a PDF reference.
  • Recursively, previous control values (cb ant) and errors (error ant) are updated to maintain continuity in calculations.
  • The PID output is constrained between a maximum of 200 and a minimum of 0 to ensure safe operation within the Arduino's PWM output range.

Testing on Arduino

  • After uploading the code to the Arduino, real-time graphs can be visualized through network nodes, showing system performance.
  • In the graphical representation, white indicates the set point, orange represents the process variable, and blue denotes the control variable. This color coding helps in monitoring system behavior effectively.

System Response to Set Point Changes

  • Upon increasing the set point using a connected button, it is observed that the process variable quickly reaches the desired set point.
Video description

Puedes descargar los archivos en este link: https://drive.google.com/drive/folders/17NF_mU48rWErRhQWqRf0p9Z-gLhPwwPk?usp=sharing