Arduino PID leaving me with dead 0's

Hi,

I'm trying to construct something useful with PID tuning, that's when I found the PID library.

The problem I'm encountering is that it's leaving me with an output value of 0.00. "IE not doing anything"

Does anybody want to shed some light on the situation?

/********************************************************
 * PID Basic Example
 * Reading analog input A0 to control analog PWM output 5
 ********************************************************/

#include <PID_v1.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, DIRECT);

int sens;

void setup()
{
  //initialize the variables we're linked to
  Input = analogRead(A0);
  sens = analogRead(A4);

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

void loop()
{
  sens = analogRead(A4);
  Setpoint = (sens\4);
  Input = analogRead(A0);
  myPID.Compute();
  analogWrite(5,Output);
}

  Setpoint = (sens\4); what's that doing?

J-M-L:
  Setpoint = (sens\4); what's that doing?

Generating a compiler error:

sketch_feb09a:29: error: stray '' in program
sketch_feb09a.ino: In function 'void loop()':
sketch_feb09a:29: error: expected `)' before numeric constant

You may be interested in my PID explorations, and particularly in my latest contribution in Reply #175 :slight_smile:

...R

Does anybody want to shed some light on the situation?

You might take a moment to explain what the Arduino is connected to, and what your code is supposed to do.

J-M-L:

  Setpoint = (sens\4);

what's that doing?

Dividing by four"4", to represent a output format when done. Instead of 0-1023, we need 0-255 for the output.

PaulS:
Generating a compiler error:

How did you bring this out to light?

jremington:
You might take a moment to explain what the Arduino is connected to, and what your code is supposed to do.

I'm going to regulate a butterfly valve from a pot-meter(A4), and a sensor is attached to the valve itself.(A0)

Paul tends to be terse. \ is an escape sequence delimiter, / is divide.

It's also clear that the code you posted wasn't the code that gave you problems, because code that cannot compile cannot run.

Dividing by four"4", to represent a output format when done. Instead of 0-1023, we need 0-255 for the output.

That would be an input value, not an output, and for PID, it is quite a bad idea to reduce the resolution of the input measurements, even if you coded the divide correctly.

For PID you would like the input measurements to have at least ten times the resolution of the output values.