Introduction: Fire and Carbon Monoxide(CO) Alert System Using Ubidots and Particle

About: We are a group of makers. We work in IoT, IOS app, android app, embedded design, sensor design, raspberry pi, arduino, beaglebone, particle electron, particle photon, Bluetooth.

Fire Alert System plays an important role in Industries, Shops, Malls, Residential buildings and so on. It helps in recognizing fire or smoke at the beginning period and can help in saving lives. Alarm and buzzer alert is generally used in most of the Fire Alert System. In this IoT based Alarm system, we are detecting Fire as well as the Carbon Monoxide level. We will get a message as well as an emergency call so that we can take further action to resolve the incident. Also, an automatic relay control connected to a water sprinkler system gets activated as the level of temperature exceeds its threshold limit.

We know that carbon monoxide is poisonous to humans and can cause death if not recognized earlier. This gas cannot be detected by humans as it has no taste or smell and cannot be seen. We can use this system at home and in industries. Emission of CO in the home environment includes gas-burning appliances together with boilers, furnaces, water heaters, fireplaces, charcoal grills, fuel and kerosene warmers, gas and wooden stoves, and material dryers.

In Industries it commonly emits at warehouses, which carry out propane-powered forklift vans, ground polishers and vicinity heaters, gas-powered concrete cutters, stress washers, and air compressors, humans believe that this gas is not a big problem however contributing to over 10,000 illnesses and up to 50 deaths per year.

Step 1: Hardware Required

1. Particle Photon

  • The Photon is a tiny Wi-Fi IoT device for creating connected projects and products for the Internet of Things. It's easy to use, it's powerful, and it's connected to the cloud. The board itself uses a Cypress Wi-Fi chip (one that can be found in Nest Protect, LIFX, and Amazon Dash) alongside a powerful STM32 ARM Cortex M3 microcontroller.

2. Particle Electron or Photon I2C Shield with Out Facing I2C Port

  • Use the Particle Electron / Photon to provide cloud connectivity to a world of expansion controllers using the PEI2C expansion.
  • The PEI2C provides a 5 Volt I2C expansion port, allowing your Particle Electron or Photon to connect to different I2C devices. Connect sensors for light level monitoring, gas level detection, temperature, and humidity monitoring, as well as many types of motion, acceleration, and direction sensors.

3. One Channel Relay(5V)

4. MQ9

  • The MQ-9 Gas sensor makes it easy to monitor carbon monoxide and combustible gas concentration levels using our I2C Mini Module form factor. The MQ9 is connected to an ADC121C 12-Bit Analog to Digital converter, which is capably expanding to 9 gas sensors per I2C port using just two address jumpers (making full use of the floating address system).
  • The MQ-9 is capable of sensing carbon monoxide air concentration levels between 10 and 1,000ppm and combustible gas-air concentration levels between 100 and 10,000ppm. The ideal sensing condition for the MQ9 is 20°C ±2°C at 65% ±5% humidity

5. SHT30

  • SHT30 is the next generation of Sensirion’s temperature and humidity sensors.
  • The SHT30 has increased intelligence, reliability, and improved accuracy specifications compared to its predecessor. Its functionality includes enhanced signal processing so that temperature and humidity can be read out using I2C communications.

Step 2: Connection With Particle Photon

The requisite connections(refer to the pictures) are as follows:

1. This will work over I2C. Take an I2C shield for Particle Photon and gently connect it on to the pins of Particle Photon.

2. Connect the one end of I2C cable to the in-port of SHT30 and the other end to the I2C shield.

3. Connect the MQ9 sensor in-port to the SHT30 out using I2C cable.

4. To power on relay use 3V and GND pin of Photon. Connect D7 pin of Photon to IN pin of the relay.

5. Finally, power the Particle Photon using USB cable. You can also use the Power Shield of Photon to provide external power.

Step 3: Connecting Particle Photon to Ubidots Using Particle Webhooks

To know about the Particle Webhook feature you can visit the following link.

1. To get started with your Particle Photon device, click here.

2. After your device is Setup, go with these steps:

  • Login to your Particle Account, go to Particle Console, move your mouse pointer to Integration.
  • Click on "New Integration"
  • Select "Webhook"
  • Name the event like Ubidots.
  • Add the URL
https://industrial.api.ubidots.com/api/v1.6/devices/{{{PARTICLE_DEVICE_ID}}}
  • Select the request type POST, request format Custom Body, device Any.
  • Go to Advanced Settings and insert the text "{{{PARTICLE_EVENT_VALUE}}}" in Custom Request Body.
  • Now move to HTTP HEADERS and insert:
Host | industrial.api.ubidots.com
X-Auth-Token | YOUR_UBIDOTS_TOKEN_HERE
Content-Type | application/json
  • Click on CREATE WEBHOOK and verify data is being streamed to Ubidots.

Step 4: Programming the Photon

After a successful connection with your Particle account to Ubidots using Webhooks, its time to program your Photon.

1. Create New App ,Click onParticle IDE.

2. Give some Name to your App.

3. Add the Ubidots library to your new project:

  • Go to the Libraries option on the right-side panel in Particle IDE and click it.
  • Search Ubidots in Community Libraries, Click on it.
  • Click on Include In Project.
  • Click your App name, Confirm it and library will be inserted.

4. Copy and Paste the Fire - Carbon Monoxide(CO) Alert System.ino code below.

// This #include statement was automatically added by the Particle IDE.
// This code is designed for Particle Photon to work with the SHT30 and MQ9 I2C Mini Module available from dcubestore.com // This code is written for Fire and Carbon Monoxide Alert System // Ubidots using Particle Webhooks.

