DonnyCraft1 / PIDArduino

A simple PID library for Arduino
MIT License
45 stars 21 forks source link
arduino automation library-automation pid pid-control proportional-integral-derivative

PIDArduino

A simple PID controller library for Arduino

Warning, this library hasn't been properly tested yet. Bugs may occur

Usage

#include <PIDController.h>
PIDController pid;

First include the library.

Then create an instance of the class.


#include <PIDController.h>
PIDController pid;

void setup () {
  Serial.begin(9600);   // Some methods require the Serial.begin() method to be called first
  pid.begin();          // initialize the PID instance
  pid.setpoint(600);    // The "goal" the PID controller tries to "reach"
  pid.tune(1, 1, 1);    // Tune the PID, arguments: kP, kI, kD
  pid.limit(0, 255);    // Limit the PID output between 0 and 255, this is important to get rid of integral windup!
}

void loop () {
  int sensorValue = analogRead(A0);         // Read the value from the sensor
  int output = pid.compute(sensorValue);    // Let the PID compute the value, returns the optimal output
  delay(30);                                // Delay for 30 ms
}

In the setup function, call:

THIS ARTICLE IS NOT FINISHED YET