My Cart

How to Send Sensor Data Using LoRa Extreme Range Connectivity Kit

Difficulty Level: Beginner -

1. Introduction

This tutorial allows the user to measure the temperature and the light level in a room. This data is sent to a LoRa gateway.

Ingredients:

    - 1 x LoRa Extreme Range Connectivity Kit:
    • 1x Multiprotocol radio shield
    • 2x LoRa module
    • 1x LoRa gateway
    • 1x LDR
    • 1x NTC
    • 1x 220Ω resistor
    • 1x Breadboard
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now
NOTE: Depending on the platform chosen to develop the project, the ingredients and the schematics shown in this tutorial can vary.

This project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.

For further information about the SX1272 LoRa module, consult the main tutorial.

Step 1: Connection

Connect the multiprotocol shield to Arduino or to Raspberry Pi connection bridge, and then connect LoRa module. Connect the light sensor and the temperature sensor in the breadboard as you can see in the next diagram.

Connect two wires, red and black, to the two long rows on the side of the breadboard to provide access to the 5 volt supply and ground.

Place the temperature sensor with the flat part looking up like the diagram. Connect the left leg of the temperature sensor to GDN and the right to 5 volt. Connect the central leg to the first pin at bottom left of the shield (Analog 0).

Connect the left leg of the light sensor to GND and the right to the second pin at bottom left of the shield (Analog 1) and also to a 220 Ohm resistor.Finally connect the other leg of the resistor to 5 volt. This structure is called "voltage divider".

On the other hand you must connect a gateway with a LoRa module to a PC.

Step 2: The Code

First you will need to open a terminal program like Cutecom (Linux), Hyperterminal or Putty (Windows). Follow the instructions in this tutorial, specially point 2 to make the communication setup.

Programs as Cutecom allow to enter hexadecimal numbers to enter these characters (Select Hex input). If you are using another program, you can use some tools to edit hexadecimal characters.

Type the following hexadecimal code to program the LoRa gateway with this specifications:

  • Mode=4 (BW=500 CR=4/5 SF=12)
  • Node address=3
  • Channel=12_868

LoRa gateway:

Code:
01 53 45 54 23 46 52 45 43 3a 43 48 5f 31 32 5f 38 36 38 3b 41 44 44 52 3a 33 3b 42 57 3a 42 57 5f 35 30 30 3b 43 52 3a 43 52 5f 35 3b 53 46 3a 53 46 5f 31 32 0d 0a 37 39 43 41 04
        

For more information on how to make the packages needed for LoRa gateway communication read point 3 in this tutorial.


Arduino:

Code:
/*  
 *  LoRa 868 / 915MHz SX1272 Module
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Victor Boria & Luis Miguel Marti
 */
 
// Include the SX1272 and SPI library: 
#include "SX1272.h"
#include <SPI.h>

int e;
char message1 [60];
int ldr;
int ntc;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  
  // Power ON the module
  sx1272.ON();
  
  // Set transmission mode and print the result
  e = sx1272.setMode(4);
  Serial.println(F("Setting Mode: state "));
  Serial.println(e, DEC);
  
  // Select frequency channel
  e = sx1272.setChannel(CH_12_868);
  Serial.println(F("Setting Channel: state "));
  Serial.println(e, DEC);
  
  // Select output power (Max, High or Low)
  e = sx1272.setPower('H');
  Serial.println(F("Setting Power: state "));
  Serial.println(e, DEC);
  
  // Set the node address and print the result
  e = sx1272.setNodeAddress(2);
  Serial.println(F("Setting node address: state "));
  Serial.println(e, DEC);
  
  // Print a success message
  Serial.println(F("SX1272 successfully configured"));
}

void loop(void)
{
  
  ldr = analogRead(1);
  get_temp();
  sprintf(message1,"LDR value: %i \r\nNTC value: %i\r\n",ldr,ntc);
  e = sx1272.sendPacketTimeout(3, message1); 
  Serial.println(message1);
  Serial.print(F("Packet sent, state "));
  Serial.println(e, DEC); 

  delay(5000);  

}

