How to fix no matching function for call to 'Button::Button(const int8_t arduino

here is the code I used for the Trash separator project and when I compile it the error message is
{ no matching function for call to 'Button::Button(const uint8_t&)' }

and the error is at line (10)

THE CODE
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

// Include Libraries
#include "Arduino.h"
#include "Button.h"
// Pin Definitions
#define REFLECTIVEIR_PIN_COLL A3
#define REFLECTIVEIR_PIN_COLL_M A5}
// object initialization
Button ReflectiveIR(REFLECTIVEIR_PIN_COLL);
Button ReflectiveIR_M(REFLECTIVEIR_PIN_COLL_M);
// define vars for testing menu
const int timeout = 10000; //define timeout of 10 sec
char menuOption = 0;
long time0;

#include <Servo.h>
#define redpin 5
#define bluepin 6
#define greenpin 7
#define redpin_M 8
#define bluepin_M 9
#define greenpin_M 10
int plasticsensor=A0;
int anothersensor=A2;
int metalsensor=A4;
int metalsensor_M=A6;

Servo myservo; // create servo object to control a servo
Servo myservo_M; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 165; // variable to store the servo position
int pos_M = 158; // variable to store the servo position

void setup() {
myservo.attach(11); // attaches the servo on pin 9 to the servo object
myservo_M.attach(12); // attaches the servo on pin 9 to the servo object
pinMode(redpin,OUTPUT);
pinMode(bluepin,OUTPUT);
pinMode(greenpin,OUTPUT);
//metal sensor
pinMode(redpin_M,OUTPUT);
pinMode(bluepin_M,OUTPUT);
pinMode(greenpin_M,OUTPUT);

pinMode(plasticsensor,INPUT_PULLUP);
pinMode(metalsensor,INPUT_PULLUP);
pinMode(anothersensor,INPUT_PULLUP);
pinMode(metalsensor_M,INPUT_PULLUP);
Serial.begin(9600);
analogWrite(redpin,255);
analogWrite(bluepin,0255);
analogWrite(greenpin,255);
analogWrite(redpin_M,255);
analogWrite(bluepin_M,0255);
analogWrite(greenpin_M,255);
ReflectiveIR.init();
ReflectiveIR_M.init();
}

void loop() {

int sensor_read=digitalRead(plasticsensor);
int sensor_read_m=digitalRead(metalsensor);
int sensor_read_mm=digitalRead(metalsensor_M);
Serial.println("plastic sensor");
Serial.println(sensor_read);
Serial.println("metal sensor");
Serial.println(sensor_read_m);
Serial.println(sensor_read_mm);

bool ReflectiveIR_Val = ReflectiveIR.read();
bool ReflectiveIR_Val_M = ReflectiveIR_M.read();
//Plastic bin
if((sensor_read==0)&&(sensor_read_m!=1)){
for (pos = 160; pos >= 90; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
analogWrite(redpin,255);
analogWrite(bluepin,0);
analogWrite(greenpin,255);
delay(2500);
for (pos = 90; pos <= 160; pos += 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position

     }
 analogWrite(redpin,0);
 analogWrite(bluepin,0);
  analogWrite(greenpin,0);

}

else if(ReflectiveIR_Val==1){ //checking the volume of the trash
 analogWrite(redpin,0);
analogWrite(bluepin,255);
analogWrite(greenpin,255);

}

else{
  // goes from 180 degrees to 0 degrees
myservo.write(pos);              // tell servo to go to position in variable 'pos'
                       // waits 15ms for the servo to reach the position


analogWrite(redpin,255);
analogWrite(bluepin,255);
analogWrite(greenpin,255);

}

//metal sensor

  if(sensor_read_mm==1){

for (pos_M = 160; pos_M >= 90; pos_M -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo_M.write(pos_M); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position
}
analogWrite(redpin_M,255);
analogWrite(bluepin_M,0);
analogWrite(greenpin_M,255);
delay(2500);
for (pos_M = 90; pos_M <= 160; pos_M += 1) { // goes from 180 degrees to 0 degrees
myservo_M.write(pos_M); // tell servo to go to position in variable 'pos'
delay(1); // waits 15ms for the servo to reach the position

 }
  analogWrite(redpin_M,0);
  analogWrite(bluepin_M,0);

analogWrite(greenpin_M,0);

}

else if(ReflectiveIR_Val_M==1){
analogWrite(redpin_M,0);
analogWrite(bluepin_M,255);
analogWrite(greenpin_M,255);

}

else{
// goes from 180 degrees to 0 degrees
myservo_M.write(pos_M); // tell servo to go to position in variable 'pos'
// waits 15ms for the servo to reach the position

analogWrite(redpin_M,255);
analogWrite(bluepin_M,255);
analogWrite(greenpin_M,255);

}

}

Try removing the } at the end of this line.

Still got the same error

https://dreamyage.blogspot.com/2019/08/arduino-trash-separation-project.html

Is this the sketch you are trying to compile? If you change the .init() lines to .begin() the code compiles.

// Include Libraries
#include "Arduino.h"
#include "Button.h"
// Pin Definitions
#define REFLECTIVEIR_PIN_COLL  A3
#define REFLECTIVEIR_PIN_COLL_M  A5
// object initialization
Button ReflectiveIR(REFLECTIVEIR_PIN_COLL);
Button ReflectiveIR_M(REFLECTIVEIR_PIN_COLL_M);
// define vars for testing menu
const int timeout = 10000;       //define timeout of 10 sec
char menuOption = 0;
long time0;

#include <Servo.h>
#define redpin 5
#define bluepin 6
#define greenpin 7
#define redpin_M 8
#define bluepin_M 9
#define greenpin_M 10
int plasticsensor = A0;
int anothersensor = A2;
int metalsensor = A4;
int metalsensor_M = A6;

Servo myservo;  // create servo object to control a servo
Servo myservo_M;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 165;    // variable to store the servo position
int pos_M = 158;    // variable to store the servo position

void setup() {
  myservo.attach(11);  // attaches the servo on pin 9 to the servo object
  myservo_M.attach(12);  // attaches the servo on pin 9 to the servo object
  pinMode(redpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  //metal sensor
  pinMode(redpin_M, OUTPUT);
  pinMode(bluepin_M, OUTPUT);
  pinMode(greenpin_M, OUTPUT);

  pinMode(plasticsensor, INPUT_PULLUP);
  pinMode(metalsensor, INPUT_PULLUP);
  pinMode(anothersensor, INPUT_PULLUP);
  pinMode(metalsensor_M, INPUT_PULLUP);
  Serial.begin(9600);
  analogWrite(redpin, 255);
  analogWrite(bluepin, 0255);
  analogWrite(greenpin, 255);
  analogWrite(redpin_M, 255);
  analogWrite(bluepin_M, 0255);
  analogWrite(greenpin_M, 255);
  //ReflectiveIR.init();
  //ReflectiveIR_M.init();
  ReflectiveIR.begin();
  ReflectiveIR_M.begin();
}

void loop() {

  int sensor_read = digitalRead(plasticsensor);
  int sensor_read_m = digitalRead(metalsensor);
  int sensor_read_mm = digitalRead(metalsensor_M);
  Serial.println("plastic sensor");
  Serial.println(sensor_read);
  Serial.println("metal sensor");
  Serial.println(sensor_read_m);
  Serial.println(sensor_read_mm);

  bool ReflectiveIR_Val = ReflectiveIR.read();
  bool ReflectiveIR_Val_M = ReflectiveIR_M.read();
  //Plastic bin
  if ((sensor_read == 0) && (sensor_read_m != 1)) {
    for (pos = 160; pos >= 90; pos -= 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position
    }
    analogWrite(redpin, 255);
    analogWrite(bluepin, 0);
    analogWrite(greenpin, 255);
    delay(2500);
    for (pos = 90; pos <= 160; pos += 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position

    }
    analogWrite(redpin, 0);
    analogWrite(bluepin, 0);
    analogWrite(greenpin, 0);

  }

  else if (ReflectiveIR_Val == 1) { //checking the volume of the trash
    analogWrite(redpin, 0);
    analogWrite(bluepin, 255);
    analogWrite(greenpin, 255);

  }

  else {
    // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    // waits 15ms for the servo to reach the position


    analogWrite(redpin, 255);
    analogWrite(bluepin, 255);
    analogWrite(greenpin, 255);

  }

  //metal sensor

  if (sensor_read_mm == 1) {
    for (pos_M = 160; pos_M >= 90; pos_M -= 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo_M.write(pos_M);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position
    }
    analogWrite(redpin_M, 255);
    analogWrite(bluepin_M, 0);
    analogWrite(greenpin_M, 255);
    delay(2500);
    for (pos_M = 90; pos_M <= 160; pos_M += 1) { // goes from 180 degrees to 0 degrees
      myservo_M.write(pos_M);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position

    }
    analogWrite(redpin_M, 0);
    analogWrite(bluepin_M, 0);
    analogWrite(greenpin_M, 0);

  }

  else if (ReflectiveIR_Val_M == 1) {
    analogWrite(redpin_M, 0);
    analogWrite(bluepin_M, 255);
    analogWrite(greenpin_M, 255);

  }

  else {
    // goes from 180 degrees to 0 degrees
    myservo_M.write(pos_M);              // tell servo to go to position in variable 'pos'
    // waits 15ms for the servo to reach the position


    analogWrite(redpin_M, 255);
    analogWrite(bluepin_M, 255);
    analogWrite(greenpin_M, 255);
  }
}
1 Like

yes that's the sketch I'm using

but how can I change them ?

and which lines are the .init() and which are the .begin() ?

//ReflectiveIR.init();
//ReflectiveIR_M.init();
  ReflectiveIR.begin();
  ReflectiveIR_M.begin();

These are the last lines of setup().


I changed them and still got the same error


this is the error line

You should post code by using code-tags. Do not post an image of your code.

There is an automatic function for doing this in the Arduino-IDE. Just three steps

1)press Ctrl-T for autoformatting your code
2)do a rightclick with the mouse and choose "copy for forum"
3)paste clipboard into write-window of a posting

