Hello how do I fix this, it's saying list index is too large, I tried all the solutions but it's still not working, also here is the aia
app_carcar (1).aia (3.9 KB)
I have tried it but nothing happened so far.
Here is the code of my Arduino.
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include<Wire.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,20,4);
SoftwareSerial bluetooth(0,1);
String msg;
Servo myservo;
int servo_entrance=11;
int servo_exit=12;
int deserbo=10;
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Hi Welcome to");
lcd.setCursor(0,1);
lcd.print("SuperMall!");
delay(10000);
lcd.clear();
pinMode(servo_entrance,INPUT);
pinMode(servo_exit,INPUT);
myservo.attach(deserbo);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(A1,INPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(A2,INPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(A3,INPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(A0,INPUT);
}
void loop() {
int a=digitalRead(A1);
int b=digitalRead(A2);
int c=digitalRead(A3);
int d=digitalRead(A0);
int se=digitalRead(servo_entrance);
int sx=digitalRead(servo_exit);
int ao, bo, co, lo = 0;
lcd.setCursor(0, 0);
lcd.print("Total remaining");
lcd.setCursor(0, 1);
lcd.print("parking slot: ");
if(a==1)
{
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
Serial.print("1");
Serial.print("|");
ao=1;
}
else if(a == 0){
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
Serial.print("0");
Serial.print("|");
ao=0;
}
if(b==1)
{
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
Serial.print("1");
Serial.print("|");
bo=1;
}
else if(b == 0){
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
Serial.print("0");
Serial.print("|");
bo=0;
}
if(c==1)
{
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
Serial.print("1");
Serial.print("|");
co=1;
}
else if(c == 0){
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
Serial.print("0");
Serial.print("|");
co=0;
}
if(d==1)
{
digitalWrite(8,HIGH);
digitalWrite(9,LOW);
Serial.println("1");
lo=1;
}
else if(d== 0){
digitalWrite(8,LOW);
digitalWrite(9,HIGH);
Serial.println("0");
lo=0;
}
int total = ao + bo + co + lo;
int slot = 4 - total;
if (total==4){
lcd.setCursor(14, 1);
lcd.print("0");
}
else{
if (se == 1 && sx ==1){
myservo.write(0);
}
if(se == 0 && sx == 0){
myservo.write(90);
}
lcd.setCursor(14, 1);
lcd.print(slot);
}
delay(500);
}
This should work. Are you using a serial monitor? Is the BT module connected to the correct pins?
See what data this application will receive.
The arduino code looks correct. The blocks too if you changed the numberOfBytes value to -1, so the electrical connection of the module remains.
No I am only using Serial Data, and Serial Clock. The Bluetooth pins are also connected correctly.
I can't verify this...there is no such error in AI2 that data is not received at all.
This should work identically to your code, but is simpler:
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include<Wire.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x27,20,4);
SoftwareSerial bluetooth(0,1);
String msg;
Servo myservo;
int servo_entrance=11;
int servo_exit=12;
int deserbo=10;
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Hi Welcome to");
lcd.setCursor(0,1);
lcd.print("SuperMall!");
delay(10000);
lcd.clear();
pinMode(servo_entrance,INPUT);
pinMode(servo_exit,INPUT);
myservo.attach(deserbo);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(A1,INPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(A2,INPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(A3,INPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(A0,INPUT);
}
void loop() {
int a=digitalRead(A1);
int b=digitalRead(A2);
int c=digitalRead(A3);
int d=digitalRead(A0);
int se=digitalRead(servo_entrance);
int sx=digitalRead(servo_exit);
lcd.setCursor(0, 0);
lcd.print("Total remaining");
lcd.setCursor(0, 1);
lcd.print("parking slot: ");
Serial.println(a + "|" + b + "|" + c "|" + d);
digitalWrite(2,a);
digitalWrite(3,!a);
digitalWrite(4,b);
digitalWrite(5,!b);
digitalWrite(6,c);
digitalWrite(7,!c);
digitalWrite(8,d);
digitalWrite(9,!d);
int total = a + b + c + d;
int slot = 4 - total;
if (total==4){
lcd.setCursor(14, 1);
lcd.print("0");
}
else{
if (se == 1 && sx ==1){
myservo.write(0);
}
if(se == 0 && sx == 0){
myservo.write(90);
}
lcd.setCursor(14, 1);
lcd.print(slot);
}
delay(500);
}
What arduino?
Ah, now I notice you're using Serial.println(); instead of bluetooth.println(); And you're probably initializing the software serial port on the pins where the hardware serial port is.