void get_temp() {
  ntc = analogRead(0) * 5 / 1024.0;
  ntc = ntc - 0.5;
  ntc = ntc / 0.01;
}

        

Raspberry Pi:

Code:
/*  
 *  LoRa 868 / 915MHz SX1272 Module
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Victor Boria & Luis Miguel Marti
 */
 
// Include the SX1272 and SPI library: 
#include "SX1272.h"

int e;
char message1 [60];
int ldr;
int ntc;
void get_temp();

void setup()
{
  // Print a start message
  printf("SX1272 module and Arduino: receive packets without ACK\n");
  
  // Power ON the module
  sx1272.ON();
  printf("Setting power ON: state ");
  printf("%d\n",e);
   
  // Set transmission mode and print the result
  e = sx1272.setMode(4);
  printf("Setting Mode: state ");
  printf("%d\n",e);
  
  // Select frequency channel
  e = sx1272.setChannel(CH_12_868);
  printf("Setting Channel: state ");
  printf("%d\n",e);
  
  // Select output power (Max, High or Low)
  e = sx1272.setPower('H');
  printf("Setting Power: state ");
  printf("%d\n",e);
  
  // Set the node address and print the result
  e = sx1272.setNodeAddress(2);
  printf("Setting node address: state ");
  printf("%d\n",e);
  
  // Print a success message
  printf("SX1272 successfully configured\n");
}

void loop(void)
{
    ldr = analogRead(1);
    get_temp();
    sprintf(message1,"LDR value: %i \r\nNTC value: %i\r\n",ldr,ntc);
    e = sx1272.sendPacketTimeout(3, message1);
    printf("Packet sent, state ");
    printf("%d\n",e);
    
    delay(5000);
}


void get_temp() {
  ntc = analogRead(0) * 5 / 1024.0;
  ntc = ntc - 0.5;
  ntc = ntc / 0.01;
}

int main (){
	setup();
	while(1){
		loop();
	}
	return (0);
}

        

Intel Galileo:

Code:
/*  
 *  LoRa 868 / 915MHz SX1272 Module
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Victor Boria & Luis Miguel Marti
 */
 
// Include the SX1272 and SPI library: 
#include "SX1272.h"
#include <SPI.h>

int e;
char message1 [60];
int ldr;
int ntc;

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  
  // Power ON the module
  sx1272.ON();
  
  // Set transmission mode and print the result
  e = sx1272.setMode(4);
  Serial.println("Setting Mode: state ");
  Serial.println(e, DEC);
  
  // Select frequency channel
  e = sx1272.setChannel(CH_12_868);
  Serial.println("Setting Channel: state ");
  Serial.println(e, DEC);
  
  // Select output power (Max, High or Low)
  e = sx1272.setPower('H');
  Serial.println("Setting Power: state ");
  Serial.println(e, DEC);
  
  // Set the node address and print the result
  e = sx1272.setNodeAddress(2);
  Serial.println("Setting node address: state ");
  Serial.println(e, DEC);
  
  // Print a success message
  Serial.println("SX1272 successfully configured");
}

void loop(void)
{
  
  ldr = analogRead(1);
  get_temp();
  sprintf(message1,"LDR value: %i \r\nNTC value: %i\r\n",ldr,ntc);
  e = sx1272.sendPacketTimeout(3, message1); 
  Serial.println(message1);
  Serial.print("Packet sent, state ");
  Serial.println(e, DEC); 

  delay(5000);  

}

void get_temp() {
  ntc = analogRead(0) * 5 / 1024.0;
  ntc = ntc - 0.5;
  ntc = ntc / 0.01;
}
        

Links and Documentation

Related Tutorials

Datasheets and Manuals



If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

Know more at:

Get the Starter Kits at: