[Subject]

Parking System


a. PHPoC Blue measures the distance from the top to the bottom using an Ultrasonic sensor. [HT0~3]
b. When a car approaches the parking lot, the LED color is changed. [UIO0~3]


Here are the items I used.

[Item]

- PHPoC Blue (P4S-342)

- Ultrasonic sensor X 2



- Bi-color LED (Green, Red) x 2

Click image for larger version

Name:	3.jpg
Views:	164
Size:	17.2 KB
ID:	102


- Lego(Parking lot model, Car model)







[Connection]
Click image for larger version

Name:	Parking system.jpg
Views:	76
Size:	120.3 KB
ID:	103


[PHPoC Blue] ----------[Ultrasonic Ranger 1]
PWR5 ---------- VCC
HT0 ---------- Trig
HT1 ---------- Echo
GND ---------- Gnd

[PHPoC Blue] ----------[Ultrasonic Ranger 2]
PWR5 ---------- VCC
HT2 ---------- Trig
HT3 ---------- Echo
GND ---------- Gnd

[PHPoC Blue] ---------- [Bi-color LED 1]
NSS/0 ---------- RED
GND ---------- GND
SCK/1 ---------- GREEN

[PHPoC Blue] ---------- [Bi-color LED 2]
MISO/2 ---------- RED
GND ---------- GND
MOSI/3 ---------- GREEN






[Source Code]

PHP Code:

<?php

include_once "/lib/sd_340.php";

$uio pid_open("/mmap/uio0");
pid_ioctl($uio"set 0 mode out");
pid_ioctl($uio"set 1 mode out");
pid_ioctl($uio"set 2 mode out");
pid_ioctl($uio"set 3 mode out");

// setup trigger pulse timer
// setup echo capture timer
ht_ioctl(0"set mode output pulse");
ht_ioctl(0"set div us");
ht_ioctl(0"set repc 1");
ht_ioctl(0"set count 5 10"); // 10us pulse width
ht_ioctl(1"reset");
ht_ioctl(1"set div us");
ht_ioctl(1"set mode capture toggle");
ht_ioctl(1"set trigger from pin rise");
ht_ioctl(1"set repc 4");

ht_ioctl(2"set mode output pulse");
ht_ioctl(2"set div us");
ht_ioctl(2"set repc 1");
ht_ioctl(2"set count 5 10");
ht_ioctl(3"reset");
ht_ioctl(3"set div us");
ht_ioctl(3"set mode capture toggle");
ht_ioctl(3"set trigger from pin rise");
ht_ioctl(3"set repc 4");

while(
1)
{
    
ht_ioctl(1"start"); // we should start capture timer first
    
ht_ioctl(0"start"); // start trigger pulse
    
ht_ioctl(3"start");
    
ht_ioctl(2"start");

    
usleep(100000);

    
// 1st capture value ("get count 0") is always zero. 2nd capture value;
    
$us1 ht_ioctl(1"get count 1");
    
$us2 ht_ioctl(3"get count 1");

    
$dist1 $us1 340.0 2// us to meter conversion
    
$dist1 $dist1 10000// meter to centimeter conversion
    
$dist2 $us2 340.0 2;
    
$dist2 $dist2 10000;

    echo 
"D1 = $dist1 [cm]\r\n";
    echo 
"D2 = $dist2 [cm]\r\n\r\n";

    
$level16.0;

    if ((
$dist2 $level) && ($dist1 $level) )
    {
        
pid_write($uio0x05);
    }
    else if ((
$dist2 $level) && ($dist1 >= $level))
    {
        
pid_write($uio0x09);
    }
    else if((
$dist2 >= $level) && ($dist1 $level))
    {
        
pid_write($uio0x06);
    }
    else if((
$dist2 >= $level) && ($dist1 >= $level))
    {
        
pid_write($uio0x0a);
    }
}

?>




[video]