-2

Error

Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"

AnalogInOutSerial:8:56: error: no matching function for call to 'PID::PID(int*, int*, double*, double&, double&, double&, int)'
 PID pid(&Rawval, &Rawval, &setpoint, kp, ki, kd, DIRECT);
                                                        ^
In file included from C:\Users\USER\AppData\Local\Temp\arduino_modified_sketch_407168\AnalogInOutSerial.ino:1:0:
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:24:5: note: candidate: PID::PID(double*, double*, double*, double, double, double, int)
     PID(double*, double*, double*,        // * constructor.  links the PID to the Input, Output, and
     ^~~
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:24:5: note:   no known conversion for argument 1 from 'int*' to 'double*'
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:20:5: note: candidate: PID::PID(double*, double*, double*, double, double, double, int, int)
     PID(double*, double*, double*,        // * constructor.  links the PID to the Input, Output, and
     ^~~
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:20:5: note:   candidate expects 8 arguments, 7 provided
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note: candidate: constexpr PID::PID(const PID&)
 class PID
       ^~~
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note:   candidate expects 1 argument, 7 provided
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note: candidate: constexpr PID::PID(PID&&)
C:\Users\USER\Documents\Arduino\libraries\Arduino-PID-Library-master/PID_v1.h:5:7: note:   candidate expects 1 argument, 7 provided
exit status 1
no matching function for call to 'PID::PID(int*, int*, double*, double&, double&, double&, int)'


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Actual Code

#include <PID_v1.h>

int analogPin = A3; 
int Rawval ;  // variable to store the value read
double setpoint = 169; // target value for the system is set to 169
double kp = 1, ki = 0.1, kd = 0.01; // PID constants
int RELAY_pin = 10;    // Relay is connected to pin D10
PID pid(&Rawval, &Rawval, &setpoint, kp, ki, kd, DIRECT);

void setup()
{
  Serial.begin(9600);           //  setup serial
  pinMode(RELAY_pin, OUTPUT);
  pid.SetMode(AUTOMATIC);
}

void loop()
{
  Rawval = analogRead(analogPin);
  Serial.print("Rawvalue from Analog input  =");
  Serial.println(Rawval);
  pid.Compute();
  digitalWrite(RELAY_pin, Rawval < setpoint ? HIGH : LOW); 
}

2 Answers 2

2

The error message is quite clear about the problem (extracted and formatted for clarity):

no matching function for call to
PID::PID(int*, int*, double*, double&, double&, double&, int)
[...]
candidate:
PID::PID(double*, double*, double*, double, double, double, int)
[...]
no known conversion for argument 1 from 'int*' to 'double*'
[other candidates left out due to non-matching number of arguments]

You need to provide pointers to double as the first two arguments, and the candidate will match.


EDIT:

I hesitated a while to provide your this, because you learn much better by doing it yourself. Anyway, here it is.

Your original variable declaration is:

int Rawval ;  // variable to store the value read

Replace the data type int by double, as the called constructor expects:

double Rawval ;  // variable to store the value read

Now there is this line, assigning an int to a double:

Rawval = analogRead(analogPin);

And you might ask yourself, is this OK? Well, try it. You will find that the compiler implicitly converts the value. If you want to make it explicitly, change the line to:

Rawval = static_cast<double>(analogRead(analogPin));

A final point, as datenheim states: Read and learn about the PID. It is for sure an error to use the same variable for input and output.

7
  • Can you kindly modify the portion & provide it here accordingly so that I can execute without any further error.Thanks in advance
    – Rocky
    Commented Feb 1, 2023 at 11:05
  • My code is fine?? I will integrate yours as per modification..Till it will give error? The code is to integrate PID in to arduino to an analogous sensor based on threshold value like 169 for raw value. If the value is less than the relay will be operational. Target rawvalue =169 Target scaleval =5 Setpoint also What would be the ka, kp, ki value for fully functional as described. Please guide. Thanks!
    – Rocky
    Commented Feb 1, 2023 at 11:50
  • 2
    @Rocky, That is not how this site works. Your code is yours. You have been given enough information to fix the error in your code and now it's up to you to integrate the solution and fix your code so it does what you want.
    – StarCat
    Commented Feb 1, 2023 at 12:47
  • 1
    @Rocky I have no idea. This is a completely different question, and certainly not one about programming. Since your course seems to involve control engineering, you should repeat the material you have. Commented Feb 1, 2023 at 21:21
  • 3
    @Rocky, that makes no sense and this site is not a free homework service.
    – StarCat
    Commented Feb 2, 2023 at 6:34
1

The first two parameters need to be of type double.

PID pid(&Rawval, &Rawval, &setpoint, kp, ki, kd, DIRECT);
        ^^^^^^^  ^^^^^^^

It also makes probably no sense to have input and output both wired to &Rawval.

Take a look on this example.

2
  • Can you kindly modify the portion & provide it here accordingly so that I can execute without any further error.Thanks in advance
    – Rocky
    Commented Feb 1, 2023 at 11:06
  • 2
    No, sorry, learning is by doing. Try it, you will see :-)
    – datenheim
    Commented Feb 1, 2023 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.