Project in progress
VoyagerGasAlert

VoyagerGasAlert © GPL3+

How to check for gas leakage in a ship; covering five sectors...

  • 20 views
  • 0 comments
  • 0 respects

Components and supplies

Ardgen mega
Arduino Mega 2560 & Genuino Mega 2560
×1
OpenSensors.io MQ-2 Gas Sensor
×5
Dual Color LED (red / green)
×5

About this project

Gas like Butane or Propane is nothing you should fool around with; even not on a ship. Because it is heavier than air, in a ship it will gather beneath the floor in the bilge, having no chance to flush. An explosive concentration could occour within seconds, and one single spark... no, we don't want this.

On my vessel, the "Voyager", I had to face this problem:

The vessel was built in 1968, we bought it in 2012. It had a liquid gas installation to serve an oven and a refrigerator. In a stern compartment the gas bottles are connected to a system of copper pipes and hoses leading the gas to the pantry. It crosses 5 compartments at all, so the idea was to install 5 gas sensors (type MQ-2) beeing monitored by an Arduino/Genuino board. Per sensor it shows an LED green if everyting is ok, and flashing red, accompanied by a buzzer, if there's something smelling suspicous.

Code

GasWarner.inoArduino
This sketch drives 5 gas sensors to alert when gas leakage is detected.
/***************************************************************************
*
* Gas warning device for 5 sectors (sensors) with buzzing alert and
* red/green alert state indication by dual LEDs per sector.
* (c) 2016 Jörg Pauly
*
* PIN OUT on an Arduino/Genuino Mega 2560 board
*				Sensors					LEDs
* 1. Sensor:	Analog in  = A1			Green = 22
*				Digital in  = 2			Red   = 23
*
* 2. Sensor:	Analog in  = A2			Green = 24
*				Digital in  = 3			Red   = 25
*
* 3. Sensor:	Analog in  = A3			Green = 26
*				Digital in  = 4			Red   = 27
*
* 4. Sensor:	Analog in  = A4			Green = 28
*				Digital in  = 5			Red   = 29
*
* 5. Sensor:	Analog in  = A5			Green = 30
*				Digital in  = 6			Red   = 31
*
* Buzzer:		off = 7HIGH
*				on  = 7LOW
*
* Onboard-LED:	off = 13LOW		(shows the system
*				on  = 13HIGH	 detected an alert.)
******************************************************************************/

#pragma region Definitions

// Pin out digital sensor pins
const int SD[5] = { 2, 3, 4, 5, 6 };

// Pin out analog sensor pins
const int SA[5] = { A1, A2, A3, A4, A5 };

// Pin out Dual-LEDs per sensor
const int LED_green[5] = { 22, 24, 26, 28, 30 };
const int LED_red[5] = { 23, 25, 27, 29, 31 };

// Pin out Buzzer
const int BUZ = 7;

// Pin out Onboard-LED
const int OLED = 13;

// Int's for sensor values
int SAstate[5] = { 0, 0, 0, 0, 0 };
int SDstate[5] = { 0, 0, 0, 0, 0 };

// Int's for LED-State
const int off = 0;
const int on = 1;

// global alert state
int alertState = 0;

#pragma endregion


#pragma region Setup und Loop

void setup()
{
	// Set pinMode for buzzer and onboard LED und switch them off.
	pinMode(BUZ, OUTPUT);	
	BuzzerOff();
	pinMode(OLED, OUTPUT);
	OLed(off);
	
	// Set all other pinModes
	for (int i = 0; i < 5; i++)
	{
		pinMode(SD[i], INPUT);
		pinMode(LED_green[i], OUTPUT);
		digitalWrite(LED_green[i], HIGH);
		pinMode(LED_red[i], OUTPUT);
		digitalWrite(LED_red[i], LOW);
	}

	// initialize USB 
	Serial.begin(9600);
}

void loop()
{
	alertState = 0;

	// Check all sensors in sequence.
	for (int i = 0; i < 5; i++)
	{
		// See readSensor() on how this works... ;-)
		alertState += readSensor(i);
	}	

	// Do we have an alert? If not, all 5 sensors report '1' == ok. 
	// A value <5 means at least one sensor is reporting alert.
	if (alertState < 5)
	{
		OLed(on);
		BuzzerOn();
		alert(SDstate, on);
		delay(100);
		BuzzerOff();
		alert(SDstate, off);
		delay(100);
	}
	else
	{
		OLed(off);
		
		for (int i = 0; i < 5; i++)
		{
			LEDgreen(i);
		}
	}
}
#pragma endregion



#pragma region Functional Logic
// Read out sensor and report state: 1 = ok, 0 = Alert
int readSensor(int sensor)
{
	// Unused here, can be usefull to calibrate device
	SAstate[sensor] = analogRead(SA[sensor]);
	// Digital value
	SDstate[sensor] = digitalRead(SD[sensor]);
	return SDstate[sensor];
}

// is called if Loop is detecting an alert on min. one sensor 
void alert(int sensors[], int state)
{	
	// Check which sensor causes the alert
	for (int i = 0; i < 5; i++)
	{
		if (SDstate[i] == 0)
		{
			// Report it to VoyagerHead
			String str = "GAS";						
			str += (i + 1);
			Serial.println(str);
			// Sector-LED red (flash in Loop)
			LEDred(i, state);
		}
		else
		{
			// Sensor [i] has no alert; LED green.
			LEDgreen(i);
		}		
	}
}

#pragma region Buzzer
// Wrapper for Buzzer

void BuzzerOff()
{
	digitalWrite(BUZ, HIGH);
}

void BuzzerOn()
{
	digitalWrite(BUZ, LOW);
}
#pragma endregion

#pragma region SectorLEDs
// Wrapper for Sector-LEDs

void LEDred(int sensor, int state)
{
	if (state)
	{
		digitalWrite(LED_green[sensor], LOW);
		digitalWrite(LED_red[sensor], HIGH);
	}
	else
	{
		digitalWrite(LED_green[sensor], LOW);
		digitalWrite(LED_red[sensor], LOW);
	}
	
}

void LEDgreen(int sensor)
{
	digitalWrite(LED_red[sensor], LOW);
	digitalWrite(LED_green[sensor], HIGH);
}
#pragma endregion

void OLed(int state)
{
	if (state)
	{
		digitalWrite(OLED, HIGH);
	}
	else
	{
		digitalWrite(OLED, LOW);
	}
}

#pragma endregion

Comments

Add projectSign up / Login