Arduino UNO with Ai-Thinker RA-02 SX1278 LoRa Module

ra-02-feature.jpg

A set up guide for sending LoRa data using the Arduino UNO with the RA-02 module by Ai-Thinker.

I’ve seen a few people asking how to set this up in various places. It’s pretty easy once you know how to plug it together and which library to use. I’m using this library https://github.com/sandeepmistry/arduino-LoRa which is available in the Arduino IDE via Sketch > Include Library > Manage Libraries. Search for and then install LoRa by Sandeep Mistry as below.

Lora Library Screen Capture

If you have the same basic RA-02 Module that I bought, it’s going to be pretty tricky to solder connections. The module is 15mm wide so the pads on the back are tiny.

Lora ModuleModule Base

I couldn’t find a breakout board for this so I used one made for an ESP12 that I’d bought (http://cgi.ebay.es/ws/eBayISAPI.dll?item=262907685863). The spacing is the same and the pins I needed are all available.

The video here is a bit long-winded but explains perfectly how to solder this type of module to a breakout board: https://www.youtube.com/watch?v=rGvvwXrv310 My effort isn’t as clean as the video!

The wiring is pretty simple. For background you can read this page about SPI on the Arduino – https://www.arduino.cc/en/Reference/SPI and this page for the wiring the SX1278 https://github.com/sandeepmistry/arduino-LoRa#semtech-sx1276777879-wiring but it’s probably easier to just follow the diagram below.

UNO RA-02 Wiring

The pins on the RA-02 look like this with the board face up and the aerial socket top left.

RA-02 Pins

IMPORTANT ! Before connecting the module to power, install the aerial – push it firmly into place. The chip can be damaged if you try transmitting without the aerial.

Breadboard Wiring

This is how I wired things up. The red and brown wires look similar in the photo so use the diagram above.

Uno Wiring

The wiring on the UNO

When it’s all connected you can try some of the examples (File > Examples > LoRa) to see if things are generally working.

I have a Heltec 32 LoRa Kit set up to receive packets (tutorial coming soon for this board). When I upload the example Sketch ‘LoRaSender’ to the Arduino UNO I see this on the serial output of the Heltec Board.

Serial Output

Which shows that the loop in the Arduino code below is sending data via the SX1278 chip correctly.

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);

  // send packet
  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();

  counter++;

  delay(5000);


19 Replies to “Arduino UNO with Ai-Thinker RA-02 SX1278 LoRa Module”

  1. Mahesh says:

    Thank you for the informative post.
    I am planning to buy this module. So I wanted to ask whether you have tested its range. Does it really work for a distance of 10km?

    1. WordBot says:

      Hi,
      I’ve not tested this module that much but this one https://robotzero.one/winext-sx1278-lora-module/ reached 3km line of sight. I’m going to test longer distances. It’s the same chip as the RA-02 but it comes with a better antenna.
      Here’s a video by another guy with distance tests: https://www.youtube.com/watch?v=adhWIo-7gr4

  2. ChatBot says:

    Hi WordBot,

    I have used ESP32 with SX1278 LoRa Module, applied two similar units – sender and receiver. SX-1278 has a max packet size of 256 bytes with bit rate upto 300 kbps. but it only sends one packet per second. Not sure how to increase number of packets per second.
    I have a data of 1490 bytes that requires 6 packets (iterations)
    Sender end – data rate is 2 packets / second (512 bytes / second)
    Receiver end – data is 1 packet / second (256 bytes / second) second packet is constantly missing.

    Any idea why this happens?

    1. WordBot says:

      Hi,
      Do you have a sketch I could look at and maybe try?

    2. Bjorn says:

      It probably has to do with regulation. There is a duty cycle saying you cannot transmit more than 1 or 0.1% of the time. If you want higher duty cycles you have to look at other frequencies or different standards. Some limitations are form LoRa and some come with the ISM band (or at least that was my understanding of it)

  3. Vladimir says:

    Hi,
    Why you dont use logic level converter 5 – 3.3V to connect 5V Arduino Uno with 3.3V RA-02? Module Ai-Thinker RA-02 have logic level converter inside?

    1. WordBot says:

      Oh.. I’ve realised what you meant. The pins for the communication on the UNO are at 5v so it could fry the ra-02. In my case it all seems OK though but maybe it would fail eventually due to this.

  4. Hendra says:

    Hi, that awesome tutorial, but i try based on your tutorial, it cant work, in the serial monitor “lora sender”
    “starting lora failed”, why ?
    tahankyou

  5. youn says:

    Hi, I test this module. But it range is only 50cm…. I dont know why!!

    1. WordBot says:

      Can you tell me more about your system please?

  6. Ramadhona says:

    Hi, i use same sketch like you, but i use node mcu, why in the serial monitor the sentence not like your tutorial, the sentence like thi : ⸮Uk⸮⸮A⸮LoRa Sender
    ⸮⸮5@⸮< ⸮LoRa Sender
    Ru⸮⸮(⸮⸮⸮⸮LoRa Sender

    1. WordBot says:

      Do you have another device as a receiver to see if the data is being sent?
      I don’t think it’s this but make sure the Sketch and the Serial Monitor have the same baud rate set.

      1. Ramadhona says:

        yes I have, for the sender i use arduino and receiver i use NodeMCU, and i use both of them to lora sender and receiver. The problem is on NodeMCU serial monitor. the NodeMCU can not send data or receive data like your example

      2. Ramadhona says:

        all of skecth, lora sender and lora recive have same baudrate (9600)

  7. Priti says:

    I tried using LoRa sender and receiver code. Sender code seems to work fine. But I am not able to receive data on receiver side. Can anyone suggest, what could be the issue?

  8. Shahid Iqbal says:

    Now I am using two arduino UNO with RA-01 LORA, one Tx and another one as Rx but I see this in the serial monitor “LoRa Sender” and in Rx serial monitor” I am seeing Received packet ” with RSSI -45″ and all that without ‘Hello 1’. Please help me

    1. WordBot says:

      I just tested this with two Unos and two RA-02 (I don’t have RA-01) using the LoRaSender and LoRaReceiver examples for the library in the tutorial and it works fine. The sender Sketch has these lines…

      // send packet
      LoRa.beginPacket();
      LoRa.print(“hello “);
      LoRa.print(counter);
      LoRa.endPacket();

      so you will see something like this…

      Received packet ‘hello 66’ with RSSI -61
      Received packet ‘hello 67’ with RSSI -60
      Received packet ‘hello 68’ with RSSI -61
      Received packet ‘hello 69’ with RSSI -61

      in the serial monitor for the receiving Uno.

Leave a Reply

Your email address will not be published. Required fields are marked *

scroll to top