Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based GPS Tracker with OLED Display and Firebase Integration

View and Edit Project In Cirkit DesignerImage of ESP32-Based GPS Tracker with OLED Display and Firebase Integration

Circuit Documentation

Summary

This document provides a detailed overview of a circuit that integrates an ESP32 microcontroller with various sensors and modules, including an OLED display, MPU6050 accelerometer, GPS module, buzzer, toggle switch, and a lithium-ion battery charger. The circuit is designed to collect and transmit GPS data to Firebase using WiFi.

Component List

  1. ESP32 (30 pin)

    • Description: A powerful microcontroller with built-in WiFi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  2. 0.96" OLED

    • Description: A small OLED display for visual output.
    • Pins: GND, VDD, SCK, SDA
  3. 18650 Lithium Ion Charger

    • Description: A charger module for 18650 lithium-ion batteries.
    • Pins: V IN, GND, OUT, IN, BAT IN, BAT GND
  4. 2000mAh Battery

    • Description: A rechargeable 2000mAh lithium-ion battery.
    • Pins: VCC, GND
  5. InvenSense MPU6050

    • Description: A 6-axis accelerometer and gyroscope sensor.
    • Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
  6. GPS NEO-6M V2

    • Description: A GPS module for location tracking.
    • Pins: VCC, RX, TX, GND
  7. Buzzer

    • Description: An audio signaling device.
    • Pins: PIN, GND
  8. Toggle Switch

    • Description: A switch to control the power state.
    • Pins: Vcc, Sig, Gnd

Wiring Details

ESP32 (30 pin)

0.96" OLED

18650 Lithium Ion Charger

2000mAh Battery

InvenSense MPU6050

GPS NEO-6M V2

Buzzer

Toggle Switch

Documented Code

#include <TinyGPS++.h>
#include <FirebaseESP32.h>
#include <WiFi.h>

// Firebase project credentials
FirebaseConfig firebaseConfig;
FirebaseAuth firebaseAuth;

// WiFi credentials
#define WIFI_SSID "VITAP-HOSTEL2"
#define WIFI_PASSWORD "1234"

// Define the UART interface for NEO-6M GPS
HardwareSerial GPS_Serial(1);  // Use Serial1 for GPS communication

TinyGPSPlus gps;
FirebaseData firebaseData;

void setup() {
  Serial.begin(115200);
  
  // Start the GPS Serial communication
  GPS_Serial.begin(9600, SERIAL_8N1, 16, 17);  // GPS on pins 16 (RX), 17 (TX)
  
  // Connect to WiFi
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi!");

  // Set up Firebase credentials
  firebaseConfig.host = "ecspro-268aa.firebaseapp.com";
  firebaseConfig.api_key = "AIzaSyA5uZccOcy9Lsm-3qJspgJ38KemMe5G54w";
  firebaseAuth.user.email = "mrdonxy1977@gmail.com";
  firebaseAuth.user.password = "don25232534x@";

  // Connect to Firebase
  Firebase.begin(&firebaseConfig, &firebaseAuth);
  Firebase.reconnectWiFi(true);
}

void loop() {
  while (GPS_Serial.available() > 0) {
    if (gps.encode(GPS_Serial.read())) {
      // If new GPS data is available
      if (gps.location.isValid()) {
        float latitude = gps.location.lat();
        float longitude = gps.location.lng();
        
        Serial.print("Latitude: ");
        Serial.println(latitude);
        Serial.print("Longitude: ");
        Serial.println(longitude);

        // Update the location in Firebase
        String path = "/patients/patient1/location";
        FirebaseJson json;
        json.set("latitude", latitude);
        json.set("longitude", longitude);
        
        if (Firebase.updateNode(firebaseData, path, json)) {
          Serial.println("Location updated successfully in Firebase.");
        } else {
          Serial.println("Failed to update location in Firebase: " + firebaseData.errorReason());
        }
      }
    }
  }
}

This code initializes the ESP32 to read GPS data from the NEO-6M module and upload the location data to Firebase. The ESP32 connects to a WiFi network and uses the Firebase ESP32 library to handle Firebase operations.