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

ESP32-Based GPS Tracker with OLED Display and Telegram Integration

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

Circuit Documentation

Summary

This circuit integrates an ESP32 microcontroller with a GPS module and an OLED display to create a GPS tracking system. The ESP32 is responsible for processing GPS data received from the NEO 6M GPS module and displaying the location coordinates on the OLED display. Additionally, the ESP32 is programmed to connect to a WiFi network and send the GPS location data to a Telegram bot. The power supply module provides the necessary voltage to the components.

Component List

ESP32 (30 pin)

1.3" OLED Display Module

GPS NEO 6M

Power Supply

Wiring Details

ESP32 (30 pin)

1.3" OLED Display Module

GPS NEO 6M

Power Supply

Documented Code

ESP32 Microcontroller Code

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <TinyGPS++.h>
#include <WiFi.h>
#include <HTTPClient.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

TinyGPSPlus gps;
#define GPS_RX 27 // RX pin for GPS
#define GPS_TX 26 // TX pin for GPS
HardwareSerial ss(GPS_RX, GPS_TX); // Serial connection for GPS

const char* ssid = "YOUR_SSID"; // Replace with your WiFi SSID
const char* password = "YOUR_PASSWORD"; // Replace with your WiFi password
const String botToken = "YOUR_BOT_TOKEN"; // Replace with your Telegram bot token
const String chatID = "YOUR_CHAT_ID"; // Replace with your chat ID

void setup() {
  Serial.begin(9600);
  ss.begin(9600);
  
  display.begin(SSD1306_I2C_ADDRESS, OLED_RESET);
  display.clearDisplay();
  
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  while (ss.available() > 0) {
    gps.encode(ss.read());
    
    if (gps.location.isUpdated()) {
      String location = "Lat: " + String(gps.location.lat(), 6) + " Lon: " + String(gps.location.lng(), 6);
      sendTelegramMessage(location);
      displayMessage(location);
    }
  }
}

void sendTelegramMessage(String message) {
  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = "https://api.telegram.org/bot" + botToken + "/sendMessage?chat_id=" + chatID + "&text=" + message;
    http.begin(url);
    int httpResponseCode = http.GET();
    if (httpResponseCode > 0) {
      String response = http.getString();
      Serial.println(response);
    }
    http.end();
  }
}

void displayMessage(String message) {
  display.clearDisplay();
  display.setCursor(0, 0);
  display.println(message);
  display.display();
}

This code initializes the ESP32 microcontroller, GPS module, and OLED display. It connects to a WiFi network and sends GPS location updates to a specified Telegram bot. The location is also displayed on the OLED screen. The code is structured with setup and loop functions, typical for Arduino sketches, and includes additional functions for sending messages via Telegram and displaying messages on the OLED.