No matching for function

I am making a project using ESP32 and I wanna make an output to thingspeak. Since I'm using 2 sensor, I wanna make 2 output in Thingspeak. I've tried make one output by one of the sensor I'm using and fortunately it worked but when I tried to make 2 output I keep getting this error. Btw I'm using HCSR04 sensor and HCSR501 sensor.Idk what function I did not recall in this scope. A little help would be appreciate.

no matching function for call to 'ThingSpeakClass::writeField(long unsigned int&, const char*&)'

#include <ThingSpeak.h>
#include <WiFi.h>
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
#include <Servo.h>
#define SERVO_PIN 26
Servo servoMotor;
const int trigPin = 4;
const int echoPin = 5;
int Redled = 25;
int Greenled = 21;
int inputPin = 39;
int pinStateCurrent   = LOW;  
int pinStatePrevious  = LOW; 
int val = 0;
int pirState = LOW;
const char* ssid = "okay";
const char* password = "hannan122";

WiFiClient  client;

unsigned long myChannelNumber = xxxx;
const char * myWriteAPIKey = "xxxxx";
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;

long duration;
float distanceCm;
int sd;

void setup() {
  Serial.begin(115200); 
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  pinMode(Redled, OUTPUT);
  pinMode(Greenled, OUTPUT);
  WiFi.mode(WIFI_STA);
  ThingSpeak.begin(client);
  servoMotor.attach(SERVO_PIN);
  pinMode(inputPin, INPUT);
}

void loop(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distanceCm = duration * SOUND_SPEED/2;

  Serial.print("Distance (cm): ");
  Serial.println(distanceCm);

   delay(500);
  sd = distanceCm;
  if(sd<=7)
  {
    delay(200);
    digitalWrite(Redled, LOW);
    digitalWrite(Greenled, HIGH);
  }
  else if(sd>=8)
  {
    delay(200);
    digitalWrite(Redled, HIGH);
    digitalWrite(Greenled, LOW);
    
  }
   val = digitalRead(inputPin); 
  if (val == HIGH)  // check if the input is HIGH
  { 
    delay(500);
    for (int pos = 0; pos <= 180; pos += 1) {
    // in steps of 1 degree
    servoMotor.write(pos);             
    delay(15);                      
  }
  for (int pos = 180; pos >= 0; pos -= 1) { 
    servoMotor.write(pos);              
    delay(15);                      
  }
    
    if (pirState == LOW) 
  {
      delay(500);
      Serial.println("Motion detected!"); 
      pirState = HIGH;
    }
  } 
  else 
  {
    delay(500);
    if (pirState == HIGH)
  {
      delay(500);
      Serial.println("Motion ended!");  
      pirState = LOW;
    }
  }
  if ((millis() - lastTime) > timerDelay) {
    
    // Connect or reconnect to WiFi
    if(WiFi.status() != WL_CONNECTED){
      Serial.print("Attempting to connect");
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, password); 
        delay(1000);     
      } 
      Serial.println("\nConnected.");
    }
  
    
    ThingSpeak.setField(1, distanceCm);
    ThingSpeak.setField(2, inputPin);
    int x = ThingSpeak.writeField(myChannelNumber, myWriteAPIKey);
    if(x == 200){
      Serial.println("Channel update successful.");
    }
    else{
      Serial.println("Problem updating channel. HTTP error code " + String(x));
    }
    lastTime = millis();
  }
}

Check the documentation. writeField takes four parameters, not two.

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