iotapp-gas-leak-monitor [] [] {"id":"gas-leak-monitor","title":"Gas Leak Monitor: Build an IoT application to monitor for gas leaks","metaDesc":"Build a connected gas leak monitoring system that sends alerts when leaks are detected and lets you turn off gas flow remotely from a mobile device.","tweet":"I'm building an #IoT gas leak monitoring system with @temboo, and you should too!","device_count":"single","devices":{"arduinoyun":"Arduino Y\u00fan","samsung_artik_ten":"Samsung ARTIK 10","samsung_artik_five":"Samsung ARTIK 5","ti_cc3100":"Texas Instruments CC3100 BoosterPack","ti_cc3200":"Texas Instruments CC3200"},"description":"Undetected gas leaks can be deadly and costly. We've built an application that detects gas leaks and allows the remote control of a gas valve to close off the flow of gas. We'll show you how you can build it.","categories":["building-management","environment","smart-cities"],"choreos":{"SendMessage":{"uri":"Library\/Amazon\/SQS\/SendMessage","templateName":"AmazonAWS","credentialDescription":"You might have heard of Amazon.com. They're the world's largest online retailer, and they also happen to run some of the most popular Web services available.\n ","description":"Sends up to ten messages to the specified queue.","credentialInputs":[{"name":"AWSAccessKeyId","type":"string","description":"The Access Key ID provided by Amazon Web Services.","placeholder":"myAWSAccessKeyId","callout":"Save your API Credentials to use them from any AWS Choreo in the Library."},{"name":"AWSSecretKeyId","type":"string","description":"The Secret Key ID provided by Amazon Web Services.","placeholder":"myAWSSecretKeyId"}],"inputs":[[{"name":"AWSAccountId","type":"integer","description":"The id for the AWS account associated with the queue you're retrieving a message from (remove all dashes in the account number).","placeholder":"myAWSAccountId"},{"name":"MessageBody","type":"string","description":"The message to send. Maximum size is 64 kb.","text":"close","callout":"The iOS app will send messages containing 'open' or 'close' to instruct the board on what state the valve should be in."},{"name":"QueueName","type":"string","description":"The name of the queue you want to send a message to.","placeholder":"mySQS-QueueName"}]]},"ReceiveMessage":{"uri":"Library\/Amazon\/SQS\/ReceiveMessage","templateName":"AmazonAWS","credentialDescription":"You might have heard of Amazon.com. They're the world's largest online retailer, and they also happen to run some of the most popular Web services available.\n ","description":"Returns one or more messages from the specified queue.","credentialInputs":[{"name":"AWSAccessKeyId","type":"string","description":"The Access Key ID provided by Amazon Web Services.","placeholder":"myAWSAccessKeyId","callout":"Save your API Credentials to use them from any AWS Choreo in the Library."},{"name":"AWSSecretKeyId","type":"string","description":"The Secret Key ID provided by Amazon Web Services.","placeholder":"myAWSSecretKeyId"}],"inputs":[[{"name":"AWSAccountId","type":"integer","description":"The id for the AWS account associated with the queue you're retrieving a message from (remove all dashes in the account number).","placeholder":"myAWSAccountId"},{"name":"QueueName","type":"string","description":"The name of the queue you want to retrieve a message from.","placeholder":"mySQS-QueueName","callout":"Messages sent to the Queue from our iOS app will be received by our board."}]]},"Publish":{"uri":"Library\/Amazon\/SNS\/Publish","templateName":"AmazonAWS","credentialDescription":"You might have heard of Amazon.com. They're the world's largest online retailer, and they also happen to run some of the most popular Web services available.\n ","description":"Sends a message to a topic's subscribed endpoints.","credentialInputs":[{"name":"AWSAccessKeyId","type":"string","description":"The Access Key ID provided by Amazon Web Services."},{"name":"AWSSecretKeyId","type":"string","description":"The Secret Key ID provided by Amazon Web Services."}],"inputs":[[{"name":"Message","type":"string","description":"The text for the message you want to send to the topic.","placeholder":"Gas leak detected. Open app to close the gas line.","callout":"This message will be sent when a gas leak is detected."},{"name":"TopicArn","type":"string","description":"The ARN of the topic you want to publish to.","placeholder":"arn:aws:sns:us-east-1:myAWSAccountId:GasLine"}]]}}}

Undetected gas leaks can be deadly and costly. We've built an application that monitors a gas line for leaks and allows the remote control of a gas valve to prevent further leakage.

We'll show you how you can build it.

Materials
Combustible Gas Sensor
Like this MQ9 Gas Sensor
Solenoid Valve
We used this solenoid valve
Breadboard
Pipes
We used these plumbing pipes
iOS Device
Requires iOS 8.3 or higher

Additional

  • 12v battery pack
  • 8 AA batteries

First, Sign up for Amazon Web Services.

