Gas/Smoke Detector, Alarm system with real-time leakage monitoring using Seeed Studio’s XIAO RP2040.

Gas/Smoke Detector, Alarm system with real-time leakage monitoring using Seeed Studio’s XIAO RP2040.

Introduction

Smoke detectors are very useful in the detection of smoke or fire in buildings, and so are the important parameters of safety. In this project, we will make a Gas\Smoke Detector Alarm System using Seeed XIAO RP2040. 

This System triggers the Siren and Flasher , whenever it detects smoke or fire nearby it.

Apart from this, We can also monitor the real time status of gas/smoke leakage in the onboard OLED Display.

In OLED Display we can monitor the following things.

1.Sensor Readings.

2.Status of Alarm, either it is ON or OFF.

3.Condition of Premises.

Two onboard Relays are also added in this system which we can use for different purposes.

I have used these relays for Siren and for warning flash light in case of fire.

So, Whenever Gas\Leakage detected onboard buzzer will start sounding also external Siren and warning flasher will activated.

This Smoke Detector Alarm circuit is designed using MQ-02 sensor and Seeed Studio’s XIAO RP2040 microcontroller.

Main part of this circuit is Gas sensor MQ-02 which is capable of detecting Smoke, LPG, Propane and HydrogenIt can be used in different types of applications where the smoke LPG, Propane and Hydrogen gas leak detection required.

This smoke detector Circuit is very good safety equipment , small and reliable, which can be easily install anywhere. We can give power to this smoke detector system in multiple ways, I have added terminal for battery as well as for DC adaptor.

So, Apart from AC main we can also give power supply from the battery as well as from 12volt power adaptor. In this way we can use any power terminal for powering up the system as per our convenient.

About XIAO RP2040.

Seeed Studio XIAO RP2040 is an Arduino Compatible microcontroller, based on the raspberry pi pico RP2040 chip. It carries the powerful dual core RP2040 Processor, that has a flexiable  clock running upto 133Mhz.

In addition to the powerful CPU, the Seeed Studio XIAO RP2040 has 264K SRAM and 2MB of Flash memory on board.

The Size of the board is very small, and is one of the world’s smallest RP2040 board.

Comparing the size & dimension with the Pi-Pico board, the Xiao RP2040 is lesser than half of the size of the Pico board, it can easily fit on a fingertip.

Seeed Studio XIAO RP2040 is compatible with the Raspberry Pi RP2040 ecosystem as they share the same RP2040 chip. It supports multiple languages including C / MicroPython / CircuitPython. 

Features

  • High Performance: Powered by Raspberry Pi 2040 chip, dual-core operating up to 133 MHz, equipped 264KB of SRAM, and 2MB of onboard flash memory.
  • Ultra-small Design: 21 x 17.5mm, Seeed Studio XIAO series classic form-factor, suitable for wearable devices.
  • Multiple Development Interfaces: 2x buttons, 11x digital / 4x analog pins, 1x I2C interface, 1x UART port, 1x SPI port, and 1x SWD Bonding pad interface.
  • Multiple Develop Platform: Support Arduino / Micropython / CircuitPython development, friendly for beginners, satisfied for electronics enthusiasts.
  • Perfect for Production: Breadboard-friendly & SMD design, no components on the back

PINOUTS

XIAO RP2040 is  rich in  I/O Pins, it has 11 digital pins, 4 analog pins, 11 PWM Pins among which one is  I2C interface, 1 UART interface, 1 SPI interface and 1 SWD Bonding pad interface pin.

And for power supply and flashing code XIAO RP2040 has USB-C Interface.

It has onboard reset and boot button and has different onboard LEDs for various purposes.


Attention

All the I/O pins are 3.3V, please do not input more than 3.3V, otherwise, the CPU may be damaged.

Hardware Connection:

  • Step 1. Press and hold the BOOT buttion and then connect the Seeed Studio XIAO RP2040 to the PC.

  • Step 2. If the “RPI-RP2” disk is shown on the PC and the Power LED on the Seeed Studio XIAO RP2040 is turned on, the connnection is complete

Software Setup

  • Step 1. Download and Install the latest version of Arduino IDE according to your operating system

  • Step 2. Launch the Arduino application.
  • Step 3. Open the Blink example by navigating “File → Examples —>01.Basics → Blink”
  • Step 4. Add Seeed Studio XIAO RP2040 to your Arduino IDE

Navigate to File > Preference, and fill “Additional Boards Manager URLs” with the url below:

https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

Navigate to Tools-> Board-> Boards Manager…, type the keyword “Seeed Studio XIAO RP2040” in the searching blank. Select the lastest version of “Seeed Studio XIAO RP2040” and install it.

  • Step 5. Select your board and port

