Pid DC motor-potentiometer Position Control

Hello folks.I’ve been trying to pid control to dc motor-potentiometer assembly by another potentiometer.My code does not work no matter how i try.Here is my code;

const int analogInPin = A0;
const int analogOutPin = A5;

int inputValue = 0;
int outputValue = 0;
int error ;
int totalerror = 0;
int timechange = 100;
int deltaerror;
int lasterror;
int pid;
double kp =1.4;
double ki =1;
double kd =1;
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
delay(1000);
pinMode(analogInPin , INPUT);
pinMode(analogOutPin, INPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);

}

void loop() {
inputValue = analogRead(analogInPin); //girisi oku
outputValue = analogRead(analogOutPin); //cikisi oku
outputValue = map(inputValue, 0, 1023, 0, 1023);
error = inputValue-outputValue; //hatayı belirle
totalerror+= errortimechange; //toplam hatayı bul
deltaerror=(error-lasterror)/timechange; //hata degisimini bul
lasterror = error; //son hatayı kalibre et
pid = kp
error+kitotalerror+kddeltaerror;

if(pid>0 ) {
digitalWrite(8, HIGH);
digitalWrite(7, LOW);
analogWrite(9, 80);
}
else if (pid< 0) {
digitalWrite(8, LOW);
digitalWrite(7, HIGH);
analogWrite(9, 80);}

else {
digitalWrite(8, LOW);
digitalWrite(7, LOW);}

delay(1000);

}

I upload the code after that Im turning potentiometer but nothing happens.Could you help me?

  outputValue = map(inputValue, 0, 1023, 0, 1023);

That's beyond silly. That's approaching stupid.

The whole idea behind PID is to come up with small changes needed to nudge the measured value closer to the setpoint. You are doing no more than determine whether you are high or low, and then slamming the gas to head towards or away. Why?

Your variable names are wrong. There is no analog out pin. There is an actual position pin and a desired position pin. Both are INPUTS.

In any case, you are measuring some values. You don't print them. You are computing some results. You don't print them. Instead, you just stand there wondering why "it doesn't work". Get your head out of the sand, and learn why.

PaulS:

  outputValue = map(inputValue, 0, 1023, 0, 1023);

That's beyond silly. That's approaching stupid.

The whole idea behind PID is to come up with small changes needed to nudge the measured value closer to the setpoint. You are doing no more than determine whether you are high or low, and then slamming the gas to head towards or away. Why?

Your variable names are wrong. There is no analog out pin. There is an actual position pin and a desired position pin. Both are INPUTS.

In any case, you are measuring some values. You don't print them. You are computing some results. You don't print them. Instead, you just stand there wondering why "it doesn't work". Get your head out of the sand, and learn why.

I'm new at arduino.Why are you so rude? I just want to learn.

I just want to learn.

Fine. Do it without my help.

Beginner PID

PaulS:
Fine. Do it without my help.

Are you arduino god or what? Should I worship you or beg you?

Kosmosive:
Are you arduino god or what? Should I worship you or beg you?

No. Just quit copping an attitude when I don't guess that you are a newbie in way over your head.

PID is not a beginner project. Since you are working on PID, I assumed that you were not a rank amateur. I see now that I assumed incorrectly.

But, since you clearly don't want to learn, forget my helping you.