srlee
Published © GPL3+

Alcohol Gas Detector

I made a simple project that detects the gaseous presence of alcohol.

BeginnerShowcase (no instructions)5 hours1,071
Alcohol Gas Detector

Things used in this project

Hardware components

PHPoC Blue
PHPoC Blue
×1
MQ3 (Alcohol gas sensor)
×1
Buzzer
Buzzer
×1
Relay (generic)
×1
LED (generic)
LED (generic)
To serve as a warning light
×1

Story

Read more

Schematics

[Connection]

[P4S-342] ----------[MQ3]
GND ---------- G
PWR5 -------- V
AD0 ---------- S

[P4S-342] ---------- [Buzzer]
3.3V ---------- VCC
GND ---------- GND
HT1 ---------- SIG

[P4S-342] ---------- [Relay module]
PWR5 ---------- 5V
GND ---------- GND
NSS/0 ---------- IN

Code

task0.php

PHP
task0.php
<?php
 
include "/lib/sd_340.php";
$pid = pid_open("/mmap/adc0");
$uio = pid_open("/mmap/uio0");
pid_ioctl($uio, "set 0 mode out");
 
function pwm_buzzer($time)
{
    if($time == 0)
    {
        while(ht_ioctl(1, "get state"))
        ht_ioctl(1, "stop");
        
        ht_ioctl(1, "set div ms"); 
        ht_ioctl(1, "set mode output pwm"); 
        ht_ioctl(1, "set count 0 10000"); 
    }
    else
    {
        ht_ioctl(1, "stop");    
        ht_ioctl(1, "set div ms"); 
        ht_ioctl(1, "set mode output pwm"); 
        ht_ioctl(1, "set count $time $time"); 
        ht_ioctl(1, "start"); 
    }
}
 
$add = 0;
$adc_val = 0;
pid_write($uio, 0x00);
 
while(1)
{
    for($i = 0; $i < 10; $i++)
    {
        pid_read($pid, $adc_val); 
        $add += $adc_val;
    }
    $avr = $add / 10;
    $real = (($avr / 4095.0) * 3.3) ;
    printf("level : %.2f\r\n\r\n", $real);
    $buzzer = (int)round ((1.0 / $avr) * 100000);
    
    if($real <= 0.7)
    {
        pwm_buzzer(0);
        pid_write($uio, 0x00);
    }
    else
    {
        pid_write($uio, 0x01);
        pwm_buzzer($buzzer);
    }
    $add = 0;
sleep(1);
}
?>

Credits

srlee

srlee

3 projects • 4 followers

Comments