Pages: [1]   Go Down
Author Topic: PID Example 1  (Read 948 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

can I upload this Ex in Arduino duemilanove? because I can't find the "Analog Out" on the board.
can some one let me know what is the input and the output supposed to be in this example?
can I replace the analog INPUT and OUTPUT to degital ? How?
what is the range of the "Set point"?


/********************************************************
 * PID Simple Example
 * Reading analog input 0 to control analog PWM output 3
 ********************************************************/

#include <PID_Beta6.h>

//Define Variables we'll be connecting to
double Setpoint, Input, Output;

//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,2,5,1);

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(0);
  Setpoint = 100;

  //turn the PID on
  myPID.SetMode(AUTO);
}

void loop()
{
  Input = analogRead(0);
  myPID.Compute();
  analogWrite(3,Output);
}



Thanx in advance,
« Last Edit: February 07, 2011, 08:10:42 pm by Bassam » Logged

New Hampshire
Offline Offline
God Member
*****
Karma: 17
Posts: 781
There are 10 kinds of people, those who know binary, and those who don't.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

analogWrite() works with the PWM pins, so pin 3 refers to digital pin 3, not analog pin 3.  The analog inputs are input only (as outputs they are digital, but without PWM capabilities)

And that sample is from the PIDLibrary in the playground here: http://www.arduino.cc/playground/Code/PIDLibrary
Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thnx for replying and thenx for posting the source, question, what kind of input can I use at ANALOG IN 0 ? just to get this example working?

also, is the output in analogWrite(3,Output), (0<output<255) to control the duty cycle of the PWM?
« Last Edit: February 08, 2011, 05:58:18 pm by Bassam » Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1225
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

+5V ----- Potentiometer----GND
                |
                \(the middle leg)
                   ------------Analog 0

That should give you an input voltage on the Analog 0 between 0 and 5V. The analogRead returns a value between 0 and 1023. Use a potentiometer with at least 10K, 100K would be fine.

Yes, The PWM control varies between 0 (0% on) and 255 (100% on)

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

see what I"m trying to do is to control the PWM via distance. i'm using the following
http://www.arduino.cc/en/Tutorial/Ping

to read distance and i'm thinking of feeding the distance that the sensor is reading as a PID Input.
i'm unable to figure this out, can i do the following:

input = cm;

?
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 33
Posts: 1225
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes.
Logged

Pages: [1]   Go Up
Jump to: