Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino - car parking lot using arduino- program logical doubt

Status
Not open for further replies.

geo_18

Newbie level 5
Newbie level 5
Joined
Sep 22, 2013
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
59
This program is just to control a car parking lot using ping sensors and servo motor.
Servo motor acts as the gate. Here when the first ping sensor detects the car the gate opens and when the car crosses the second ping sensor the gate closes and correspondingly the number of parking lots left are shown on a lcd screen. That is how the program is programmed. But now i have encountered a situation where the car cuts the first ping sensor and the gate opens, but the car decides not to enter the parking lot and goes back. So I want my gate to close. Could anyone suggest me the correct logical modification to this program to handle such a situation.

This is the program :

#include<Servo.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int pingPinTRI1 = 7;
int pingPinECHO1 = 8;
int pingPinTRI2 = 9;
int pingPinECHO2 = 10;
Servo myservo;
Servo myservo1;
Servo myservo2;
int avlb=15;

void setup()
{
myservo.attach(6);
myservo1.attach(9);
myservo2.attach(7);
pinMode(pingPinTRI1, OUTPUT);
pinMode(pingPinECHO1, INPUT);
pinMode(pingPinTRI2, OUTPUT);
pinMode(pingPinECHO2, INPUT);
lcd.begin(16,2);
Serial.begin(9600);
}



void loop()
{
display(avlb);
long duration1, cm1 , duration2 , cm2 ;

digitalWrite(pingPinTRI1, LOW);
delayMicroseconds(2);
digitalWrite(pingPinTRI1, HIGH);
delayMicroseconds(5);
digitalWrite(pingPinTRI1, LOW);
digitalWrite(pingPinTRI2, LOW);
delayMicroseconds(2);
digitalWrite(pingPinTRI2, HIGH);
delayMicroseconds(5);
digitalWrite(pingPinTRI2, LOW);

duration1=pulseIn(pingPinECHO1, HIGH);
cm1=microsecondsToCentimeters(duration1);

if(cm1>1 && cm1<5)
{
if(avlb!=0)
{
myservo.write(177);
myservo1.write(177);
jump1:
duration2=pulseIn(pingPinECHO2, HIGH);
cm2=microsecondsToCentimeters(duration2);
if(cm2>1 && cm2<5)
{
myservo.write(110);
avlb--;
display(avlb);
}
else
{
goto jump1;
}
}
delay(5000);
}

duration2=pulseIn(pingPinECHO2, HIGH);
cm2=microsecondsToCentimeters(duration2);

if(cm2>1 && cm2<5)
{
if(avlb!=15)
{
myservo.write(177);
myservo2.write(177);
jump2:
duration1=pulseIn(pingPinECHO1, HIGH);
cm1=microsecondsToCentimeters(duration1);
if(cm1>1 && cm1<5)
{
myservo.write(110);
avlb++;
display(avlb);
}
else
{
goto jump2;
}
delay(5000);
}
}
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

void display(int lots)
{
lcd.print("no.of lots ");
lcd.setCursor(0,1);
lcd.print("available : ");
lcd.print(lots);
}
 

It sounds like you need to have 4 sensor conditions:Condtion 0: Neither sensor active. Condition 1: in front of gate(sensor 1 active). Condition 2: past gate(sensor 1 and sensor 2 both active). Wait. Condition 3: Moved forward(sensor 2 only active).

The states would be something like:

State 1: (Idle state)
Close Gate
If Condition 1==> State 2
State 2:
Open gate
If Condition 2 ==> State 3
Elsif Condition 1==> State 4
State 3:
Close Gate
If Condition 4==> State 1
State 4:
If Condition 0 ==> State 1


Something like that...
 
Last edited:

Actually I did not get the solution properly. Could you be more specific.
Anyway I am really thankful for your reply.
 

I thought I was pretty specific.

Ok, you've got 4 possible states of the car's position
1: Not there (no sensor activated)
2: In front of the gate (Only sensor 1 active)
3: Past the gate, but not past the 2nd sensor (both sensors active)
4: Passing the 2nd sensor. (only the 2nd sensor active)

In state 1 you can move to state 2 if sensor 1 is detected. Gate is closed.
In state 2 you can move to either state 3 (both sensors active) or state 1 (no sensor active). Car is in front of gate. Gate is opened.
In state 3 you can move to state 4 if only sensor 2 is active; state 2 if only sensor 1 is active. Car has moved forward past gate.
In state 4 you can move to state 0 when no sensors are active. Car has moved farther beyond gate.

Hope that helps.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top