Copy and paste the complete error message you are getting as well.

// Include Libraries
#include "Arduino.h"
#include "Button.h"
// Pin Definitions
#define REFLECTIVEIR_PIN_COLL  A3
#define REFLECTIVEIR_PIN_COLL_M  A5
// object initialization
Button ReflectiveIR(REFLECTIVEIR_PIN_COLL);
Button ReflectiveIR_M(REFLECTIVEIR_PIN_COLL_M);
// define vars for testing menu
const int timeout = 10000;       //define timeout of 10 sec
char menuOption = 0;
long time0;

#include <Servo.h>
#define redpin 5
#define bluepin 6
#define greenpin 7
#define redpin_M 8
#define bluepin_M 9
#define greenpin_M 10
int plasticsensor = A0;
int anothersensor = A2;
int metalsensor = A4;
int metalsensor_M = A6;

Servo myservo;  // create servo object to control a servo
Servo myservo_M;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 165;    // variable to store the servo position
int pos_M = 158;    // variable to store the servo position

void setup() {
  myservo.attach(11);  // attaches the servo on pin 9 to the servo object
  myservo_M.attach(12);  // attaches the servo on pin 9 to the servo object
  pinMode(redpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  //metal sensor
  pinMode(redpin_M, OUTPUT);
  pinMode(bluepin_M, OUTPUT);
  pinMode(greenpin_M, OUTPUT);

  pinMode(plasticsensor, INPUT_PULLUP);
  pinMode(metalsensor, INPUT_PULLUP);
  pinMode(anothersensor, INPUT_PULLUP);
  pinMode(metalsensor_M, INPUT_PULLUP);
  Serial.begin(9600);
  analogWrite(redpin, 255);
  analogWrite(bluepin, 0255);
  analogWrite(greenpin, 255);
  analogWrite(redpin_M, 255);
  analogWrite(bluepin_M, 0255);
  analogWrite(greenpin_M, 255);
  ReflectiveIR.begin();
  ReflectiveIR_M.begin();
}

void loop() {

  int sensor_read = digitalRead(plasticsensor);
  int sensor_read_m = digitalRead(metalsensor);
  int sensor_read_mm = digitalRead(metalsensor_M);
  Serial.println("plastic sensor");
  Serial.println(sensor_read);
  Serial.println("metal sensor");
  Serial.println(sensor_read_m);
  Serial.println(sensor_read_mm);

  bool ReflectiveIR_Val = ReflectiveIR.read();
  bool ReflectiveIR_Val_M = ReflectiveIR_M.read();
  //Plastic bin
  if ((sensor_read == 0) && (sensor_read_m != 1)) {
    for (pos = 160; pos >= 90; pos -= 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position
    }
    analogWrite(redpin, 255);
    analogWrite(bluepin, 0);
    analogWrite(greenpin, 255);
    delay(2500);
    for (pos = 90; pos <= 160; pos += 1) { // goes from 180 degrees to 0 degrees
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position

    }
    analogWrite(redpin, 0);
    analogWrite(bluepin, 0);
    analogWrite(greenpin, 0);

  }

  else if (ReflectiveIR_Val == 1) { //checking the volume of the trash
    analogWrite(redpin, 0);
    analogWrite(bluepin, 255);
    analogWrite(greenpin, 255);

  }

  else {
    // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    // waits 15ms for the servo to reach the position


    analogWrite(redpin, 255);
    analogWrite(bluepin, 255);
    analogWrite(greenpin, 255);

  }

  //metal sensor

  if (sensor_read_mm == 1) {
    for (pos_M = 160; pos_M >= 90; pos_M -= 1) { // goes from 0 degrees to 180 degrees
      // in steps of 1 degree
      myservo_M.write(pos_M);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position
    }
    analogWrite(redpin_M, 255);
    analogWrite(bluepin_M, 0);
    analogWrite(greenpin_M, 255);
    delay(2500);
    for (pos_M = 90; pos_M <= 160; pos_M += 1) { // goes from 180 degrees to 0 degrees
      myservo_M.write(pos_M);              // tell servo to go to position in variable 'pos'
      delay(1);                       // waits 15ms for the servo to reach the position

    }
    analogWrite(redpin_M, 0);
    analogWrite(bluepin_M, 0);
    analogWrite(greenpin_M, 0);

  }

  else if (ReflectiveIR_Val_M == 1) {
    analogWrite(redpin_M, 0);
    analogWrite(bluepin_M, 255);
    analogWrite(greenpin_M, 255);

  }

  else {
    // goes from 180 degrees to 0 degrees
    myservo_M.write(pos_M);              // tell servo to go to position in variable 'pos'
    // waits 15ms for the servo to reach the position


    analogWrite(redpin_M, 255);
    analogWrite(bluepin_M, 255);
    analogWrite(greenpin_M, 255);

  }


}

the error message


Trash_sepeation:8:42: error: no matching function for call to 'Button::Button(const uint8_t&)'
 Button ReflectiveIR(REFLECTIVEIR_PIN_COLL);
                                          ^
In file included from C:\Users\zizo\Documents\Arduino\Trash_sepeation\Trash_sepeation.ino:3:0:
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:27:5: note: candidate: Button::Button(int, bool, unsigned char*)
     Button(int myBit, bool myMode, unsigned char *myRegister);
     ^~~~~~
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:27:5: note:   candidate expects 3 arguments, 1 provided
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:26:5: note: candidate: Button::Button(int, bool)
     Button(int myPin, bool myMode);
     ^~~~~~
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:26:5: note:   candidate expects 2 arguments, 1 provided
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note: candidate: constexpr Button::Button(const Button&)
 class Button {
       ^~~~~~
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note:   no known conversion for argument 1 from 'const uint8_t {aka const unsigned char}' to 'const Button&'
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note: candidate: constexpr Button::Button(Button&&)
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note:   no known conversion for argument 1 from 'const uint8_t {aka const unsigned char}' to 'Button&&'
Trash_sepeation:9:46: error: no matching function for call to 'Button::Button(const uint8_t&)'
 Button ReflectiveIR_M(REFLECTIVEIR_PIN_COLL_M);
                                              ^
In file included from C:\Users\zizo\Documents\Arduino\Trash_sepeation\Trash_sepeation.ino:3:0:
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:27:5: note: candidate: Button::Button(int, bool, unsigned char*)
     Button(int myBit, bool myMode, unsigned char *myRegister);
     ^~~~~~
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:27:5: note:   candidate expects 3 arguments, 1 provided
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:26:5: note: candidate: Button::Button(int, bool)
     Button(int myPin, bool myMode);
     ^~~~~~
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:26:5: note:   candidate expects 2 arguments, 1 provided
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note: candidate: constexpr Button::Button(const Button&)
 class Button {
       ^~~~~~
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note:   no known conversion for argument 1 from 'const uint8_t {aka const unsigned char}' to 'const Button&'
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note: candidate: constexpr Button::Button(Button&&)
C:\Users\zizo\Documents\Arduino\libraries\Arduino-Library-Button-main/Button.h:21:7: note:   no known conversion for argument 1 from 'const uint8_t {aka const unsigned char}' to 'Button&&'
C:\Users\zizo\Documents\Arduino\Trash_sepeation\Trash_sepeation.ino: In function 'void setup()':
Trash_sepeation:56:16: error: 'class Button' has no member named 'begin'
   ReflectiveIR.begin();
                ^~~~~
Trash_sepeation:57:18: error: 'class Button' has no member named 'begin'
   ReflectiveIR_M.begin();
                  ^~~~~
C:\Users\zizo\Documents\Arduino\Trash_sepeation\Trash_sepeation.ino: In function 'void loop()':
Trash_sepeation:71:40: error: 'class Button' has no member named 'read'
   bool ReflectiveIR_Val = ReflectiveIR.read();
                                        ^~~~
Trash_sepeation:72:44: error: 'class Button' has no member named 'read'
   bool ReflectiveIR_Val_M = ReflectiveIR_M.read();
                                            ^~~~
exit status 1
no matching function for call to 'Button::Button(const uint8_t&)'

#include "Button.h"

The sketch is written for a library called Button by Michael Adams. It can be installed through the library manager. I can compile the sketch for an Uno without error.

I'm not clear what library you are using, or where you got it from, but I would delete it and reinstall the library I referenced through the library manager.

EDIT: I think you are trying to use this library
https://github.com/carlynorama/Arduino-Library-Button/blob/main/Button.h

I think you have installed a library called Button-Arduino by Davide Palladino. That's not the library the sketch is written to use.

thnx man
It compiled fine when I installed Michael Adams library

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.