No match for 'operator+'

I am getting error suddenly. I just took the file and re-compiled and it started throwing this error.

This is what is running on the Arduino board now.

***Blynk_app_connect:254:19: error: no match for 'operator+' (operand types are 'BlynkTimer' and 'const long unsigned int')***
***     timer = timer + pirConstTimer;***
***             ~~~~~~^~~~~~~~~~~~~~~***
***Blynk_app_connect:255:21: error: no match for 'operator<' (operand types are 'long unsigned int' and 'BlynkTimer')***
***     while (millis() < timer)***
***            ~~~~~~~~~^~~~~~~***
***Blynk_app_connect:260:24: error: no match for 'operator=' (operand types are 'BlynkTimer' and 'long unsigned int')***
***         timer = millis();***

This is the method where it is throwing error.

void callPirSensior() { 
  // Serial.println("Entering...callPirSensior");
  volatile long pirTimer = 0;
  if (digitalRead(pirPin) == HIGH) {
    pirTimer = millis();   
    while (millis() <  timer + pirConstTimer)
    {
      digitalWrite(relayModuleInput_2, LOW);
      if (millis() > (pirTimer + 2300) && digitalRead(pirPin) == HIGH)
      {
        timer = millis();
      }
    }
  }
  //Serial.println("Leaving...callPirSensior");
}```

Almost impossible to debug based on just this snippet of code.
I think you need to post the full sketch exactly as you are trying to compile it.

Pete.

This is the full skech.

#define BLYNK_PRINT Serial
#include <Arduino.h>
#include <Wire.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>
#include <TimeLib.h>                                    /* Program code related to Real Time Clock (RTC). */
#include <WidgetRTC.h>                                  /* Communication code with Blynk Real Time Clock Widget */ 
 

void callPirSensior();
void callLDRSensor();
void LDRAndPIR();
bool calculateTimeGreater(int, int, int);
bool calculateTimeLesser(int, int, int);

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXX";

// Your WiFi credentials for home network
char ssid[] = "2.4-XXXX";
char pass[] = "XXXXX";

//Software Serial on Uno, Nano... - This is were the ESP-01 module will communicate
SoftwareSerial EspSerial(2, 3); // RX, TX

BlynkTimer timer;
WidgetRTC rtc;

ESP8266 wifi(&EspSerial);

//INPUT
const uint8_t LDR = 13;
const uint8_t pirPin = 4;

//OUTPUT
const uint8_t relayModuleInput_2 = 8;
const uint8_t relayModuleInput_1 = 12;
const uint8_t buzzer = 7;

//Varibales
volatile boolean dontBuzz = true;
volatile boolean forceOff = false;
volatile boolean forceOn = false;
volatile boolean isRelayModuleOn = false;
const unsigned long pirConstTimer = 50000L;

WidgetLED led0(V1);
WidgetLED led1(V0);

void(* resetFunc) (void) = 0;

BLYNK_CONNECTED() {
  // Synchronize time on connection
  rtc.begin();
  Blynk.syncAll();
}

// Two Led in the blynk app- This is to know if the relayModule is on or off.
void blinkLedWidget()
{
  if (!isRelayModuleOn) {
    led0.off();
    led1.on();
  } else {
    led0.on();
    led1.off();

  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  delay(100);
  //OUTPUT
  pinMode(relayModuleInput_2, OUTPUT);
  digitalWrite(relayModuleInput_2, HIGH);
  digitalWrite(relayModuleInput_1, HIGH);
  forceOn = false;
  forceOff = false;
  isRelayModuleOn = false;
  blinkLedWidget();
  setSyncInterval(20 * 60); // Sync interval in seconds
  timer.setInterval(500L, blinkLedWidget);
  timer.setInterval(2200L, LDRAndPIR);
  timer.setInterval(50000L, resetForceOffBool);
  timer.setInterval(60000L * 23, resetFunc);
  //attachInterrupt(digitalPinToInterrupt(interruptPin), LDRAndPIR, CHANGE); //Arduino recommended way. [2 & 3 are Interrupts]

}

BLYNK_WRITE(V5)
{
  int pinValue = param.asInt();
  if (pinValue == 1) {
    digitalWrite(relayModuleInput_2, LOW);
    forceOff = false;
    forceOn = true;
    isRelayModuleOn = true;
  }
  else if (pinValue == 0) {
    digitalWrite(relayModuleInput_2, HIGH);
    forceOff = true;
    forceOn = false;
    isRelayModuleOn = false;
  }
}

void loop()
{
  Blynk.run();
  timer.run();
}

void LDRAndPIR() {
  if (forceOn) { // If light is On from the Blynk App.
    isRelayModuleOn = true;
    return;
  }

  bool morning = calculateTimeGreater (6, 30, 00);
  bool toEve = calculateTimeLesser (17, 59, 59);

  if (morning && toEve) {
    //Skip till eve @ 6.10 PM
  } else {
    bool trunOnLDRAndPIR = calculateTimeGreater (18, 00, 00);
    bool trunOnOnlyLDR = calculateTimeLesser (22, 29, 59);
    if (trunOnLDRAndPIR)
    {
      //PIR Sensior
      callPirSensior();

      //LDR Sensor
      if (trunOnOnlyLDR) {
        callLDRSensor();
      }
      else {
        digitalWrite(relayModuleInput_2, HIGH);
        isRelayModuleOn = false;
      }
    }  else {
      //From midnight to morning.
      bool trunOnOnlyPIR = calculateTimeGreater (00, 00, 00);
      bool trunOffOnlyPIR = calculateTimeLesser (6, 30, 00);
      if (trunOnOnlyPIR && trunOffOnlyPIR) {
        //PIR Sensior
        callPirSensior();
      }
      if (!forceOn) {
        digitalWrite(relayModuleInput_2, HIGH);
        isRelayModuleOn = false;
      }
    }
  }
}

bool calculateTimeGreater(int inputHour, int inputMin, int inputSec) {
  if (hour() > inputHour) {
    return true;
  } else if (hour() == inputHour) {
    if (minute() > inputMin) {
      return true;
    }
    if (minute() == inputMin) {
      if (second() >= inputSec) {
        return true;
      }
    }
  }
  return false;
}

bool calculateTimeLesser(int inputHour, int inputMin, int inputSec) {
  if (hour() < inputHour) {
    return true;
  } else if (hour() == inputHour) {
    if (minute() < inputMin) {
      return true;
    }
    if (minute() == inputMin) {
      if (second() <= inputSec) {
        return true;
      }
    }
  }
  return false;
}

void showTime()
{
  Serial.print("Time:");
  Serial.print(hour());
  Serial.print(':');
  Serial.print(minute());
  Serial.print(':');
  Serial.print(second());
  Serial.print("    ");
  Serial.print(" ");
  Serial.println();
}
/**
  This will call from 18:10:00 to next day morning 6:30:00 morning. If there is any motion detected it will get on. If we force off from the Blynk app trun off the light.
**/
void callPirSensior() { 
  volatile long pirTimer = 0;
  if (digitalRead(pirPin) == HIGH && !forceOff) {
    pirTimer = millis();
    isRelayModuleOn = true;
    blinkLedWidget();// This has to be called if not the value dont gets changed.
    forceOff = false;
    timer = timer + pirConstTimer;
    while (millis() < timer)
    {
      digitalWrite(relayModuleInput_2, LOW);
      if (millis() > (pirTimer + 2300) && digitalRead(pirPin) == HIGH)
      {
        timer = millis();
      }
    }
  }
  //Serial.println("Leaving...callPirSensior");
}

/**
  This method will be called only during the 18:10:00 
  to 22:30:00 hours. If force off from the Blynk app turn off the light.
**/
void callLDRSensor() {
  //Serial.println("Entering...callLDRSensor");
  if (digitalRead(LDR) == HIGH && !forceOff) {
    digitalWrite(relayModuleInput_2, LOW);
    isRelayModuleOn = true;
  } else {
    digitalWrite(relayModuleInput_2, HIGH);
    isRelayModuleOn = false;
  }
  // Serial.println("Leaving...callLDRSensor");
}

void resetForceOffBool() {
  //Serial.println("Entering...resetForceOffBool");
  //bool trunOn = calculateTimeGreater (6, 29, 59);
  //bool trunOff = caslculateTimeLesser (22, 29, 59);
  if (forceOff) {
    //Serial.println("Entering forceOn to reset...");
    forceOff = false;
  }
  //Serial.println("Leaving...resetForceOffBool");
}

This is working. I just copy-pasted the same code into a new file and it worked. :thinking: :thinking:

Well, the code you posted gives exactly the same compiler messages that you received when I try to compile it. and I’ll explain why - and what you need to do to fix it.

This line defines a BlynkTimer object with the name of timer

BlynkTimer timer;

This is used in several places throughout the code like this…

  timer.setInterval(2200L, LDRAndPIR);
  timer.setInterval(50000L, resetForceOffBool);
  timer.setInterval(60000L * 23, resetFunc);

and this…

  timer.run();

The timer object isn’t a variable, so you can’t do normal variable operations with it like this…

timer = timer + pirConstTimer;

which is why you get the error messages.

I believe that what you should be doing in your code is this…

    pirTimer = pirTimer + pirConstTimer;

There are several other places in your code where you try to change the value of the timer object rather than the pirTimer variable. Once these are rectified the code compiles correctly.

Pete.

Got it. Ya. I should not used the timer object in the PIR sensor method. I re-named it. I should have used that variable. It was my mistake. Thx a lot.