Board

After installing the board package, navigate to Tools-> Board, find “Seeed Studio XIAO RP2040” and select it. Now we have finished setting up the Seeed Studio XIAO RP2040 for Arduino IDE.

Port

Navigate to Tools > Port and select the serial port name of the connected Seeed Studio XIAO RP2040. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). The serial port of the connected Seeed Studio XIAO RP2040 usually contains parentheses that are written “Seeed Studio XIAO RP2040”.

  • Step 6. Click the Upload button to upload the Blink example code to the board.

Once uploaded, you should be able to see the pin 25 Green (USER) LED on the board blinks once a second. If it does, congratulations! This means the connection is successful and now you can explore more projects with the Seeed Studio XIAO RP2040!

Designing the PCB.

To design the circuit and PCB, we used EasyEDA which is a browser based software to design PCBs.

Designing the circuit works like in any other circuit software tool, you place some components and you wire them together. Then, you assign each component to a footprint.

Having the parts assigned, place each component. When you’re happy with the layout, make all the connections and route your PCB.

Save your project and export the Gerber files.

Seeed Fusion PCB Assembly.

Seeed Studio Fusion PCB Assembly  Service takes care of the entire fabrication process from PCB manufacturing , parts sourcing, assembly and testing services, so you can be sure that they are getting a quality product. After gauging market interest and verifying a working prototype, Seeed Propagate Service can help you bring the product to market with professional guidance and a strong network of connections.

After ten days ,PCBs arrived at my place. the quality of PCB is very premium and the Components are soldered very well. 

Traces are perfect, silkscreen is fine. Green color PCB Masking looks very beautiful and PCBs look pretty professional. 

Connection Diagram.

Connection of Siren & flasher.Click here to download.

Siren & flasher are only useful if you are using this Gas\Smoke detector circuit in any industries.

If you want use this system in home or in kitchen then onboard buzzer is enough.

Code.

Click here to download the code or copy the code from given below. 

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
int Flasher = 3;
int Siren = 7;
int buzzer = 2;
int smokeA0 = A1;
// My threshold value
int sensorThres = 400;
void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  pinMode(Flasher, OUTPUT);
  pinMode(Siren, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600);
}
void loop() {
  int analogSensor = analogRead(smokeA0);
  Serial.print(“Pin A0: “);
  Serial.println(analogSensor);
  // Checks if it has reached the threshold value
  if (analogSensor > sensorThres)
  {
    digitalWrite(Flasher, HIGH);
    digitalWrite(Siren, HIGH);
    tone(buzzer, 1000, 200);
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println(” GAS/SMOKE DETECTOR “);
    display.print(“Sensor Reading :”);
    display.print(analogSensor);
    display.println(“Gas Leakage Detected”);
    display.display();
  }
  else
  {
    digitalWrite(Flasher, LOW);
    digitalWrite(Siren, LOW);
    noTone(buzzer);
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(WHITE);
    display.setCursor(0,0);
    display.println(” GAS/SMOKE DETECTOR “);
    display.print(“Sensor Reading :”);
    display.print(analogSensor);
    display.println(“No Leakage”);
    display.display();
  }
  delay(100);
}

Open the code in Arduino IDE, before  you upload the into XIAO R2040, you need to make few changes , so that your code will compile without getting any error.

First of all you need to add these library in your arduino ide. Click here to download the libraries.

These are the pin definition and sensor threshold value, Change this threshold value according to your sensor sensitivity.

In the loop section, we read the sensor value and compare it with the threshold value, if the sensor reading is greater than the threshold value then buzzer, flasher and siren will activated and warning message will displayed in the OLED display along with the current sensor reading.

If everything is normal, that is if no leakage is detected then sensor reading will below the threshold value in that case buzzer, flasher and siren will remain idle. and in the OLED display “No leakage” message will displayed along with the current sensor readings.

Conclusion.

This Gas\Smoke detector system is very useful safety equipment.

We can install this system in Industries, Offices , kitchens. In broad sense we install anywhere , there is probability of gas\smoke leakage.

Due to small form factor we can install anywhere without changing etiquette.

In case if you want to install in your kitchen then no need to install siren and flasher, onboard buzzer is enough.

As I mentioned earlier we can give power to this system in multiple ways, So we have option to give power supply either from AC main or from battery.   

Application of XIAO RP2040.
  • Wearable devices.
  • Rapid prototyping (directly attached to the expanded PCB as a minimal system).
  • Perfect for all the projects that need mini Arduino.
  • USB development (USB to multi-channel TTL/USB host mode, etc.).
  • DIY keyboard.
Thank you so much for reading. 🙂

Leave a Reply

Your email address will not be published.