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

Picture of 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

Picture of 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

5V<------------>Vcc

GND<--------->GND

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
https://labs.mediatek.com/site/global/developer_to...

Or this is instructables made by Light Bug has more clear instruction on installing the device software https://www.instructables.com/id/Getting-Started-w...

Step 2: Make New Data Source

Picture of Make New Data Source

open http://ubidots.com/ 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

Picture of 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

Picture of 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:
     LWiFi.begin();
     Serial.begin(115200);
     
     Serial.println("connecting...");
     while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
  {
    delay(1000);
  }
   }

void loop()
   {
     int value = analogRead(A0);
     save_value(String(value));
   }

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();
     delay(10000);
     if(client.connect("things.ubidots.com", 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);
       client.println("Host: things.ubidots.com\n");
       Serial.println("Host: things.ubidots.com\n");
       client.print(var);
       Serial.print(var+"\n");
     }
     else
     {
       // if you didn't get a connection to the server:
       Serial.println("connection failed");
     }

   if (!client.connected())
     {
       Serial.println();
       Serial.println("disconnecting.");
       client.stop();
     }

    if (client.available())
     {
       char c = client.read();
       Serial.print(c);
     }
     client.flush();
     client.stop();

}

Step 6: Get Your Data

Picture of 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

Comments

Arwan94 (author)2015-10-21

good tutorial.. (Y)

About This Instructable

1,075views

8favorites

License:

More by chalei:Linkit One IoT: Sending SMS without SIM CardLinkit One: Blowing an LEDLinkit One: Debounce button
Add instructable to: