How LoRa Works: Simple Explanation and Usage
LoRa uses
chirp spread spectrum modulation to send data over long distances with very low power. It works by spreading a signal across a wide frequency band, allowing devices to communicate even with weak signals and interference.Syntax
LoRa communication involves these main parts:
- Spreading Factor (SF): Controls how long the signal spreads, affecting range and speed.
- Bandwidth (BW): The frequency range used for sending data.
- Transmission Power: The strength of the signal sent.
- Frequency: The radio frequency channel used.
These parameters configure how LoRa devices send and receive data.
cpp
LoRa.begin(frequency); LoRa.setSpreadingFactor(SF); LoRa.setSignalBandwidth(BW); LoRa.setTxPower(power);
Example
This example shows how a LoRa device sends a simple message:
cpp
#include <LoRa.h> void setup() { Serial.begin(9600); if (!LoRa.begin(915E6)) { Serial.println("Starting LoRa failed!"); while (1); } LoRa.setSpreadingFactor(7); // Medium range and speed LoRa.setSignalBandwidth(125E3); // 125 kHz bandwidth LoRa.setTxPower(14); // 14 dBm power } void loop() { LoRa.beginPacket(); LoRa.print("Hello LoRa"); LoRa.endPacket(); delay(2000); // Send every 2 seconds }
Output
No direct output; message "Hello LoRa" is sent wirelessly every 2 seconds.
Common Pitfalls
Common mistakes when using LoRa include:
- Setting a very high spreading factor which slows data rate unnecessarily.
- Using incorrect frequency for your region, causing communication failure.
- Ignoring antenna quality, which reduces range significantly.
- Not matching parameters (SF, BW) between sender and receiver.
Always check local regulations for allowed frequencies and power limits.
cpp
/* Wrong: Using unmatched spreading factors */ LoRa.setSpreadingFactor(12); // Sender // Receiver uses SF 7 - will not decode correctly /* Right: Matching spreading factors */ LoRa.setSpreadingFactor(7); // Sender and receiver both use SF 7
Quick Reference
| Parameter | Description | Effect |
|---|---|---|
| Spreading Factor (SF) | Length of chirp signal | Higher SF = longer range, lower speed |
| Bandwidth (BW) | Frequency width used | Wider BW = faster data, less range |
| Transmission Power | Signal strength in dBm | Higher power = longer range, more battery use |
| Frequency | Radio channel in Hz | Must match region and devices |
Key Takeaways
LoRa uses chirp spread spectrum to send data long distances with low power.
Matching spreading factor and bandwidth between devices is essential for communication.
Use correct frequency and power settings based on your region and device needs.
Higher spreading factor increases range but reduces data speed.
Good antenna and proper configuration improve LoRa performance significantly.