Psoc 4: Natural Gas Leakage Alarm System For Kitchen Safety

About the project

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

Project info

Difficulty: Easy

Platforms: CypressSparkFun

Estimated time: 1 hour

License: GNU General Public License, version 3 or later (GPL3+)

Items used in this project

Hardware components

Sparkfun Capacitor Kit Sparkfun Capacitor Kit x 1
Ultrasonic Sensor Hc-sr04 Ultrasonic Sensor Hc-sr04 x 1
Pimoroni Micro Dot pHAT w/Red LEDs Pimoroni Micro Dot pHAT w/Red LEDs x 1
Tiny Breadboard Tiny Breadboard x 1
Jumper Wire Kit - 140pcs Jumper Wire Kit - 140pcs x 1

Software apps and online services

Cypress PSoC Creator Cypress PSoC Creator

Hand tools and fabrication machines

Seeed Jumper wire Seeed Jumper wire x 1
Soldering iron (generic) Soldering iron (generic) x 1

Story

About

This project is a downsized version of the original idea I submitted for Sensing the World contest. Unfortunately the idea was not selected. Anyway, I made a part of it to show respect to my own idea!

It's a system that monitors the environment of kitchen. Here, only natural gas leakage level monitoring and alarming is equipped. Gas leakage can happen from faulty gas cylinders, gas pipes, valves etc.

Think, somehow a turned on gas stove's fire is extinguished (could happen by air blow, cooking spillage), natural gas will start to accumulate inside the kitchen. If such a scenario is left for a prolonged period, an air-gas explosive mixture will be created. Now, someone lights up a fire, or somehow an electric spark happens from a device - BOOOOOOOOOOOOOM!

This basic system will alert the user, a further developed system (for commercial purpose) can shut-off gas flow, turn on ventilation fan, inform user over IoT link!

Flame of Abyss !

External Hardware

There are a few external hardware devices used in this project. The MQ 05 Gas Sensor (also available as Grove Module) which is sensitive to Natural Gas (Methane). Natural Gas is a commonly used stove fuel for kitchen. Anyway, there is a small electro-chemical heater inside MQ gas sensors which responds to certain types of gasses. If you use the non grove version of the sensor, a load resistor is required for adjusting sensor sensitivity/detection range. The sensor provides analog voltage as output: the higher the gas concentration, the higher is the voltage.

For displaying visual alert, there is a Red-Yellow-Green 7 dash LED bar display, which is a common anode display. It requires some external resistors to limit LED current. The alarm is generated with a high impedance piezoelectric speaker. Being high impedance makes it possible to drive with low current.

Of course there is the PSoC 4 CY8CKIT049 which breaks out the CY8C4245AXI-483 chip-32-bit PSoC ARM MCU.

K Safety

PSoC Internal Hardware

ADC, IDAC, OpAmp and some I/O pin components are utilized for this project.

12-bit ADC basically measures the Gas Sensor Analog Output. ADC range is from Ground to Rail (0V to 5V) with Vdd/2 as reference voltage, operated in unsigned, single ended mode gives full 4095 values measurable from sensor. With a pre-calibrated sensor Gas PPM levels may be possible to measure.

ADC Config where to change !

Setting Single ended mode on ADC

IDAC is used to create time varying voltage by passing through a external 10k load resistor which will make the IDAC to function like VDAC. It is possible to create sine/square/triangular/whim shaped voltage waves. Here, I created staircase-saw-tooth like voltage wave. IDAC must be configured as Source.

IDAC as Current Source

Internal OpAmp can drive load up to 10 mA. The OpAmp is operated voltage-follower-peizo-driver to generate sound signal. Opamp is configured in Power mode.

OpAmp as follower and Max mAmp drive to power piezo

There are 3 Analog and 7 Digital I/O pins used to interface with external devices. One Analog input interfaces with the Gas Sensor configured in High Impedance mode with initial state as low.

Hi Z analog Input to read sensor voltage

One of the other two Analog pins are used to interface with 10k Current to Voltage converter resistor configured in Strong Drive mode. The other Analog pin brings out the OpAmp Output to interface with piezoelectric speaker also configured as Strong Drive mode.

Analog Output for IDAC to VDAC

The 7 Digital pins are interfaced with the LED Bar Display configures as Output, Strong Drive. Since the Bar Display is Common Anode (+), so lowering the remaining pins will cause LED glow. This is done by these 7 Digital Outputs – which is software controlled.

Building the Project

The project is built on a breadboard. CY8CKIT is placed on the breadboard with the soldered male header pins. Breadboard jumper wires are used to make electrical connections with Display, Gas Sensor, Piezo. A USB Power Bank is used to power up the project.

Working Principle & Software

The working principle is super simple. Get sensor value > Show Gas Level > Buzz Alarm and the start over again.

Since I am too lazy when it comes to coding (bad habit grew from Arduino Usage-Delay/Polling/Code Space wasting/One Dimensional Thinking) and don’t like writing sleek C-Codes (let alone Assembly) that is full of interrupts, power saving, optimized, memory efficient and other stuff. The code is plain-which is kinda shame for a 32-bit ARM-PSoC MCU abused in the hand of a ignorant child. They could have probably gone to the Mars in 60’s if they had such computing power to control Apollo-11.

Anyway, first we start the Internal Hardware with Start APIs. Then we use the blocking ADC conversion and get sensor data. Then update Bar Display. If Gas concentration is too high, the IDAC value is set repeatedly with different values for each iteration of the infinite For-Loop. With the natural delays of APIs execution- I have managed to get a wave of around 4 kHz.

Analog Heavy!

I have used ADC, DAC, OpAmp to emphasize analog hardware components.

IDAC and OpAmp are used to create sound tone, which could alternatively done with PWM. PSoC 4 has limited Analog Resources. PSoC 5 is the right choice for developing such devices.

Live Action!

Here is a video of the system tested with Lighter Gas.

PSoC Kitchen Natural Gas Leakage Monitoring System

As you can see, when the gas is burning/fire is on, the sensor does not show gas level. Because when natural gas burns it creates CO2/H2O/Other Stuffs.

But when there is no fire and the Natural Gas/Methane is leaking, the sensor picks it up and the PSoC knows it through ADC. Next video shows the wave shape of the IDAC current wave converted to VDAC voltage wave, then buffered through OpAmp.

Wave on O'Scope

Schematics, diagrams and documents

PSoC Internal & External Sch

Code

PSoC Files

Download

C Code

Credits

Leave your feedback...