Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Interfacing LoRa SX1278 with STM32 – Sender & Receiver
IoT Projects LoRa/LoRaWAN Projects STM32 Projects

Interfacing LoRa SX1278 with STM32 – Sender & Receiver

Mamtaz AlamBy Mamtaz AlamUpdated:May 29, 20238 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
STM32 LoRa SX1278
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this tutorial, we will learn Interfacing of LoRa Module SX1278 with STM32 Bluepill Microcontroller. The Ra-02 module uses SX1278 IC and works on a 433MHz frequency. Using the Frequency hopping, it gives the sweet balance of quality signal transmission—will cover a range of 420-450MHz. The LoRa SX1278 works with SPI communication protocol so it can be used with any microcontroller that supports SPI. The SX1278 module can be easily interfaced with the STM32F103 chip.

The tutorial consists of two examples. In the first example, we will send a simple “Hello World” message from LoRa Sender/Transmitter to Receiver. But in the second example, we will send the sensor data wirelessly. The BME280 Barometric Pressure Sensor gives the information of Barometric Pressure, Temperature, Humidity & Approx. Altitude. The STM32 LoRa Sender will send the sensor data to the STM32 LoRa Receiver.

If you are reading this post from the North America region, then you can work with 915MHz LoRa Module SX1276.


Bill of Materials

All the components required for this tutorial are given below along with the purchase link.

S.N.Components NameQuantityPurchase Links
1STM32F103C Microcontroller2Amazon | AliExpress
2LoRa Module SX12782Amazon | AliExpress
3BME280 Sensor1Amazon | AliExpress
45V Power Supply 2Amazon | AliExpress
5Connecting Jumper Wires20Amazon | AliExpress
6Breadboard1Amazon | AliExpress




LoRa Module SX1278

The SX1278 Ra-02 Chip is manufactured by Semtech. The SX1278 RF module is mainly used for long-range spread spectrum communication. It can resist Minimize current consumption & has a high sensitivity of -148 dBm with a power output of +20 dBm. A long transmission distance with almost 5km can be achieved with high reliability. Thus SX1278 is great for IoT applications to send sensor data to the cloud over long ranges.

SX1278 Module

This module uses SX1278 IC from SEMTECH and works on a 433MHz frequency. Frequency hopping—which gives you that sweet balance of quality signal transmission will cover a range of 420-450 MHz. This long-range wireless capability is packed into a small (17 x 16mm) package and delivered without an antenna.


SX1278 Pinout

SX1278 Pinout

Pin 1: ANT – This pin is to attach to the antenna.

Pin 2, 9, 16: GND – Ground pin of common ground with power supply and controllers.

Pin 3: 3.3V – To power up the device pin 3 will help for power input.

Pin 4: RESET – Pin 4 is to reset the module through an external signal.

Pin 5, 6, 7, 8, 10, 11: DIO0, DIO1, DIO2, DIO3, DIO4, DIO5 – To perform the general, I/O function through module the DIO pins will help. These pins is customizable as an interrupt pin.

Pin 12: SCK – SCK pin is for the clock pulse during the SPI communication.

Pin 13: MISO – MISO means Master in and Slave out that transfers data transfer from the Module to the Controller. The Master is a controller & SX1278 is Slave.

Pin 14: MOSI – MOSI means Master out Slave In. So, this pin will receive the data from Controller.

Pin 15: NSS – NSS is a chip select/enable pin will help to activate the slave.




LoRa Frequency Allocation

LoRa frequency is not legal everywhere. I am from India and here the unlicensed Frequency range is from 865MHz to 867MHz. So I am only allowed to use this frequency range. The SX1278 has a frequency of 433MHz so I am not allowed to use it for an extended time aside from for an academic purpose. Similarly, check the allowed Ranges in your country and confirm you’re allowed to use the actual frequency range. LoRa modules do are available different frequency ranges, the foremost common being the 433MHz, 915MHz, and 868MHz.


Interfacing LoRa SX1278 with STM32

Now let us interface LoRa Module SX1278 with STM32F103C Board and make a simple STM32 LoRa Sender Receiver Device. The connection between SX1278 & STM32F103 is as follows:

SX1278 STM32F103C Connection

The schematic is given below. You can assemble the pair of the circuit on the breadboard. One of the circuits will act as a transmitter or sender and the other as a receiver.

Interfacing LoRa SX1278 with STM32


LoRa Library for STM32

The Arduino LoRa Library is not supported by STM32F103 Board. That is why there is a modified library for STM32F103 Board for Arduino IDE. The STM32 LoRa library is used for sending and receiving data using LoRa radios.

