Just fix the errors
#define POT A0
#define TRIG 23
#define ECHO 24
#define UServo 22
#define LM_EN 2
#define LM_IN1 3
#define LM_IN2 4
#define RM_IN1 5
#define RM_IN2 6
#define RM_EN 7
#define IR_R2 30
#define IR_R1 31
#define IR_M 32
#define IR_L1 33
#define IR_L2 34
#define SW1 52
#define SW2 53
#include
Servo US_servo;
#include
#include
LiquidCrystal_I2C lcd (0x27,16,2);
byte OUTPINS[] = {LM_EN, LM_IN1, LM_IN2, RM_EN, RM_IN1, RM_IN2, TRIG};
byte INPINS[] = {IR_L2, IR_L1,IR_M, IR_R1, IR_R2,ECHO, SW1,SW2};
void setup()
{
for (int i = 0; i < sizeof(OUTPINS); i++) pinMode(OUTPINS[i], OUTPUT);
for (int i = 0; i < sizeof(INPINS); i++) pinMode(INPINS[i], INPUT);
US_servo.attach(UServo);
US_servo.write(90);
delay(100);
lcd.init();
lcd.backlight();
Serial.begin(9600);
Serial1.begin(9600);
lcd.setCursor(0,0);
lcd.print(" SPEEDY 004");
lcd.setCursor(0,1);
lcd.print(" SPEEDY XXX");
delay(2000);
}
int dist, ldist, rdist;
byte spd;char BT_cmd;
boolean sL2,sL1,sM,sR1,sR2,swlVal, sw2Val;
void loop()
{
sw1val = digitalRead(SW1);
sw2Val = digitalRead(SW2);
if (!sw1Val && !sw2Val) // 00 BT Control
{
lcd.setCursor(0, 1);
lcd.print(" BT Control ");
BT_control();
}
else if (!sw1Val && sw2Val) // 01 Direction Finder
{
lcd.setCursor(0, 1);
lcd.print(" Direction Finder ");
line_follower();
}
else if (sw1Val && !sw2Val) // 10 Line Finder
{
lcd.setCursor(0, 1);
lcd.print(" Line Finder ");
BT_control();
}
else if (sw1Val && !sw2Val)
{
lcd.setCursor(0, 1);
lcd.print(" Line Follower ");
line_follower();
}
else if (sw1Val && !sw2Val)
{
lcd.setCursor(0, 1);
lcd.print(" Direction Finder ");
line_finder();
}
else // 11
{
lcd.setCursor(0, 1);
lcd.print(" Line Follower ");
line_follower();
}
else if (sw1Val && !sw2Val)
{
lcd.setCursor(0, 1);
lcd.print(" Direction Finder ");
direction_finder();
}
lcd.setCursor(0, 1);
lcd.print(" Line Follower ");
line_follower();
}
void line_follower()
{
sL2 = digitalRead(IR_L2);
sL1 = digitalRead(IR_L1);
sM = digitalRead(IR_M);
sR1 = digitalRead(IR_R1);
sR2 = digitalRead(IR_R2);
// Move Back
if (!sL2 && !sL1 && !sM && !sR1 && !sR2) // 00000
{
serial.println ("moving ahead")
Car_control(LOW, 255, LOW, 255); // moving back slowly
}
else if ((sL2 || sL1 && !sM && !sR1 && sR2) // 00001
{
serial.println ("moving right")
Car_control(LOW, 255, LOW, 100); // moving back slowly
}
else if (!sL2 && !sL1 && !sM && sR1 || !sR2) // 00010
{
serial.println ("moving left")
Car_control(LOW, 100, LOW, 255); // moving back slowly
}
if (sL2 && sL1 && sM && sR1 && sR2) // 00011
{
serial.println ("u turn")
Car_control(LOW, 255, HIGH, 255); // moving back slowly
}
}
void BT_control()
{
if(Serial1.available))
{
BT_cmd = Serial.read();
}
if (BT_cmd == 'F' || BT_cmd == 'f')
{
Car_control(LOW, 255, LOW, 255);
Serial.println("forward");
}
else if (BT_cmd == 'B' || BT_cmd == 'b')
{
Car_control(HIGH, 155, HIGH, 155);
Serial.println("revers");
}
else if (BT_cmd == 'R' || BT_cmd == 'r')
{
Car_control(LOW, 255, LOW, 55);
Serial.println("right");
}
else if (BT_cmd == 'L' || BT_cmd == 'l')
{
Car_control(LOW, 55, LOW, 255);
Serial.println("left");
}
else if (BT_cmd == 'S' || BT_cmd == 's')
{
Car_control(LOW, 0, LOW, 0);
Serial.println("stopped");
}
else if (BT_cmd == 'U' || BT_cmd == 'u')
{
Car_control(LOW, 255, HIGH, 255);
Serial.println("U turn");
}
}
void line_follower()
{
aL2 = digitalRead(IR_L2);
aL1 = digitalRead(IR_L1);
sM = digitalRead(IR_M);
sR1 = digitalRead(IR_R1);
sR2 = digitalRead(IR_R2);
Serial.print(sL2);
Serial.print("");
Serial.print(sL1);
Serial.print("");
Serial.print(sM);
Serial.print("");
Serial.print(sR1);
Serial.print("");
Serial.print(sR2);
if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("back slowly");
car_control(HIGH,100,HIGH,100);
}
else if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("turn right");
car_control(LOW,255,LOW,50);
}
else if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("straight");
car_control(LOW,255,LOW,255);
}
else if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("90 right");
car_control(LOW,255,HIGH,255);
delay(1000);
}
else if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("90 left");
car_control(HIGH,255,LOW,255);
delay(1000);
}
else if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("u turn");
car_control(LOW,255,HIGH,255);
delay(2000);
}
else if (!sL2 && !sL1 && !sM && !sR1 &&sR2)
{
Serial.println("turn left");
car_control(LOW,55,LOW,255);
}
}
void direction_finder()
{
US_servo.write(90);
delay(200);
dist = get_distance();
if (dist >= 100)
{
Car_control(LOW, 255, LOW, 255);
Serial.println(“forward”);
}
else if (dist > 20 && dist <100)
{
spd = map (dist,21,99,60,220);
Car_control(LOW, 255, LOW, 255);
Serial.println("forward");
}
else if (dist <=20)
{
Car_control(LOW, 0, LOW, 0);
US_servo.write(10);
delay(200);
rdist = get_distance();
US_servo.write(170);
delay(500);
ldist = get_distance();
US_servo.write(90);
delay(200);
if (ldist > rdist + 15)
{Serial.println(“lift”);
Car_control(HIGH, 255, LOW, 255);
delay(1000);
}
else if (rdist > ldist + 15)
{Serial.println(“right”);
Car_control(LOW, 255, HIGH, 255);
delay(1000);
}
else if (abs(ldist – rdist) < 10)
{Serial.println("u turn");
Car_control(HIGH, 255, LOW, 255);
delay(2000);
}
}
}
int get_distance()
{long int duration;
int cm;
digitalWrite(TRIG,LOW);
delayMicroseconds(2);
digitalWrite(TRIG,HIGH);
delayMicroseconds(5);
digitalWrite(TRIG,LOW);
duration = pulseIn(ECHO, HIGH);
cm = duration/58;
if (cm>150) cm =150;
if (cm<=5) cm = 5;
return cm;
}
void Car_control(boolean Ldir, byte Lspd, boolean Rdir, byte Rspd)
{
digitalWrite(LM_IN1, Ldir);
digitalWrite(LM_IN2, !Ldir);
digitalWrite(RM_IN1, Rdir);
digitalWrite(RM_IN2, !Rdir);
analogWrite(LM_EN, Lspd);
analogWrite(RM_EN, Rspd);
}
Place this order or similar order and get an amazing discount. USE Discount code “GET20” for 20% discount