IoT Your Arduino Using Bluetooth and Andriod Smart Phone (MQTT Tethering)

15,435

11

6

Introduction: IoT Your Arduino Using Bluetooth and Andriod Smart Phone (MQTT Tethering)

I want to try IoT using the MQTT protocol (http://mqtt.org/), in order to do this most of Arduino recipe uses Ethernet or WIFI, but I have only bluetooth HC-06, so I utilize my smartphone as hub to access internet through it

attached video contains what I achieved before in other project using this recipe, I will cover here only the connectivity and libraries used.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Install Arduino Required Libraries

Two libraries used in this project json library and custom made library to tether mqtt protocol for the Android smart phone, over software Serial.

you can download both libraries from here

https://github.com/ahmadsayed/Mqtt_Bluetooth

https://github.com/bblanchon/ArduinoJson

Hint : as per the attached image you can directly download the library from github using Download Zip button and extract it to Arduino Library folder at the Arduino IDE installation path

Step 2: Hardware Steup , Connect Arduino to HC-06

In this project I use HC-06 similar to what happen in a previous instructable you can find in the below address

https://www.instructables.com/id/Arduino-Internet-W...

but instead connect the RX,TX with 10, 11 digital output pins because our sample code uses Software Serial.

Step 3: Setup You Andriod Application

This android application needs some improvements to detect MAC address, you need to insert the MAC address manually, for simplicity I hard-coded the first 4 bytes they should be the same for all HC-06 from same supplier.

you can find the Android application source code using Android Studio here, and tweak it to fit your module

https://github.com/ahmadsayed/MQTTSerialTethering

Hint: Please insure your phone paired with the HC-06 and your bluetooth turned on before press connect

Step 4: Testing Your Application

This is just a sample to test your connectivity setup, we are going to use IBM provided quickstart service you can use it to it chart your sensor readings, just provide the HC-06 module MAC address and wait for the reading.

Upload attached test.ino to your Arduino, insure updating line 7 with your module info

for example if your mac address is (00:14:03:18:XX:XX), your constructor should be as follow

MqttSerial mqttSerial ("d:quickstart:instructable:00140318XXXX",bluetoothSerial);

the attached code read A0 Analog input pin and publish the data over quick start Mqtt protocol and the data get charted by this magical IBM web page

Attachments

Step 5: What Is Going to Happen

Finally, it works the result is from my experiment, this is not an actual sensor data but it is the noise on A0 pin however it gives a very interesting chart too :) :)

Be the First to Share

    Recommendations

    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Raspberry Pi Contest 2020

      Raspberry Pi Contest 2020
    • Wearables Contest

      Wearables Contest

    6 Discussions

    0
    SumanM19
    SumanM19

    3 years ago

    C:\Users\User\Documents\1Project\Tobe\test\test.ino:2:24: fatal error: JsonParser.h: No such file or directory

    #include <JsonParser.h>

    Why do I get this error while compiling the arduino program test.ino

    0
    bblanchon
    bblanchon

    Reply 2 years ago

    This is because the project has been written for version 3 of ArduinoJson.

    Download it here: https://github.com/bblanchon/ArduinoJson/releases/tag/v3.4

    0
    EdgarW10
    EdgarW10

    Reply 3 years ago

    Hi SumanM19, have u found out the solution? I am going trough the same problem.

    0
    SumanM19
    SumanM19

    Reply 3 years ago

    no solutions still now

    the uploader has not replied too.

    0
    ahassan31
    ahassan31

    Reply 5 years ago on Introduction

    Thank you, for your support :), this is the first comment I get in my first instructable :)