C10: Arduino / RPi Pico Advanced – Actuator Interfacing

Aim:

Create a gas leak detection system that sounds an alarm if gas is detected above a safe level.

Requirements:

  • Arduino Uno or Raspberry Pi Pico

  • Gas sensor MQ-2

  • Piezo buzzer

  • Breadboard and jumper wires

  • USB cable and computer with Arduino IDE or Thonny

Working Principle:

  • The MQ-2 sensor detects gases such as LPG, methane, and smoke.

  • The sensor outputs a voltage proportional to the gas concentration.

  • The Arduino reads this voltage and compares it with a set threshold.

  • If the gas concentration exceeds the threshold, the buzzer is activated.

Circuit Connections

Gas Sensor VCC → 5V
Gas Sensor GND → GND
Gas Sensor AO → A0 (Arduino)

Buzzer + → Pin 8 (Arduino)
Buzzer – → GND

Step-by-Step Instructions

Step 1: Wiring

  1. Place the gas sensor and buzzer on the breadboard.

  2. Connect MQ-2’s VCC to 5V, GND to GND, and AO to A0 pin on Arduino.

  3. Connect buzzer positive terminal to Pin 8, negative terminal to GND.

Step 2: Arduino Code (Basic Version)

int gasSensor = A0;

int buzzer = 8;

int threshold = 400; // Adjust if needed

 

void setup() {

  pinMode(buzzer, OUTPUT);

  Serial.begin(9600);

}

 

void loop() {

  int gasValue = analogRead(gasSensor);

  Serial.println(gasValue);

 

  if (gasValue > threshold) {

    digitalWrite(buzzer, HIGH); // Alarm ON

  } else {

    digitalWrite(buzzer, LOW); // Alarm OFF

  }

 

  delay(500);

}

 

Step 3: Testing

  • Open Serial Monitor to observe gas readings.

  • Bring a small gas source (like LPG from a lighter without flame) near the sensor.

  • The buzzer should sound when gas levels are high.

Advanced Version – Adding LED Alert

int gasSensor = A0;

int buzzer = 8;

int led = 7;

int threshold = 400;

 

void setup() {

  pinMode(buzzer, OUTPUT);

  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

 

void loop() {

  int gasValue = analogRead(gasSensor);

  Serial.println(gasValue);

 

  if (gasValue > threshold) {

    digitalWrite(buzzer, HIGH);

    digitalWrite(led, HIGH);

  } else {

    digitalWrite(buzzer, LOW);

    digitalWrite(led, LOW);

  }

 

  delay(500);

}

Step 3: Testing

  • Open Serial Monitor to observe gas readings.

  • Bring a small gas source (like LPG from a lighter without flame) near the sensor.

  • The buzzer should sound when gas levels are high.

Advanced Version – Adding LED Alert

int gasSensor = A0;

int buzzer = 8;

int led = 7;

int threshold = 400;

 

void setup() {

  pinMode(buzzer, OUTPUT);

  pinMode(led, OUTPUT);

  Serial.begin(9600);

}

 

void loop() {

  int gasValue = analogRead(gasSensor);

  Serial.println(gasValue);

 

  if (gasValue > threshold) {

    digitalWrite(buzzer, HIGH);

    digitalWrite(led, HIGH);

  } else {

    digitalWrite(buzzer, LOW);

    digitalWrite(led, LOW);

  }

 

  delay(500);

}

 

Real-World Applications

  • Home safety systems for detecting gas leaks.

  • Industrial safety in factories handling chemicals.

  • Smart home integration for automatic alerts to mobile devices.

Fill in the form for S’O’A Fablab Orientation 2021.