Why mit have error the operation cannot accept the argument


For block diagram

For code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
SoftwareSerial bt (7,8);

const int ldrPin = 10;
const int ledPin1 = 12;
const int ledPin2 = 11;
const int buttonPin1 = 3; // Assuming the first button is connected to pin 7
const int buttonPin2 = 4; // Assuming the second button is connected to pin 6
const int ledPin3 = 6; // LED 3
const int ledPin4 = 5; // LED 4
unsigned long lcdWarningStartTime = 0; // Variable to store the start time for the warning message
const unsigned long lcdWarningDuration = 2000; // Duration for the warning message in milliseconds
unsigned long darkSceneStartTime = 0;
const unsigned long darkSceneDelay = 2000; // 2-second delay
int lightSensorValue;
int darkSceneThreshold = 200; // Adjust this threshold based on your light conditions

LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 chars by 2 lines display

void setup() {
  Serial.begin(9600);
  bt.begin (9600);

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ldrPin, INPUT);
  pinMode(buttonPin1, INPUT_PULLUP); // Using internal pull-up resistor for button 1
  pinMode(buttonPin2, INPUT_PULLUP); // Using internal pull-up resistor for button 2
  lcd.begin();
  lcd.backlight();
}

void loop() {
  unsigned long currentMillis = millis(); // Current time

  if (digitalRead(ldrPin) == HIGH || digitalRead(buttonPin1) == LOW) {
    // Existing dark scene LCD code
    if (digitalRead(ldrPin) == HIGH && digitalRead(buttonPin2) == LOW) {
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("DARK SCENE : YES");
      bt.print("DARK SCENE: YES ");
      bt.print("OPEN LIGHT");
      delay(1000);

      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("OPEN LIGHT");
      delay(1000);
    } else {
      if (currentMillis - lcdWarningStartTime < lcdWarningDuration) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("    WARNING    ");
        delay(1000);
      } else {
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("DARK SCENE : YES");
      bt.print("DARK SCENE: YES ");
      bt.print("OPEN LIGHT");
      delay(1000);

      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("OPEN LIGHT");
      }
    }
  } else {
    // Existing LCD code for when not in a dark scene
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("DARK SCENE : NO");
      bt.print("DARK SCENE: NO ");
      bt.print("CLOSED LIGHT ");
      delay(1000);

      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("CLOSED LIGHT");
    lcdWarningStartTime = currentMillis;
  }
  
  // Existing LED control code

  if (digitalRead(ldrPin) == HIGH || digitalRead(buttonPin1) == LOW) {
    // Existing LED control code
    if (darkSceneStartTime == 0) {
      darkSceneStartTime = millis();
    }

    if (millis() - darkSceneStartTime >= darkSceneDelay) {
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
    }

    if (digitalRead(ldrPin) == HIGH && digitalRead(buttonPin2) == LOW) {
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH);
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, HIGH);
    }
  } else {
    // Existing LED control code when not in a dark scene
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW);
    darkSceneStartTime = 0;
  }

  // Ensure that the serial buffer is flushed before the delay to avoid issues
  Serial.flush();

  delay(1000); // Adding a delay of 1 second (1000 milliseconds)
}

Because < is a math operator , it works with number only, in your project you get a number and a text "YES OPEN LIGHT ....."

MY BLOCK DIAGRAM

MY CODE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>

SoftwareSerial bt(7, 8); // Assuming Bluetooth connection
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27, 16 chars by 2 lines display

// Pin assignment
const int ldrPin = 10;
const int ledPin1 = 12;
const int ledPin2 = 11;
const int ledPin3 = 6; // LED 6
const int ledPin4 = 5; // LED 5

const int buttonPin1 = 3; // Assuming the first button is connected to pin 7
const int buttonPin2 = 4; // Assuming the second button is connected to pin 6

unsigned long lcdWarningStartTime = 0; // Variable to store the start time for the warning message
const unsigned long lcdWarningDuration = 2000; // Duration for the warning message in milliseconds

void setup() {
  Serial.begin(9600); // For debugging purposes, if needed
  bt.begin(9600);

  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ldrPin, INPUT);
  pinMode(buttonPin1, INPUT_PULLUP); // Using internal pull-up resistor for button 1
  pinMode(buttonPin2, INPUT_PULLUP); // Using internal pull-up resistor for button 2
  lcd.begin();
  lcd.backlight();
}

void loop() {
  unsigned long currentMillis = millis(); // Current time

  if (digitalRead(ldrPin) == HIGH || digitalRead(buttonPin1) == LOW) {
    // Existing dark scene LCD code
    if (digitalRead(ldrPin) == HIGH && digitalRead(buttonPin2) == LOW) {
      lcd.setCursor(0, 0);
      lcd.clear();
      lcd.print("DARK SCENE : YES");
      delay(1000);

      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("OPEN LIGHT");
      delay(1000);
    } else {
      if (currentMillis - lcdWarningStartTime < lcdWarningDuration) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("    WARNING    ");
        delay(1000);
      } else {
        lcd.setCursor(0, 0);
        lcd.clear();
        lcd.print("DARK SCENE : YES");
        delay(1000);

        lcd.setCursor(0, 1);
        lcd.clear();
        lcd.print("OPEN LIGHT");
      }
    }
  } else {
    // Existing LCD code for when not in a dark scene
    lcd.setCursor(0, 0);
    lcd.clear();
    lcd.print("DARK SCENE : NO");
    delay(1000);

    lcd.setCursor(0, 1);
    lcd.clear();
    lcd.print("CLOSED LIGHT");
  }

  // Existing LED control code
  if (digitalRead(ldrPin) == HIGH || digitalRead(buttonPin1) == LOW) {
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, HIGH); // Both LEDs on when high LDR reading or either button pressed
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW); // LEDs on when either button pressed

    if (digitalRead(ldrPin) == HIGH && digitalRead(buttonPin2) == LOW) {
      digitalWrite(ledPin1, HIGH);
      digitalWrite(ledPin2, HIGH); // Both LEDs off when low LDR reading and no button pressed
      digitalWrite(ledPin3, HIGH);
      digitalWrite(ledPin4, HIGH); // LEDs off when no button pressed
    }
  } else {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW); // Both LEDs off when low LDR reading and no button pressed
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin4, LOW); // LEDs off when no button pressed
  }

  // Send data over Bluetooth
  bt.print("d");
  bt.print(digitalRead(ldrPin));
  bt.print(";");
  bt.print(digitalRead(buttonPin1));
  bt.print(";");
  bt.print(digitalRead(buttonPin2));
  bt.print(";");

  // Ensure that the serial buffer is flushed before the delay to avoid issues
  Serial.flush();

  delay(1000); // Adding a delay of 1 second (1000 milliseconds)
}

Why mit cannot read data when sensor detect

What do you get in Label2 if you deactivate the 3rd if statement?

Taifun