Simple Smart Fan using PHPoC Blue

Simple Smart Fan using PHPoC Blue

Postby Roy » Fri Nov 20, 2015 5:40 pm

[Subject]
smart fan stopping movement when it detects an object
Image

[Board]
a.PHPoC Blue (P4S-342)
b. bread board extend board for PHPoC Blue
Image

[Sensor/Module]
a. servo motor: RB-65PG with pan tilt component
Image

b. ultrasonic sensor: HC-SR04
Image

c. fan motor: Keyes 111330 fan motor
Image

[Connection]
a. PHPoC Blue - Servo Motor
Image

b. PHPoC Blue - Ultrasonic Sensor
Image

c. PHPoC Blue - Fan Motor
Image

[Description]
a. automatic stand alone operation
b. continuously moves the body unless there is no object by servo motor
c. try to detects objects regardless of movement
d. fan motor keeps running
e. stops movement about one second if it detects an object
f. after one second, it moves again


[Video]

phpBB [video]



[Source Code - task0.php]

Code: Select all

<?php
 
// define constants
define("WIDTH_MIN", 700);
define("WIDTH_MAX", 2300);
 
// define variables
$pid_ht0 = 0;
$pid_ht1 = 0;
$pid_ht3 = 0;
$dir_flag = 0;
$width = WIDTH_MIN;
 
// start fan function
function run_fan()
{
    $pid = pid_open("/mmap/uio0");
    pid_ioctl($pid, "set 0-1 mode out low");
    pid_ioctl($pid, "set 0 output low");
    pid_ioctl($pid, "set 1 output high");
    pid_close($pid);
}
 
// control servo motor function
function init_ht3()
{
    global $pid_ht3;
    $pid_ht3 = pid_open("/mmap/ht3");
    pid_ioctl($pid_ht3, "set div us");
    pid_ioctl($pid_ht3, "set mode output pwm");
    pid_ioctl($pid_ht3, "set count 1500 20000");
}
 
// output trigger pulse function
function send_trigger()
{
    global $pid_ht0;
    $pid_ht0 = pid_open("/mmap/ht0");
    pid_ioctl($pid_ht0, "set div us");
    pid_ioctl($pid_ht0, "set mode output pulse");
    pid_ioctl($pid_ht0, "set count 5 5");
    pid_ioctl($pid_ht0, "set repc 1");
    pid_ioctl($pid_ht0, "start");
    while(pid_ioctl($pid_ht0, "get state"))
        ;
    pid_close($pid_ht0);
}
 
// capture sensor response function
function start_capture()
{
    global $pid_ht1;
    $pid_ht1 = pid_open("/mmap/ht1");
    pid_ioctl($pid_ht1, "set div us");
    pid_ioctl($pid_ht1, "set mode capture fall");
    pid_ioctl($pid_ht1, "set trigger from pin rise");
    pid_ioctl($pid_ht1, "set repc 1");
    pid_ioctl($pid_ht1, "start");
    send_trigger();
    usleep(30000);
}
 
// detect distance function
function detect()
{
    global $pid_ht0;
    global $pid_ht1;
 
    start_capture
();
    $state = pid_ioctl($pid_ht1, "get state");
 
    if
($state != 0)
    {
        pid_ioctl($pid_ht1, "stop");
        $distance = -1;
    }
    else
    
{
        $duration = pid_ioctl($pid_ht1, "get count 0");
        $distance = (331.5 + 0.60714 * 25) * ($duration / 2) / 10000;
    }
    pid_close($pid_ht1);
    return $distance;
}
 
// init servo motor and fun fan motor
init_ht3();
pid_ioctl($pid_ht3, "start");
run_fan();
 
// start main loop
while(1)
{
    pid_ioctl($pid_ht3, "set count $width 20000");
 
    if
($width <= WIDTH_MIN)
        $dir_flag = 1;
    elseif($width >= WIDTH_MAX)
        $dir_flag = 2;
 
    if
($dir_flag == 0)
    {
        while(1)
        {
            $dir_flag = rand(1, 2);
            if($dir_flag != 0)
                break;
        }
        sleep(1);
    }
    elseif($dir_flag == 2)
        $width -= 50;
    else
        $width 
+= 50;
 
    $distance 
= detect();
 
    if
(($distance > 3) &amp;&amp; ($distance < 25))
        $dir_flag = 0;
}
 
?>
Last edited by Roy on Fri Feb 19, 2016 2:46 pm, edited 4 times in total.
Roy
 
Posts: 8
Joined: Fri Mar 14, 2014 10:49 am

Re: Simple Smart Fan using P4S-342

Postby DavidKwon » Fri Nov 20, 2015 6:03 pm

Wall-E ? :lol:
DavidKwon
 
Posts: 3
Joined: Fri Jul 31, 2015 4:26 pm


Return to Project

Who is online

Users browsing this forum: No registered users and 1 guest

cron