Hi all, i have encountered this error: Select list item: List index too large
This is my code blocks
This is my arduino code
#include <Wire.h> //For LCD
#include <LiquidCrystal_I2C.h> //For LCD
#include <Servo.h> //For Servo
#include <SoftwareSerial.h> //For Bluetooth
Servo myservo; //Servo 1
Servo myservo2; //Servo 2
Servo myservo3; //Servo 3
LiquidCrystal_I2C lcd(0x27, 16, 2); //GND=GROUND,VCC=5V,SCL=A4,SDA=A5
int IR = 2; //digital Pin 2 as IR sensor
int IR2 = 3; //digital Pin 3 as IR sensor
int pushButton = 4; //digital Pin 4 as PushButton
int TX = 5; //digital Pin 5 as TX pin for Bluetooth
int RX = 6; //digital Pin 6 as RX pin for Bluetooth
int Echo = 9; //Sets the Echo as an Input for Ultrasonic
int Trigger = 10; //Sets the Trigger as an Output for Ultrasonic
int LED = 11; //digital Pin 11 as Red LED
int LED2 = 12; //digital Pin 12 as Green LED
int Buzzer = 13; //digital Pin 13 as Buzzer
SoftwareSerial HC05(TX, RX); //For Bluetooth
String BT_data=""; //Data From HC-05 for Bluetooth
String Arduino_data=""; //Data From Arduino to HC-05
String lcdBTData = "";
// defines variables
long duration; //For Ultrasonic
int distance; //For Ultrasonic
int safetyDistance; //For Ultrasonic
bool scenario1Active = false; // Variable to track the state of scenario 1
void setup() {
pinMode(IR, INPUT);
pinMode(IR2, INPUT);
pinMode(pushButton, INPUT);
pinMode(Trigger, OUTPUT);
pinMode(Echo, INPUT);
pinMode(LED, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(Buzzer, OUTPUT);
myservo.attach(7);
myservo.write(0);
myservo2.attach(8);
myservo.write(0);
myservo3.attach(A0);
myservo.write(0);
lcd.begin();
lcd.backlight();
lcd.print("System On");
Serial.begin(9600);
HC05.begin(9600);
}
void loop() {
digitalWrite(Trigger, LOW);
delayMicroseconds(2);
digitalWrite(Trigger, HIGH);
delayMicroseconds(10);
digitalWrite(Trigger, LOW);
duration = pulseIn(Echo, HIGH);
distance = duration * 0.034 / 2;
safetyDistance = distance;
Serial.print("Ultrasonic Value: ");
Serial.println(distance);
int sensorValue = digitalRead(IR);
int sensorValue2 = digitalRead(IR2);
if ((safetyDistance <= 5)||(BT_data == "2")) //**Scenario 1**
{
scenario1Active = true;
tone(Buzzer, 150);
delay(50);
noTone(Buzzer);
delay(50);
digitalWrite(LED, HIGH);
delay(50);
digitalWrite(LED, LOW);
delay(50);
lcd.clear();
lcd.print("Obstruction");
myservo.write(100);
myservo2.write(40);
myservo3.write(20);
digitalWrite(LED2, LOW);
} else {
scenario1Active = false;
}
if ((!scenario1Active && sensorValue == LOW)||(BT_data == "3")) //**Scenario 2**
{
tone(Buzzer, 150);
digitalWrite(LED, HIGH);
lcd.clear();
lcd.print("Train Coming ");
myservo.write(100);
digitalWrite(LED2, LOW);
}
if ((sensorValue2 == LOW)||(BT_data == "4")) //**Scenario 3**
{
noTone(Buzzer);
digitalWrite(LED2, HIGH);
digitalWrite(LED, LOW);
lcd.clear();
lcd.print("Safe to Pass ");
myservo.write(0);
myservo2.write(0);
}
if ((BT_data == "5")|| (digitalRead(pushButton) == HIGH)) //**Scenario 4**
{
noTone(Buzzer);
digitalWrite(LED, LOW);
digitalWrite(LED2, LOW);
lcd.clear();
myservo.write(0);
myservo2.write(0);
myservo3.write(0);
}
if (BT_data == "6")
{
myservo.write(100);
}
if (BT_data == "7")
{
myservo2.write(40);
}
if (BT_data == "8")
{
digitalWrite(LED, HIGH);
}
if (BT_data == "9")
{
digitalWrite(LED2, HIGH);
}
if (BT_data == "10")
{
tone(Buzzer, 150);
}
if (HC05.available())
{
BT_data = HC05.readString();
Serial.println(BT_data);
lcd.setCursor(0,1);
//lcd.print(BT_data);
if (BT_data != "2" && BT_data != "3" && BT_data != "4"&& BT_data != "5" && BT_data != "6" && BT_data != "7" && BT_data != "8" && BT_data != "9" && BT_data != "10") {
lcd.print(BT_data);
}
}
if (Serial.available()) //**Scenario 5**
{
Arduino_data = Serial.readString();
BT_data = "";
HC05.print("\r");
HC05.println(Arduino_data);
}
HC05.print(distance);
HC05.print("|");
HC05.print(sensorValue);
HC05.print("|");
HC05.print(sensorValue2);
HC05.print("|");
HC05.println(Arduino_data);
delay(1000);
}
Really appreciate if could help as I'm at lost.