ashishpandey:
#include <LiquidCrystal.h>
#include <Servo.h>
// Servo Motor
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
// LCD
int contrast=100;
const int rs=12,en=11,d4=5,d5=4,d6=3,d7=2;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
//IR sensor
int isObstacle1Pin=22;
int isObstacle2Pin=24;
int isObstacle3Pin=26;
int isObstacle4Pin=28;
int isObstacle5Pin=30;
int isObstacle1=0;
int isObstacle2=0;
int isObstacle3=0;
int isObstacle4=0;
int isObstacle5=0;
// Control time for Servo
unsigned long ServoStartTime;
const unsigned long ServoOnTime=3000;
// Slots
int count=0;
int i;
byte val[3];
const int place[3]={26,28,30};
void setup()
{
pinMode(isObstacle1Pin,INPUT_PULLUP);
pinMode(isObstacle2Pin,INPUT_PULLUP);
myservo.attach(9);
Serial.begin(9600);
Serial.println("---------------------------------------------");
Serial.println(" Welcome to Smart Car Parking System");
Serial.println("---------------------------------------------");
analogWrite(A0,contrast);
lcd.begin(16,2);
lcd.setCursor(0,0);
}
void loop()
{
isObstacle1 = digitalRead(isObstacle1Pin);
isObstacle2 = digitalRead(isObstacle2Pin);
isObstacle3 = digitalRead(isObstacle3Pin);
isObstacle4 = digitalRead(isObstacle4Pin);
isObstacle5 = digitalRead(isObstacle5Pin);
lcd.setCursor(0,0);
lcd.print("Hello");
// For checking slots
Serial.println("Booked Slots");
for(i=0;i<=2;i++)
{
val[i]=digitalRead(place[i]);
if(val[i]==1)
{
Serial.println(i+1);
Serial.println();
}
}
// For Entry Gate
if(isObstacle1 == HIGH)
{
if(isObstacle3 && isObstacle4 && isObstacle5)
{
myservo.write(90);
}
else
{
ServoStartTime = millis();
Serial.println("Entry gate opening");
// lcd.setCurso(0,1)
// lcd.print("Entry gate opening
for (pos = 90; pos <= 180; pos += 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
while(isObstacle1 == HIGH)
{
isObstacle1 = digitalRead(isObstacle1Pin);
}
delay(3000);
Serial.println("Please hold on gate is closing");
for (pos = 180; pos >= 90; pos -= 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Serial.println("Entry gate closed");
Serial.println();
}
}
// For Exit Gate
else if(isObstacle2 == HIGH)
{
ServoStartTime = millis();
Serial.println("Exit gate opening");
for (pos = 90; pos <= 180; pos += 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
while(isObstacle2 == HIGH)
{
isObstacle2 = digitalRead(isObstacle2Pin);
}
delay(3000);
Serial.println("Please hold on gate is closing");
for (pos = 180; pos >= 90; pos -= 1)
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Serial.println("Exit gate closed");
Serial.println();
}
}
tl;dr (hint)