Shahariar
Published © GPL3+

PSoC 4: Natural Gas Leakage Alarm System for Kitchen Safety

An analog heavy system that detects leakage of NG (Methane) from stoves, gas cylinder tubes inside kitchen and generates audiovisual alerts.

EasyFull instructions provided4 hours1,272
PSoC 4: Natural Gas Leakage Alarm System for Kitchen Safety

Things used in this project

Hardware components

PSoC 4 Prototyping Kit
Cypress PSoC 4 Prototyping Kit
×1
RGY Segment LED Bar/Dash Display
×1
Seeed Grove Gas Sensor MQ5
×1
SparkFun Piezo
×1

Software apps and online services

PSoC Creator
Cypress PSoC Creator

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Seeed BreadBoard
Seeed Jumper wire

Story

Read more

Schematics

PSoC Internal & External Sch

Sxhqbju4bgbj2cyidi4l

Code

C Code

C/C++
/* ========================================
 *
 * Copyright YOUR COMPANY, THE YEAR
 * All Rights Reserved
 * UNPUBLISHED, LICENSED SOFTWARE.
 *
 * CONFIDENTIAL AND PROPRIETARY INFORMATION
 * WHICH IS THE PROPERTY OF your company.
 *
 * ========================================
*/
#include <project.h>

int Val=0;
int slope=0;
// Fn Def
void Level_7(void);
void Level_6(void);
void Level_5(void);
void Level_4(void);
void Level_3(void);
void Level_2(void);
void Level_1(void);
void Level_Off(void);


int main()
{
uint16_t gaslevel=0;
int i;
    ADC_Start();
    Opamp_Start();
    IDAC_Start();
    
    //// DONT FORGET TO START EVERY HARDWaaaaaaa //
    
    
ADC_StartConvert();
IDAC_Start();
for(i=0;i<10;i++)
{
Level_7();
CyDelay(200);
Level_Off();
CyDelay(200);
}
    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
    for(;;)
    {
        /* Place your application code here. */
while(ADC_IsEndConversion(ADC_RETURN_STATUS)){}
gaslevel=ADC_GetResult16(0);


if (gaslevel>0&&gaslevel<600)
{   Level_1();}
else if (gaslevel>=600&&gaslevel<900)
{   Level_2();}
else if (gaslevel>=900&&gaslevel<1200)
{   Level_3();}
else if (gaslevel>=1200&&gaslevel<1800)
{   Level_4();}
else if (gaslevel>=1800&&gaslevel<2400)
{   Level_5();
IDAC_SetValue(Val);Val=Val+15;if(Val>255){Val=0;}
}
else if (gaslevel>=2400&&gaslevel<3000)
{   Level_6();
IDAC_SetValue(Val);Val=Val+20;if(Val>255){Val=0;}
}
else if(gaslevel>3000)
{   Level_7();
IDAC_SetValue(Val);Val=Val+25;if(Val>255){Val=0;}
}
    
}
}
///////////////////////////////////////////
///////////////////////////////////////////
// ROUTINES //

void Level_7(void)
{
  //  CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(0);
LED_G3_Write(0);
LED_Y1_Write(0);
LED_Y2_Write(0);
LED_R1_Write(0);
LED_R2_Write(0);
   // CyDelay(1); 
}


void Level_6(void)
{
   //  CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(0);
LED_G3_Write(0);
LED_Y1_Write(0);
LED_Y2_Write(0);
LED_R1_Write(0);
LED_R2_Write(1);
   //  CyDelay(1);
}


void Level_5(void)
{
     CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(0);
LED_G3_Write(0);
LED_Y1_Write(0);
LED_Y2_Write(0);
LED_R1_Write(1);
LED_R2_Write(1);
     CyDelay(1);
}

void Level_4(void)
{
     CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(0);
LED_G3_Write(0);
LED_Y1_Write(0);
LED_Y2_Write(1);
LED_R1_Write(1);
LED_R2_Write(1);
 CyDelay(1);   

}


void Level_3(void)
{
     CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(0);
LED_G3_Write(0);
LED_Y1_Write(1);
LED_Y2_Write(1);
LED_R1_Write(1);
LED_R2_Write(1);
     CyDelay(1);
}

void Level_2(void)
{
     CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(0);
LED_G3_Write(1);
LED_Y1_Write(1);
LED_Y2_Write(1);
LED_R1_Write(1);
LED_R2_Write(1);
     CyDelay(1);
}

void Level_1(void)
{
     CyDelay(1);
LED_G1_Write(0);
LED_G2_Write(1);
LED_G3_Write(1);
LED_Y1_Write(1);
LED_Y2_Write(1);
LED_R1_Write(1);
LED_R2_Write(1);
     CyDelay(1);
}
void Level_Off(void)
{
     CyDelay(100);
LED_G1_Write(1);
LED_G2_Write(1);
LED_G3_Write(1);
LED_Y1_Write(1);
LED_Y2_Write(1);
LED_R1_Write(1);
LED_R2_Write(1);
 CyDelay(100);
    
}
    

/* [] END OF FILE */

PSoC Files

C/C++
No preview (download only).

Credits

Shahariar

Shahariar

27 projects • 94 followers
Tired of Life, Sick of Death! Torn by Failure, Worn by Faith! Effed by Time & Lost my Mind! 'Coz I'm Idiot, One of a Kind! ____Fake Engineer

Comments