#include <LiquidCrystal_I2C.h>
//BASIC CONNECTIONS
#define sensor 0
#define en1 13
#define en2 12
#define en3 11
#define en4 10
#define nyuma 9
#define mbele 8
#define buzzer A1
LiquidCrystal_I2C lcd(0x27,16,2);
bool state;
void setup()
{
lcd.init();
lcd.backlight();
loadingdisplay();
Serial.begin(115200);
pinMode(nyuma,INPUT);
pinMode(mbele,INPUT);
pinMode(en1,OUTPUT);
pinMode(en2,OUTPUT);
pinMode(en3,OUTPUT);
pinMode(en4,OUTPUT);
pinMode(buzzer,OUTPUT);
lcd.clear();
}
void loadingdisplay()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("VEHICLE STARTED");
lcd.setCursor(0,1);
lcd.print("WARMING UP.....");
delay(2000);
}
void homedisplay()
{
lcd.setCursor(0,0);
lcd.print("SAFE TO DRIVE");
}
void alertdisplay()
{
lcd.setCursor(0,0);
lcd.print("--->!ALEART!<---");
lcd.setCursor(0,1);
lcd.print("ALCOHOL DETECTED");
}
void loop()
{
while(analogRead(0)<500)
{
digitalWrite(A1,LOW);
if(digitalRead(mbele)==LOW)
{
lcd.setCursor(0,0);
lcd.print("VEHICLE ENABLED ");
lcd.setCursor(0,1);
lcd.print("--->REVERSE <---");
move(2);
}
else if(digitalRead(nyuma)==LOW)
{
lcd.setCursor(0,0);
lcd.print("VEHICLE ENABLED ");
lcd.setCursor(0,1);
lcd.print("--->FORWARD<----");
move(1);
}
else
{
lcd.setCursor(0,0);
lcd.print("VEHICLE ENABLED ");
lcd.setCursor(0,1);
lcd.print("--->NEUTRAL<----");
move(3);
}
}
alertdisplay();
digitalWrite(A1,HIGH);
move(3);
}
void move(int num)
{
if(num==1){
digitalWrite(en1,HIGH);
digitalWrite(en2,LOW);
digitalWrite(en3,LOW);
digitalWrite(en4,HIGH);
}
if(num==3){
digitalWrite(en2,LOW);
digitalWrite(en1,LOW);
digitalWrite(en4,LOW);
digitalWrite(en3,LOW);
}
if(num==2){
digitalWrite(en1,LOW);
digitalWrite(en2,HIGH);
digitalWrite(en3,HIGH);
digitalWrite(en4,LOW);
}
}