0% found this document useful (0 votes)
73 views1 page

PID Control For LED To Adjust The Brightness

This C++ code uses a PID controller to read an analog input sensor on pin 0, compare it to a setpoint of 500, and control an analog PWM output on pin 3 to minimize the error between the input and setpoint using proportional, integral and derivative tuning parameters. The PID controller is initialized with the input, output and setpoint variables and tuning parameters, and runs in a loop computing the output and writing it to pin 3.

Uploaded by

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

PID Control For LED To Adjust The Brightness

This C++ code uses a PID controller to read an analog input sensor on pin 0, compare it to a setpoint of 500, and control an analog PWM output on pin 3 to minimize the error between the input and setpoint using proportional, integral and derivative tuning parameters. The PID controller is initialized with the input, output and setpoint variables and tuning parameters, and runs in a loop computing the output and writing it to pin 3.

Uploaded by

jaweria arshad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/********************************************************

* PID Basic Example


* Reading analog input 0 to control analog PWM output 3
********************************************************/

#include <PID_v1.h>
#define PIN_INPUT 0
#define PIN_OUTPUT 3
//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters

double Kp=1, Ki=2, Kd=0; // 2 5 1

PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);


void setup()
{
Serial.begin(9600);
//initialize the variables we're linked to
Input = analogRead(PIN_INPUT);
Setpoint = 500;
//turn the PID on
myPID.SetMode(AUTOMATIC);
}
void loop()
{
Input = analogRead(PIN_INPUT);
Serial.println(Input);
myPID.Compute();
analogWrite(PIN_OUTPUT, Output);
Serial.println(Output);
}

You might also like