CODE:https://cdn.rawgit.com/samliew/4f6aec0c65e4dbe5c7fd782ea0953a3b/raw/0d928b52b69aef81b1bf5da50cbfb26ba3b4e71e/countries.js

Free email course on building IoT with Cloud IoT CoreCloud IoT Core
Free email course on  
Connectivity in IoT
Thanks for signing up! You'll get the first email soon.
Oops! Something went wrong while submitting the form.
< Back to Blog

 This series is intended for developers and hackers looking to test out a LoRaWAN network using MultiTech’s Conduit and mDot RF modules. The Things Network has an extensive forum and support for public gateways and nodes in Europe, but little documentation exists for those wanting to test a private network in the US.This is the fourth post in a four part guide which covers:

1. Configuring the Conduit & Starter Kit

2. Node-RED & Bypassing IBM Bluemix

3. Programming MultiTech Developer Kit & Adding Sensors

4. Using the mDot, xbee shield, and Arduino

Using the mDot, xbee shield, and Arduino

Part IV of the MultiTech series will focus on using a xbee shield and Arduino to build a custom node. This is a cheaper and hackier alternative to buying the developer board. For more polished versions, please check out Part III of the guide.

Hardware

To get started with the project, I followed the instructions laid out by Mike Vladimer and Anna Aflalo of Orange IoT Studio. Instead of the Arduino Mega, I used my Arduino Uno and bought the XBee shield v2.0 from Seeed Studio. But I do also know that the SparkFun XBee Shield works just fine with the mDot.

To set the mDot onto the XBee shield, bend the two pins in the XB_TX row next to pins 11 and 12 to make room. Now push in the mDot with the antenna facing outward from the board. Finally, connect one wire from XB_TX row to pin 2 of the shield, and connect another wire from pin 3 to XB_RX row.

Image Credit: Leverege

Hello World!

To send “Hello World” to the gateway, all you need is to be comfortable with AT commands supported by MultiTech. Here’s a simple starter code to join the network and send “Hello World” once.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

void setup() {

  // AT Commands for MultiTech

  Serial.println("Joining Lora Network");

  mySerial.begin(115200);

  mySerial.println("AT");

  mySerial.println("AT+NI=1,levdev01"); // Match your network name

  mySerial.println("AT+NK=1,levdev01"); // Match your password

  mySerial.println("AT+FSB=1");

  mySerial.println("AT+JOIN");

  mySerial.println("AT+SEND=Hello World");

}

void loop() {

 // Reading the output in terminal

 if (mySerial.available()) {

     Serial.write(mySerial.read());

 }

}

You just need to change the network name and password from levdev01 to what you had set your LoRa settings to be. If you run into trouble, make sure the correct board is selected in the Arduino IDE and run the Serial Monitor with baud rate of 115200.

Adding Sensors

This process is trivial once you are able to join the gateway. You can use any Arduino-compatible sensor, get the code to read in the data, and just send the value to using the AT+SEND command. For example, I used a MQ2 sensor to build a simple gas leak detector. To test the sensor, you can use Listerine to activate the gas sensor.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

const int gasPin = 8;

void setup() {

 // Setting up Serial Monitor

 Serial.begin(115200);

 mySerial.begin(115200);

// Join the Lora Network

 mySerial.println("AT");

 mySerial.println("AT+NI=1,levdev01");

 mySerial.println("AT+NK=1,levdev01");

 mySerial.println("AT+FSB=1");

 mySerial.println("AT+JOIN");

}

void loop() {

 // Send string "gas" if MQ2 sensor detects gas

 if(digitalRead(gasPin) == LOW){

   mySerial.println("AT+SEND=Gas");

   delay(1000);

 }

// This is for debugging

 if (mySerial.available()) {

     Serial.write(mySerial.read());

 }

}

I used the digital output of the gas sensor to just simply tell me when it detects gas and send the value to the gateway. If you would like the actual analog readings, MQ2 sensor also has analog ports as well.

You can refer to the pictures below for the simple setup and the NodeRED flow to verify it working!

Image Credit: Leverege

I hope this series was helpful for those looking to test out a LoRaWAN network. Personally, I was surprised by the range of these modules. We were getting good reception several km away from our office even when the gateway was sitting on a desk. In my next post, I will continue to work with alternative solutions using Raspberry Pi and Dragino Shield!

Have Questions? Talk to an Expert

Yitaek Hwang

From traveling the world solving vision issues in underserved regions through ViFlex to building software to diagnose autism using machine learning, I realized that I like building things. So currently I’m on a path to build an Internet of Things (IoT) platform at Leverege as a Venture for America Fellow.

SHARE

Liked this post? You're gonna love these!

IoT Device Management: What Is It and Why Do You Need It?
February 26, 2019
Why You Need Contextual IoT Device Management
February 26, 2019
Using LoRa and Google Cloud for IIoT Applications
February 20, 2019

Talk with Leverege

What type of use case are you building for? Whichever it is we are looking forward to learning more about your needs.

Have Questions?

Our team of experts is here to help!

Thanks for your submission! Our team is looking forward to connecting with you and will be in touch very soon!
Oops! Something went wrong while submitting the form.