This library exposes the LoRa radio directly and allows you to send data to any radios in range with the same radio parameters. All data is broadcasted and there is no addressing.

Download: STM32 LoRa Library


Sender & Receiver Code

Sender Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <SPI.h>
#include <LoRa_STM32.h>
 
#define SS PA4
#define RST PB0
#define DI0 PA1
 
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
 
int counter = 0;
 
void setup() {
  Serial.begin(115200);
  while (!Serial);
 
  Serial.println("LoRa Sender");
 
  LoRa.setTxPower(TX_P);
  LoRa.setSyncWord(ENCRYPT);
  
  LoRa.setPins(SS, RST, DI0);
  if (!LoRa.begin(BAND))
  {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}
 
void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);
 
  // send packet
  LoRa.beginPacket();
  LoRa.print("hello ");
  LoRa.print(counter);
  LoRa.endPacket();
 
  counter++;
 
  delay(5000);
}


Receiver Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <SPI.h>
#include <LoRa_STM32.h>
 
#define SS PA4
#define RST PB0
#define DI0 PA1
 
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
 
void setup()
{
  Serial.begin(115200);
  while (!Serial);
 
  Serial.println("LoRa Receiver");
  LoRa.setTxPower(TX_P);
  LoRa.setSyncWord(ENCRYPT);
  
  LoRa.setPins(SS, RST, DI0);
  if (!LoRa.begin(BAND))
  {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}
 
void loop() {
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");
 
    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
 
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
  }
}

Result


Sending Sensor Data Wirelessly using LoRa Module

Let us go through the second example now. In this example, we will be Interfacing SX1278 with STM32 and BME280 sensor to the Sender Circuit. The BME280 is an integrated environmental sensor developed specifically for mobile applications that have high linearity & accuracy for pressure, humidity and temperature measurements.

STM32F103C LoRa

The Sensor works on I2C Protocol so its I2C Pins, i.e SDA & SCL is connected to PB7 & PB6 respectively. We will send the BME280 Sensor reading wirelessly from STM32 LoRa Sender to STM32 LoRa Receiver.

Check the previous similar project here: Send Sensor Data Wirelessly using LoRa & Arduino



Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the circuit on breadboard and you want PCB for the project, then here is the PCB for you. The PCB Board for the STM32 LoRa SX1278 Sender & Receiver is designed using EasyEDA online Circuit Schematics & PCB designing tool. The image of the Sender PCB is given below.

Similarly the image of the Receiver PCB is given below.

The Gerber File for the PCB is given below. You can simply download the Gerber File and order the PCB from ALLPCB at 1$ only.

  1. Download Gerber File for Sender PCB: Sender PCB
  2. Download Gerber File for Receiver PCB: Receiver PCB

You can use this Gerber file to order high quality PCB for this project. To do that visit the ALLPCB official website by clicking here: https://www.allpcb.com/.

You can now upload the Gerber File by choosing the Quote Now option. From these options, you can choose the Material Type, Dimensions, Quantity, Thickness, Solder Mask Color and other required parameters.

After filling all details, select your country and shipping method. Finally you can place the order.




Source Code/Program

The LoRa SX1278 STM32 Sender and Receiver Code is given below. The Sender Code requires a BME280 Library. Download the BME280 Library from this link: BME280 Library

STM32 LoRa Sender Receiver

Sender Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <Wire.h>
#include <SPI.h>
#include <LoRa_STM32.h>
 
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
 
#define NSS PA4
#define RST PB0
#define DI0 PA1
 
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
 
int counter = 0;
String LoRaMessage = "";
 
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
 
void setup()
{
  Serial.begin(115200);
  while (!Serial);
 
  Serial.println(F("LoRa Sender"));
 
  //LoRa.setTxPower(TX_P);
  LoRa.setSyncWord(ENCRYPT);
  
  LoRa.setPins(NSS, RST, DI0);
  if (!LoRa.begin(BAND))
  {
    Serial.println(F("Starting LoRa failed!"));
    while (1);
  }
  if (!bme.begin(0x76))
  {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
}
 
void loop()
{
  float temperature = bme.readTemperature();
  float pressure = bme.readPressure() / 100.0F;
  float altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  float humidity = bme.readHumidity();
  
  Serial.print(F("Sending packet: "));
  Serial.println(counter);
  
  Serial.print(F("Temperature = "));
  Serial.print(temperature);
  Serial.println(F("*C"));
 
  Serial.print(F("Pressure = "));
  Serial.print(pressure);
  Serial.println(F("hPa"));
 
  Serial.print(F("Approx. Altitude = "));
  Serial.print(altitude);
  Serial.println(F("m"));
 
  Serial.print(F("Humidity = "));
  Serial.print(humidity);
  Serial.println(F("%"));
 
  Serial.println();
 
  LoRaMessage = String(counter) + "/" + String(temperature) + "&" + String(pressure) + "#" + String(altitude) + "@" + String(humidity);
 
  // send packet
  LoRa.beginPacket();
  LoRa.print(LoRaMessage);
  LoRa.endPacket();
 
  counter++;
 
  delay(3000);
}

Receiver Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <SPI.h>
#include <LoRa_STM32.h>
 
#define SS PA4
#define RST PB0
#define DI0 PA1
 
#define TX_P 17
#define BAND 433E6
#define ENCRYPT 0x78
 
  String counter;
  String temperature;
  String pressure;
  String altitude;
  String humidity;
 
void setup()
{
  Serial.begin(115200);
  while (!Serial);
 
  Serial.println("LoRa Receiver");
  //LoRa.setTxPower(TX_P);
  LoRa.setSyncWord(ENCRYPT);
  
  LoRa.setPins(SS, RST, DI0);
  if (!LoRa.begin(BAND))
  {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}
 
void loop() {
  // try to parse packet
  int pos1,pos2,pos3,pos4;
  
  int packetSize = LoRa.parsePacket();
  if (packetSize)
  {
    // received a packet
    Serial.print("Received packet:  ");
    String LoRaData = LoRa.readString();
    Serial.print(LoRaData);
    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }
    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
 
    pos1 = LoRaData.indexOf('/');
    pos2 = LoRaData.indexOf('&');
    pos3 = LoRaData.indexOf('#');
    pos4 = LoRaData.indexOf('@');
 
    counter = LoRaData.substring(0, pos1);
    temperature = LoRaData.substring(pos1+1,pos2);
    pressure = LoRaData.substring(pos2+1,pos3);
    altitude = LoRaData.substring(pos3+1,pos4);
    humidity = LoRaData.substring(pos4+1,LoRaData.length());
 
    
    Serial.print(F("Packet No. = "));
    Serial.println(counter);
    
    Serial.print(F("Temperature = "));
    Serial.print(temperature);
    Serial.println(F("*C"));
  
    Serial.print(F("Pressure = "));
    Serial.print(pressure);
    Serial.println(F("hPa"));
  
    Serial.print(F("Approx. Altitude = "));
    Serial.print(altitude);
    Serial.println(F("m"));
  
    Serial.print(F("Humidity = "));
    Serial.print(humidity);
    Serial.println(F("%"));
    Serial.println();
  }
}

Results

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleHow to Control Stepper Motor with A4988 Driver & Arduino
Next Article Blynk Controlled WS2812B Neopixel LED Strip with NodeMCU

Related Posts

ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

Updated:June 16, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

Updated:June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

Updated:May 10, 20262K
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

Updated:May 2, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

Updated:April 27, 20261K
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

Updated:April 27, 20262K
View 8 Comments

8 Comments

  1. MrNams on September 20, 2021 10:14 PM

    We can encrypt data, but I could not understand how to make receiver to listen to only particular sender,
    I have two transmitter Lora Module transmits some data, consider these as T1 and T2, and one receiver Lora modules R1.
    Here receiver module R1 receives data from both transmitter T1 and T2,
    So how can we make R1 to receive data from only T1?

    Reply
    • Admin on September 20, 2021 10:15 PM

      Assign device address to identify from which receiver the data is being received.

      Reply
  2. MrNams on September 20, 2021 11:06 PM

    Thanks for quick reply, i am new to this world, can you share document link?sample code?

    Reply
    • Arun on April 13, 2024 1:45 PM

      It’s not working I connected same components in same circuit but it’s not working

      Reply
  3. MrNams on September 22, 2021 6:41 PM

    Thanks, i did it at software level.

    Reply
  4. Mirza Yaran on October 23, 2021 2:25 AM

    Hello, can i use this system with ra-01 lora?

    Reply
  5. Mirza Yaran on October 23, 2021 2:26 AM

    can i use this system with lora ra – 01?

    Reply
  6. Arun on April 13, 2024 1:46 PM

    Y it’s not working

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 16, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • How to use ADS1115 16-Bit ADC Module with Arduino
    How to use ADS1115 16-Bit ADC Module with Arduino
  • ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
    ECG Graph Monitoring with AD8232 ECG Sensor & Arduino
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • Interfacing PN532 NFC RFID Module with Arduino
    Interfacing PN532 NFC RFID Module with Arduino
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.