HELP : Arduino Mega Project (RFID - LCD -etc)

I need a help witch this project.
in the void loop() : the 3rd if remove_int and else if remove_int doesn't work with lcd_standby() and lcd_remove() function.
I will be glad if you help me. thx
Edit : I deleted unnecessary codes because it was limited to 9000 words. If necessary, the full code: Full Code (click to see it)

#include "HUSKYLENS.h"
#include "SoftwareSerial.h"
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#define echopin  22 //distnce sensor
#define trigpin 23 //distance sensor
int time0; //time integer (hc-sr04)
int distance; //distance integer (hc-sr04)
int left1 = 2;  //motor driver pins
int left2 = 3;  //motor driver pins
int right1 = 4;  //motor driver pins
int right2 = 5;  //motor driver pins
int pwmleft = 6;  //motor driver pins (pwm)
int pwmright = 7;  //motor driver pins (pwm)
int RST_PIN = 49;  // 50miso 51mosi 52sck  (rfid)
int SS_PIN = 53;  //(rfid)
int total = 0; //basket total
int water = 2; //tl
int chips = 6; //tl
int milk = 8; //tl
int yoghurt = 10; //tl
int remove_button = A1; //remove push button pin
int data ; //data receive from bluetooth
int auto_switch = A2; //auto-manuel drive switch pin

HUSKYLENS huskylens;
SoftwareSerial mySerial(10, 11); //rx tx (arduino) cam pins
LiquidCrystal_I2C lcd(0x27, 20, 4); //20x4 LCD define.
MFRC522 rfid(SS_PIN, RST_PIN);  //rfid defined pins.
void printResult(HUSKYLENSResult result);
void setup() {
  Serial.begin(115200);
  mySerial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  lcd_start();
  total = 0;
  pinMode(left1, OUTPUT);
  pinMode(left2, OUTPUT);
  pinMode(right1, OUTPUT);
  pinMode(right2, OUTPUT);
  pinMode(pwmleft, OUTPUT);
  pinMode(pwmright, OUTPUT);
  pinMode(echopin, INPUT);
  pinMode(trigpin, OUTPUT);
  pinMode(remove_button, INPUT_PULLUP);
  pinMode(auto_switch, INPUT_PULLUP);

  while (!huskylens.begin(mySerial))
  {
    delay(100);
  }

}

void loop() {

  digitalWrite(trigpin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigpin, LOW);
  time0 = pulseIn(echopin, HIGH);
  distance = (time0 / 2) / 29.1 ;

  int remove_int = analogRead(remove_button);
  int auto_int = analogRead(auto_switch);

  if (Serial.available()) {
    data = Serial.read();
  }
  if (auto_int <= 150) { //auto
    while (huskylens.available())
    {
      HUSKYLENSResult result = huskylens.read();
      printResult(result);
      driveBot(result);
    }
  }
  else if (auto_int >= 950) { // manuel
    if (data == '1' && distance >= 30) { //forward



    }
    else if (data == '2' && distance >= 30) { //left



    }
    else if (data == '3' && distance >= 30) { //right

  

    }
    else if (data == '4') { //backward



    }
    else if (data == '0') { //stop

    }
    else {

    }
  }
  if (remove_int >= 950) {
    lcd_standby();
    if ( ! rfid.PICC_IsNewCardPresent())
      return;
    if ( ! rfid.PICC_ReadCardSerial())
      return;
    if (rfid.uid.uidByte[0] == 186  ) {


    }
    else if (rfid.uid.uidByte[0] == 178  ) {


    }
    else if (rfid.uid.uidByte[0] == 217  ) {


    }
    else if (rfid.uid.uidByte[0] == 153  ) {


    }
    else {
      undefined();
    }
    rfid.PICC_HaltA();
  }
  else if (remove_int <= 150) {
    lcd_remove();
    if ( ! rfid.PICC_IsNewCardPresent())
      return;
    if ( ! rfid.PICC_ReadCardSerial())
      return;
    if (rfid.uid.uidByte[0] == 186   ) { //bu mekanın lordları bizi madafaka



    }
    else if (rfid.uid.uidByte[0] == 178 ) {

    }
    else if (rfid.uid.uidByte[0] == 217 ) {


    }
    else if (rfid.uid.uidByte[0] == 153 ) {


    }
    else {
      undefined();
    }
    rfid.PICC_HaltA();
  }
}
void printResult(HUSKYLENSResult result) {

}
void driveBot(HUSKYLENSResult result) //auto
{
  if (result.xCenter <= 120) //left
  {
    if ( distance >= 30) {

    }
    else {
 
    }
  }

  else if (result.xCenter >= 200) //right
  {
    if ( distance >= 30) {

    }
    else {

    }
  }

  else if ((result.xCenter >= 120) && (result.xCenter <= 200))
  {
    if (result.width <= 50 && distance >= 30) //forward
    {

    }

    else if (result.width > 50 || distance < 30) // stop
    {

    }
    else {

    }
  }
  else {

  }
}



void lcd_remove() {
  lcd.setCursor(2, 0);
  lcd.print("Plaese read the");
  lcd.setCursor(0, 1);
  lcd.print("Product for Removing");
  lcd.setCursor(4, 2);
  lcd.print("from Basket");
  delay(500);
  lcd.clear();

  /*lcd.print("Basket Total");
    lcd.setCursor(8,2);
    lcd.print(total);
    lcd.setCursor(11,2);
    lcd.print("TL"); */
}


void lcd_standby() {

  lcd.setCursor(2, 0);
  lcd.print("Plaese read the");
  lcd.setCursor(6, 1);
  lcd.print("Product");
  lcd.setCursor(1, 3);
  lcd.print("Basket Total=");
  lcd.setCursor(14, 3);
  lcd.print(total);
  lcd.setCursor(18, 3);
  lcd.print("TL");
  delay(500);
  lcd.clear();
}

sad.ino (11.7 KB)

What do you mean by "doesn't work" How does it not work? Are you seeing anything on your LCD? You can always insert some Serial.print() statements to help debug the problem. For example, what is the value of remove_int? You only act on it if it is above 950 or below 150.
Also note, you can use the analog pins as digital inputs, just declare them as INPUT or INPUT_PULLUP and use digitalRead() since it seems you are just reading on/off state of a button. How to you have them wired up? A common way is one side to ground and the other side to the input pin and then declare the pin as INPUT_PULLUP. No external resistors required. This makes a button press LOW and a non-press HIGH.

Try clearing your data after you use it.
i.e.
data = -1; // clear after processing

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