/**************************************** Include Libraries ****************************************/ #include <Ubidots.h>

#include <application.h>

#include <spark_wiring_i2c.h>

/**************************************** Define Instances and Constants ****************************************/

#define interval 1000 #define Addr 0x44 #define Addr2 0x50 double cTemp = 0.0, fTemp = 0.0, humidity = 0.0; int raw_adc_MQ9 = 0; double ppm_MQ9 = 0.0; int relay = D7; int i = 0;

const char* WEBHOOK_NAME = "Ubidots";

Ubidots ubidots("webhook", UBI_PARTICLE);

/**************************************** Main Functions ****************************************/

void setup() { Serial.begin(115200); ubidots.setDebug(true); // Uncomment this line for printing debug messages

// Set variable for SHT30 Particle.variable("i2cdevice", "SHT30"); Particle.variable("cTemp", cTemp); Particle.variable("humidity", humidity);

// Initialise I2C communication as MASTER Wire.begin(); // Initialise serial communication, set baud rate = 9600 Serial.begin(9600); delay(300);

// Set variable for MQ9 Particle.variable("i2cdevice", "ADC121C_MQ9"); Particle.variable("PPM", ppm_MQ9);

// Initialise I2C communication as MASTER Wire.begin(); // Initialise serial communication, set baud rate = 9600 Serial.begin(9600); delay(300); pinMode(relay, OUTPUT);

}

void loop() {

// SHT30 unsigned int data[6];

// Start I2C Transmission Wire.beginTransmission(Addr); // Send 16-bit command byte Wire.write(0x2C); Wire.write(0x06); // Stop I2C transmission Wire.endTransmission(); delay(300);

// Start I2C Transmission Wire.beginTransmission(Addr); // Stop I2C Transmission Wire.endTransmission();

// Request 6 bytes of data Wire.requestFrom(Addr, 6);

// Read 6 bytes of data // temp msb, temp lsb, crc, hum msb, hum lsb, crc if (Wire.available() == 6) { data[0] = Wire.read(); data[1] = Wire.read(); data[2] = Wire.read(); data[3] = Wire.read(); data[4] = Wire.read(); data[5] = Wire.read(); } delay(500);

// Convert the data cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45; fTemp = (cTemp * 1.8) + 32; humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0);

// Output data to dashboard Particle.publish("Temperature in Celsius: ", String(cTemp)); Particle.publish("Temperature in Fahrenheit: ", String(fTemp)); Particle.publish("Relative Humidity: ", String(humidity));

float value2 = humidity ; float value1 = cTemp ; if (cTemp >= 60) { digitalWrite(relay, HIGH); delay(interval); digitalWrite(relay, HIGH); delay(interval); } else { digitalWrite(relay, LOW); delay(interval); digitalWrite(relay, LOW); delay(interval); } delay(1000);

// MQ9

unsigned int data2[2];

// Start I2C transmission Wire.beginTransmission(Addr2); // Select data register Wire.write(0x00); // Stop I2C transmission Wire.endTransmission();

// Request 2 bytes of data Wire.requestFrom(Addr2, 2);

// Read 2 bytes of data // raw_adc msb, raw_adc lsb if (Wire.available() == 2) { data2[0] = Wire.read(); data2[1] = Wire.read(); } delay(300);

// Convert the data to 12-bits raw_adc_MQ9 = ((data2[0] & 0x0F) * 256) + data2[1]; float sensor_voltage = raw_adc_MQ9 / 1024.0 * 5.0; float RS_gas = (5.0 - sensor_voltage) / sensor_voltage; float ratio = RS_gas / 3.78;

// Output data to dashboard Particle.publish("Carbon Monoxide Concentration : ", String(ratio)); float value3 = ratio; delay(1000);

ubidots.add("Variable_Name_One", value1); // Change for your variable name ubidots.add("Variable_Name_Two", value2); ubidots.add("Variable_Name_Three", value3); bool bufferSent = false; bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC); // Will use particle webhooks to send data

if (bufferSent) { // Do something if values were sent properly Serial.println("Values sent by the device"); }

delay(5000);

}

5. Verify the code and flash it.

Step 5: Create Ubidots Events

Once the code is flash to Photon using Particle IDE, data starts to appear at Ubidots.

Ubidots support already integrated events to allow you to send Events, Alerts, and Notifications to those who need to know when they need to know. You can learn more about them at Creating Conditional Events and Alerts.

Steps to create events:

1. Login to your Ubidots Dashboard.

2. Go to DATA and select Events.

3. Click + sign at your left side of the Ubidots console to create Events.

4. Select the If triggers tab to organize your event logic or condition.

5. Click on Select Variable: Temperature And Humidity.

6. Create a condition: If the value of Temperature or Humidity is Greater than or equal to 60 for 0 min.

7. Select the Then actions tab to execute the planned Event or Alert, in our case we will use Voice and SMS alert.

8. Establish which actions are to be executed and the message to the receiver.

9. Determine the time.

10. Confirm the Events

Step 6: Output

Step 7: Applications

  • This system allows you to analyze real-time data in the Ubidots platform.
  • The fire generated heat and smoke can severely damage or totally destroy the items beyond repair. This emergency alert with automatic relay control which could be connected to a water sprinkler system can save many lives and properties.
  • We can also connect GPS to get a real-time location which can be shared to near fire stations and hospitals so that they can reach in time.
  • This system can be used for multipurpose i.e, Fire alert and alert for poisonous Carbon monoxide gas.

Step 8: Resources

For more information about SHT30 And MQ9 check out the below links: