In fact, I just want to understand the code clearly. sorry for making confusion.
Because at the top of the example says:
- PID Basic Example
- Reading analog input 0 to control analog PWM output 3
At first glance, I didn't really know about the process of the code and its application
After I've looked at the code, I thought (If I am wrong, please confirm that to me) that the analog input was a feedback part which fed the PWM output at pin 3 back to the microcontroller. I've done this test because I want to know how the code works and the only option to observe the duty cycle without an oscilloscope is led brightness.
PaulS:
You should also be printing the Input, Setpoint, and Output values so YOU can see how the output changes as the input changes, as you manipulate the tuning parameters.
Of course, I'll learn how to record the response of this thing and show you later. What I've done is just changing the PID term by by term and see how it affects. I just want to understand how to use the code properly (how to give a value to the setpoint parameter properly) not to tune this led lamp into a critical damp which is the goal of PID.
wildbill:
I assume that this is a learning exercise and that there's more to come later, but right now this:
I want to control the PWM duty cycle at the pin3
as others have said, doesn't need the PID at all. Replacing your loop function with this satisfies your requirement as written:
void loop()
{
Input = analogRead(1);
analogWrite(3,Input/4);
}
Is there some reason that you don't want the PWM to react so quickly?
Yes because I want to see the effect of the PID gain (In fact, I've known the theory before but I want to apply the control theory to coding in arduino properly)
I might misunderstand about the code. the analog input might be just reading the potentiometer value instead of reading the actual PWM which is supplied to the LED.