Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP8266 NodeMCU with GPS and LoRa Connectivity

Image of ESP8266 NodeMCU with GPS and LoRa Connectivity

Circuit Documentation

Summary

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.

Component List

ESP8266 NodeMCU

  • Microcontroller with WiFi capability
  • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN

LoRa Ra-02 SX1278

  • Long Range (LoRa) transceiver module
  • Pins: GND, NSS, MOSI, MISO, SCK, D105, DI04, 3.3V, RST, DI00, DI01, D102, DI03

GPS NEO 6M

  • GPS module for location tracking
  • Pins: VCC, RX, TX, GND

3.7v Battery

  • Power source for the circuit
  • Pins: +, -

GND

  • Common ground reference point
  • Pins: GND

Wiring Details

ESP8266 NodeMCU

  • D0 connected to LoRa Ra-02 SX1278 RST
  • D1 connected to LoRa Ra-02 SX1278 DI00
  • D2 connected to LoRa Ra-02 SX1278 DI01
  • D3 connected to GPS NEO 6M TX
  • D5 connected to LoRa Ra-02 SX1278 SCK
  • D6 connected to LoRa Ra-02 SX1278 MISO
  • D7 connected to LoRa Ra-02 SX1278 MOSI
  • D8 connected to LoRa Ra-02 SX1278 NSS
  • GND connected to LoRa Ra-02 SX1278 GND, GPS NEO 6M GND, and 3.7v Battery -
  • 3V3 connected to LoRa Ra-02 SX1278 3.3V and GPS NEO 6M VCC
  • VIN connected to 3.7v Battery +

LoRa Ra-02 SX1278

  • GND connected to ESP8266 NodeMCU GND
  • NSS connected to ESP8266 NodeMCU D8
  • MOSI connected to ESP8266 NodeMCU D7
  • MISO connected to ESP8266 NodeMCU D6
  • SCK connected to ESP8266 NodeMCU D5
  • RST connected to ESP8266 NodeMCU D0
  • DI00 connected to ESP8266 NodeMCU D1
  • 3.3V connected to ESP8266 NodeMCU 3V3

GPS NEO 6M

  • VCC connected to ESP8266 NodeMCU 3V3
  • RX not connected in this configuration
  • TX connected to ESP8266 NodeMCU D3
  • GND connected to ESP8266 NodeMCU GND

3.7v Battery

    • connected to ESP8266 NodeMCU VIN
    • connected to ESP8266 NodeMCU GND

Documented Code

/*
 * 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.