loading

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.

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

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 :) :)

<p>C:\Users\User\Documents\1Project\Tobe\test\test.ino:2:24: fatal error: JsonParser.h: No such file or directory</p><p> #include &lt;JsonParser.h&gt;</p><p>Why do I get this error while compiling the arduino program test.ino</p>
<p>Hi SumanM19, have u found out the solution? I am going trough the same problem.</p>
<p>no solutions still now</p><p>the uploader has not replied too.</p>
<p>Nice gadget, and awesome job on the coding!</p>
<p>Thank you, for your support :), this is the first comment I get in my first instructable :)</p>

About This Instructable

11,576views

11favorites

More by ahassan31:IoT your Arduino using bluetooth and andriod smart phone (MQTT tethering) 
Add instructable to: