This circuit integrates an ESP8266 NodeMCU microcontroller with a LoRa Ra-02 SX1278 module and a GPS NEO 6M module to create a GPS tracking system that can transmit location data over LoRa communication. The ESP8266 NodeMCU reads GPS data from the GPS NEO 6M module via UART and transmits this information using the LoRa module, which is interfaced using SPI. The circuit is powered by a 3.7v battery connected to the NodeMCU, which also provides power to the GPS and LoRa modules through voltage regulation.
/*
* This Arduino Sketch is for an ESP8266 NodeMCU microcontroller that reads GPS
* data from a GPS NEO 6M module and transmits the location data using a LoRa
* SX1278 Ra-02 module. The GPS data is read via UART and the LoRa module is
* interfaced using SPI.
*/
#include <SPI.h>
#include <LoRa.h>
#include <TinyGPS++.h>
#define NSS 15 // D8
#define RST 16 // D0
#define DIO0 5 // D1
#define GPS_TX 0 // D3
#define GPS_RX 3 // RX
TinyGPSPlus gps;
void setup() {
Serial.begin(9600); // Initialize serial for GPS
while (!Serial);
// Initialize LoRa module
LoRa.setPins(NSS, RST, DIO0);
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
Serial.println("LoRa Initializing OK!");
// Initialize GPS module
Serial1.begin(9600, SERIAL_8N1, GPS_RX, GPS_TX); // Initialize Serial1 for GPS
}
void loop() {
while (Serial1.available() > 0) {
gps.encode(Serial1.read());
if (gps.location.isUpdated()) {
String gpsData = "Lat: " + String(gps.location.lat(), 6) + ", Lon: " + String(gps.location.lng(), 6);
sendLoRaMessage(gpsData);
}
}
}
void sendLoRaMessage(String message) {
LoRa.beginPacket();
LoRa.print(message);
LoRa.endPacket();
Serial.print("Sent: ");
Serial.println(message);
}
This code initializes the ESP8266 NodeMCU to communicate with the GPS module via UART and the LoRa module via SPI. It reads GPS data and sends it over LoRa. The setup()
function initializes serial communication and sets up the LoRa and GPS modules. The loop()
function reads data from the GPS module and sends it via LoRa if the location is updated. The sendLoRaMessage()
function handles the actual transmission of the GPS data over LoRa.