0% found this document useful (0 votes)
6 views5 pages

Arduino PID Controller Implementation

Uploaded by

Rifki Fajri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Arduino PID Controller Implementation

Uploaded by

Rifki Fajri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Sign inSign up

Instantly share code, notes, and snippets.

careyi3/[Link]

Last active last month

CodeRevisions5Stars43Forks11

Clone this repository at <script


src="[Link]
uot;></script>

Arduino PID Implementation

[Link]

Arduino PID

This is a basic implementation of a PID controller on an Arduino.

To replicate this, wire up the system as shown below:


For more info, check out the YouTube video here.

arduino_pid_system.png

[Link]
[Link]

const int INPUT_PIN = A0;

const int OUTPUT_PIN = DD3;

double dt, last_time;

double integral, previous, output = 0;

double kp, ki, kd;

double setpoint = 75.00;

void setup()

kp = 0.8;

ki = 0.20;

kd = 0.001;

last_time = 0;
[Link](9600);

analogWrite(OUTPUT_PIN, 0);

for(int i = 0; i < 50; i++)

[Link](setpoint);

[Link](",");

[Link](0);

delay(100);

delay(100);

void loop()

double now = millis();

dt = (now - last_time)/1000.00;

last_time = now;

double actual = map(analogRead(INPUT_PIN), 0, 1024, 0, 255);

double error = setpoint - actual;

output = pid(error);

analogWrite(OUTPUT_PIN, output);

// Setpoint VS Actual

[Link](setpoint);

[Link](",");
[Link](actual);

// Error

//[Link](error);

delay(300);

double pid(double error)

double proportional = error;

integral += error * dt;

double derivative = (error - previous) / dt;

previous = error;

double output = (kp * proportional) + (ki * integral) + (kd * derivative);

return output;

You might also like