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

RA-02

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


36 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.

  9. Dave says:

    Hi

    I bought this module but it shipped with no antenna. I already bought wrong antenna. What kind of antenna can i buy for this?

  10. S.KARTHIK says:

    the code doesn’t works….it shows some error like the counter was not declared in the scope

    1. WordBot says:

      You need to use the whole example code in File > Examples > LoRa > LoRaSender . Not just paste the part I highlighted.

  11. Yanle says:

    Thanks, I was wondering if you tested with temperature sensor?

    1. WordBot says:

      Nope but it shouldn’t be too hard to put the value from the sensor in the loop replacing
      LoRa.print(“hello “);
      with
      LoRa.print(SensorValue);

  12. Ditto says:

    Hi WordBot,

    Thanks for the tutorial and it worked for me. However i want to step up, i have a kinect sensor and i want to send its data through LoRa. How can i do it? i planned to send 4 types of data is it even possible?

    1. WordBot says:

      How are you connecting to the Kinect? I think you’ll need to get the data from a PC to the Arduino somehow – https://www.instructables.com/id/Kinect-controls-Arduino-wired-Servos-using-Visual-/

      1. Ditto says:

        Yep that’s done already, i have acquired two types of data from the kinect sensor. However i am still confused of how to receive these two data separately. Maybe you have a solution?

        1. WordBot says:

          If the data is always the same length you can send it as one string and at the other end use https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/substring/ to extract the relevant parts into variables. If the data is different lengths you can create one string but with delimiters -https://en.wikipedia.org/wiki/Delimiter-separated_values and extract the relevant parts when you receive it. This is tricky but this might help – https://forum.arduino.cc/index.php?topic=387175.0

  13. javier says:

    Did you burn the module by not using logic level converter 3.3 volt to 5 volt? arduino one works with 5 volt logic, not 3.3 volt.

    1. WordBot says:

      It was OK for me and I did quite a lot of testing but for long term it would be better to use the logic level converter to be sure.

  14. Rudi says:

    == Corruption when multiple senders send at the same time. ==
    Nice simple example of how to wire lora ra-02 Arduino all up.
    Works perfectly with one sender and one received.

    However when I have more than 1 senders they seem to clash and receiver received garbage?

    1. WordBot says:

      This is really simple example to get going. If you want to do more with this you probably want to look at LoraWan which is network version of Lora. You could also look at having the second sender on a different frequency but I’m not sure how to do that. Lots of advice in the issues from the Github of the library used – https://github.com/sandeepmistry/arduino-LoRa/issues

  15. VIKAS says:

    HELLO CAN I SEND DATA FROM SINGLE TRANSMITTER TO MULTIPLE RECIEVER SET OF LORA??

    1. WordBot says:

      Hi, I think so. The transmitter just transmits like a radio and any receivers in range will pick it up.

  16. Jakub says:

    Hi thank you for your article!
    It works very well, but from some reason pin 11 is set to HIGH for ever. I have only copied and paste your scetch and LED connected to GND and pin 11 is still lighting 🙂 I can not switch it to LOW so I can not use it for another function. Any explanation of it? Any idea how to get rid of it?

    1. WordBot says:

      Hi, Did you try with another sketch? Maybe the blank one or blink? I saw this: https://forum.arduino.cc/index.php?topic=27196.0

  17. Jakub says:

    Maybe I have now an answer. Your proposal works well, but if I add only a library and setup for LoRa, than pin 11 is again High. Pin 12, 13 as well. Maybe it is becase MOSI can be connected to pin 11 or ICSP-4, MISO to pin 12 or ICSP-1 and SCK to pin 13 or ICSP-3. So it seems to me, that 11, 12, 13 are occupied even if LoRa is connected to SPI. If I am right, than it is a pitty and I need arduino mega.

    1. WordBot says:

      Ah, that makes sense. I don’t do anything with the Arduino boards these days. What else did you want to connect to the board?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

scroll to top