Go to Security Credentials and obtain your AWSAccessKeyID and AWSSecretKeyID.

Create a SQS Queue. This will be used to communicate with the gas valve. The board will retrieve instructional messages sent from an iOS application.

Limit the retention time to 5 minutes to ensure older messages aren't read by mistake.

Find your 12 digit Account ID included in the URL and ARN of your Queue.

Create a SNS Topic. This will be used to send notifications to the operations manager in charge of the gas line.

Create a SNS Subscription with the email address that the alert should be sent to as the subscription endpoint.

Locate the TopicArn of the topic you want to publish to.

Connect the power and ground of your board to your breadboard.

When gas levels rise above 1.2 on the sensor, the Amazon SNS alert will be triggered.

We'll add some smoothing to our data in the final code by looking at the average of the last 100 readings.

Connect the first pin of your MQ-9 gas sensor to
Analog

Connect the middle pin of the gas sensor to power, and the third pin of your sensor to ground.

The solenoid valve can be closed via the iOS app which sends a message to an SQS queue.

If a gas leak is detected, our board will retrieve messages from the queue to receive instruction.

Connect the ground of the solenoid valve to the Collector pin (middle) of the TIP120 Transistor.

Connect the Base pin (first) of the TIP120 Transistor to
Digital

Connect the Emitter pin (third) of the TIP120 Transistor to ground.

IMPORTANT! Never connect the positive side of the 12v power source to your board. If connected improperly, your board will have a new career as a door stop.

Connect the ground of the 12v power supply to the same ground as your board.

Connect the positive end of the 12v power supply to the rail with the power end of the pump.

Need help running the code?
Need help running the iOS code?

Install for Samsung ARTIK

If this is the first time using Temboo, you'll need to set up your ARTIK board to find the Temboo libraries. To do so, you'll need to create the file temboo.conf in /etc/ld.so.conf.d. Inside of temboo.conf, you'll want to copy the line below and paste it into the file:

/opt/iothub/artik/temboo/temboo_artik_library/lib

After saving temboo.conf, run ldconfig from the command line to add the Temboo library directory to the system library search path.

You’ll also need to get the IP address of your ARTIK board using ifconfig. The example below shows the results when the ARTIK board is connected to the internet through an ethernet cable. The IP address you'll want to use is listed next to inet.

[root@localhost ~]$ ifconfig
eth0: flags=4163  mtu 1500
inet 10.11.6.200  netmask 255.255.255.0  broadcast 10.11.6.255

Run the code

Download and unzip the IoT Application file. In your IoT Application folder, you'll find a Samsung folder containing the GasLeakMonitor folder with code for the Artik. Copy the Samsung folder to your ARTIK board using scp. From your computer, go to the directory where the Samsung folder is located and type the command below. Make sure you use the IP address for your board you found using ifconfig.

[root@localhost ~]$ scp -r GasLeakMonitor root@xxx.xxx.xxx.xxx:/home

Now cd into the directory on your Artik where you placed the folder and and compile and run your code using the command below.

make

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.

Install for TI LaunchPad

Open the .ino file with Energia. While the sketch is running, open the Serial Monitor and you should see your app running.

Congratulations! Now that you know how to make your LaunchPad run any Choreo, you're just a few steps away from making something extraordinary.

You can find more examples of how to use Temboo with your LaunchPad here.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.

Run the Sketch and rejoice

Save and upload your sketch to the Arduino Yún, and open the serial monitor.

Congratulations! You've just run an IoT Application. With Temboo handling all the small stuff, you're free to think big.

You can find lots of examples of how to use Temboo with your Yún here.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.

Running the iOS Application

Make sure you have the latest Xcode, which can be downloaded here.

Download the Code

Download the code at the link above.

Unzip the files where you can find them. You should see one folder containing the iOS code, and another containing the hardware device code.

Open the Xcode Project

Locate the .xcodeproj file in the iOS code. Open the file with Xcode and you should see all of the accompanying files in the Project navigator.

If the file titles in your Project navigator are red, you'll need to relink them by clicking control and selecting "Add Files to ", then select and add all of the files from the iot application folder contained in the iOS folder you downloaded. Control click and delete any of the unlinked files that appear in the Project navigator.

Download the iOS SDK

The latest Temboo iOS SDK can be downloaded here. Save and unzip it to a folder where you can find it.

Once again, you'll need to control-click on the top-level folder in your Xcode Project navigator. Select "Add Files to " and browse to where you saved the Temboo SDK, locate and click on the "core" folder inside the SDK "src" folder. Make sure that "copy items if needed" is unchecked and "Create groups" is selected, then and select "Add".

Repeat the above steps to add the appropriate files located in the SDk's src/library folder.

Run the App

Make sure you have a device selected in the simulator, and click the run button.

Congratulations! You should see the app displayed in the simulator window. Go ahead and try it out, and you should see the Choreo results printed to the console.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.