srlee
Published © GPL3+

Parking System

I made a simple project called "smart car parking system."

BeginnerShowcase (no instructions)5 hours1,617
Parking System

Things used in this project

Hardware components

PHPoC Blue
PHPoC Blue
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
bi-color led(Green-Red)
×2

Story

Read more

Schematics

Connection

[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

Code

task0.php

PHP
task0.php
<?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";
 
    $level= 16.0;
 
    if (($dist2 < $level) && ($dist1 < $level) )
    {
        pid_write($uio, 0x05);
    }
    else if (($dist2 < $level) && ($dist1 >= $level))
    {
        pid_write($uio, 0x09); 
    }
    else if(($dist2 >= $level) && ($dist1 < $level))
    {
        pid_write($uio, 0x06); 
    }
    else if(($dist2 >= $level) && ($dist1 >= $level))
    {
        pid_write($uio, 0x0a);
    }
}
 
?>

Credits

srlee

srlee

3 projects • 4 followers

Comments