Introduction: Linkit One Gas IoT: (LPG) Monitor With Ubidots

This instructables is a continuatioan of my linkit one IoT Tutorial Series. You can check my previous linkit one tutorial in here.

This time I will use MQ 2 Sensor to detect Gas (LPG) Level and send the data to Ubidots platform via Wifi connection

Ubidots is an IoT Platform that compatible with a lot of development Boards, and ubidots supply many documentation for new user so they can easily adapt with the ubidots platform. Ubidots also have a great dashboard that is easy to understand and could be implemented at your custom web page

Step 1: Get the Material and Make the Connection

material and components that needed for this project are:

  1. Linkit One Board with wifi antenna attached
  2. 3 Male to Male Jumper Cable
  3. MQ-2 Sensor
  4. Breadboard
  5. Usb Micro Cable

After You get the material make the connection like in the picture

Linkit OneMQ-2



A0<------------->A0(analog pin)

And then we are ready to code

To get Started with linkit one you can click the link below

Here are the full instruction on how to install the software

Or this is instructables made by Light Bug has more clear instruction on installing the device software

Step 2: Make New Data Source

open and sign up for new account.

After You are succeed making new account click "Source" and then make new data source.

Click On Generic Icon and then name the data source as "Gas Data"

to save it click "create" button

Step 3: Make New Variables

now we have a data source called "Gas Data". What we need to do next is create a new variable data by clicking the "Gas Data" box that we have just create.

After that "Add Variable" and we name the variable as "MQ 2 Data", then click create.

Now You have one variable box with variable key in it. Get your variable key by clicking the "i" icon and the save it to your notepad. we will use it later at the next step

Step 4: Get Your Token Key

Next Step is to get your token key. To this, click your account name then choose my profile.

Create New Token and then save it to notepad.

And now we are really ready to code

Step 5: The Code

Copy and paste this code to your Arduino IDE, make sure you are already install the library for the linkit one board

Open your notepad that has your variable and token key in it. and change it in this code.

After everything is set, upload it

//Put your variable key in "idvariable"

//and put your token key in "token" 
#include <LTask.h>
#include <LWiFi.h>
#include <LWiFiClient.h>
#define WIFI_AP "YourWiFiName"
#define WIFI_PASSWORD "WiFiPassword"
#define WIFI_AUTH LWIFI_WPA  // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to you WiFi AP configuration

LWiFiClient client;

String idvariable = "YourVariableKey";
String token = "YourTokenKey";

void setup() {
    // Open serial communications and wait for port to open:
     while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))

void loop()
     int value = analogRead(A0);

void save_value(String value)
     // if you get a connection, report back via serial:
     int num=0;
     String var = "{\"value\":"+ String(value) + "}";
     num = var.length();
     if(client.connect("", 80))
       Serial.println("connected");    // New lines according to ubidots support:       
       client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       Serial.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
       client.println("Content-Type: application/json");
       Serial.println("Content-Type: application/json");
       client.println("Content-Length: "+String(num));
       Serial.println("Content-Length: "+String(num));
       client.println("X-Auth-Token: "+token);
       Serial.println("X-Auth-Token: "+token);
       // if you didn't get a connection to the server:
       Serial.println("connection failed");

   if (!client.connected())

    if (client.available())
       char c =;


Step 6: Get Your Data

The code that you just uploaded will send the gas data every ten second. To test that your code is really working. Get a gas lighter but don't light it, just press the button until the gas come out and place it close to the MQ 2 Sensor just like in the picture.

Click your variable box and then will see your data with charts and table in it.

Hopefully this project will help you to learn more about IoT