Things used in this project

Hardware components:
Phpoc blue per 100x1000 euk22wtv9i
PHPoC Blue
×1
Relay (generic)
×1
12V LED Light
×1
SparkFun Sound Detector (SEN-12642)
×1

Schematics

Connecting to PHPoC Blue
[Sound detecting sensor] ---- [PHPoC Blue]
ENVELOPE ---- AD0
GATE ---- NSS/0
GND ---- GND
VCC ---- 3.3V

[Relay] ---- [PHPoC Blue]
IN ---- SCK/1
GND ---- GND
5V ---- PWR5
Sound detect bb jlpxasf2ao

Code

2. Clap once for On, Clap twice for OffPHP
It recognizes the number of noises within 500ms.
<?php
include_once "/lib/sd_340.php";
adc_setup(0, 0);
uio_setup(0, 0, "in");
uio_setup(0, 1, "out");
uio_out(0, 1, LOW); 
st_free_setup(0);
 
define("FINAL_DETECTED",    0);
define("CLAP_NOT_DETECTED",   1);
define("TIMEOUT",   2);
 
$start_time = 0;
 
function indicate_clap($clap_num)
{
    if($clap_num == 2) //2 clap
        uio_out(0, 1, LOW); 
 
    else if($clap_num == 1) //1 clap
        uio_out(0, 1, HIGH);    
    
    usleep(100000);
}
 
function detect_claps($clap_num)
{    
    global $start_time;
    
    if($clap_num == 2)  // 2 clap -> off
    {
        indicate_clap($clap_num);
 
        return FINAL_DETECTED;
    }
    
    $uio_in = uio_in(0, 0);    
    $adc_in = adc_in(0, 100);
    
    indicate_clap($clap_num); //no clap
        
    if($adc_in > 600 && $uio_in == 1) //clap detect
    {
        $start_time = st_free_get_count(0);
        $current_time = st_free_get_count(0);
    
        while(1)
        {
            if($current_time - $start_time < 500)
            {    
                $current_time = st_free_get_count(0);
                $clap_state = detect_claps($clap_num + 1);   
 
                if($clap_state == FINAL_DETECTED)
                    return $clap_state;
            }
            else 
                return TIMEOUT;            
        }    
    }
    
    return CLAP_NOT_DETECTED;
}
 
while(1)
{            
    $clap_state = detect_claps(0);
    
      if($clap_state == FINAL_DETECTED)
        indicate_clap(0);
 
    usleep(10000);          
}
?>
1. On/Off TogglePHP
<?php
include_once "/lib/sd_340.php";
adc_setup(0, 0);
uio_setup(0, 0, "in");
uio_setup(0, 1, "out");
uio_out(0, 1, LOW);
function control_led()
{
    uio_out(0, 1, TOGGLE);    
    usleep(100000);
}
while(1)
{        
    $uio_in = uio_in(0, 0);    //GATE 
    $adc_in = adc_in(0, 100); //ENVELOPE 
    
    if($adc_in > 600 && $uio_in == 1)
        control_led();
        
    usleep(10000);  
}
?>

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Controlling Stepper Motor Precisely via Web
Easy
  • 192
  • 8

This project shows how to control the step motor precisely using micro-stepping method via Web.

Mask with Blinking Eye
Easy
  • 62
  • 3

Protip

Makes a great mask more eye-catching when one eye is blinking. Has an on-off switch, is powered by a cell , and driven by an ATtiny85.

PHPoC - Detect Someone Taking Your Stuff
Easy
  • 605
  • 14

When your stuff is being taken away by a thief, PHPoC makes an alert and sends a notification to you via Gmail.

PHPoC - Web-Based Two-Player Game
Easy
  • 253
  • 8

Have fun with a colleague during break time with this web-based game.

Safe City: A Device to Keep You Safe
Easy
  • 770
  • 8

Full instructions

The device will keep you safe. Just have to click a button and your precise location will be shared.

Scavenger Hunt Clues w/ Telephone Keypad
Easy
  • 990
  • 4

Full instructions

Type the correct code on the phone's keypad to hear the clue through the handset, then decode the message to finish before the other team.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog