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

Web-Based Internet Signboard
Easy
  • 178
  • 5

Full instructions

Build a web-based Internet Signboard with PHPoC.

Monitoring the Trash Can
Easy
  • 260
  • 7

Full instructions

Status of trash can in public area is monitored. When the trash can is full, an email is sent to trash manager or status of trash can.

Temperature Sensor
Easy
  • 450
  • 5

Full instructions

A photon that measures the temperature and humididty with a DHT 22 sensor and communicates the temperature data to another photon.

Alcohol Gas Detector
Easy
  • 210
  • 9

Full instructions

I made a simple project called "Alcohol Gas Detector".

MQTT for IoT Devices, Support TLS/SSL, QoS Level: 0, 1, 2
Easy
  • 216
  • 7

Protip

This project describes MQTT library for an IoT Platfrom so-called PHPoC. This library supports MQTT over TLS/SSL and all QoS Level: 0, 1, 2.

Car Blinker
Easy
  • 264
  • 4

Protip

Blink for Vehicles, such as bikes and skates. Easy.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback