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

Battery-Powered GPS Tracker with SIM800L and Arduino UNO

View and Edit Project In Cirkit DesignerImage of Battery-Powered GPS Tracker with SIM800L and Arduino UNO

Circuit Documentation

Summary

This circuit is designed to read GPS data from a NEO 6M module and send the current location to a designated phone number via a SIM800L module when a button is pressed twice within a short interval. The circuit is controlled by an Arduino UNO microcontroller.

Component List

SIM800L

Arcade Button (white)

Arduino UNO

Battery 18650

Resistor

GPS NEO 6M

Wiring Details

SIM800L

Arcade Button (white)

Arduino UNO

Battery 18650

Resistor

GPS NEO 6M

Code Documentation

/*
 * This Arduino Sketch reads GPS data from a NEO 6M module and sends the current
 * location to a designated phone number via a SIM800L module when a button is
 * pressed twice within a short interval.
 */

#include <SoftwareSerial.h>

// Pin definitions
#define GPS_RX_PIN 3
#define GPS_TX_PIN 4
#define SIM800L_RX_PIN 12
#define SIM800L_TX_PIN 11
#define BUTTON_PIN 5

// Create software serial ports
SoftwareSerial gpsSerial(GPS_TX_PIN, GPS_RX_PIN);
SoftwareSerial sim800lSerial(SIM800L_TX_PIN, SIM800L_RX_PIN);

// Variables for button press detection
unsigned long lastButtonPressTime = 0;
unsigned long buttonPressInterval = 500; // 500 ms
int buttonPressCount = 0;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  gpsSerial.begin(9600);
  sim800lSerial.begin(9600);

  // Initialize button pin
  pinMode(BUTTON_PIN, INPUT);

  // Initialize SIM800L
  initializeSIM800L();
}

void loop() {
  // Check for button press
  if (digitalRead(BUTTON_PIN) == HIGH) {
    unsigned long currentTime = millis();
    if (currentTime - lastButtonPressTime < buttonPressInterval) {
      buttonPressCount++;
    } else {
      buttonPressCount = 1;
    }
    lastButtonPressTime = currentTime;
  }

  // If button is pressed twice, send location
  if (buttonPressCount == 2) {
    String location = getGPSLocation();
    sendLocationSMS(location);
    buttonPressCount = 0;
  }
}

void initializeSIM800L() {
  // Send initialization commands to SIM800L
  sim800lSerial.println("AT");
  delay(1000);
  sim800lSerial.println("AT+CMGF=1"); // Set SMS to text mode
  delay(1000);
}

String getGPSLocation() {
  String gpsData = "";
  while (gpsSerial.available()) {
    char c = gpsSerial.read();
    gpsData += c;
  }
  // Parse GPS data to extract location
  // This is a simplified example, actual parsing will depend on GPS data format
  String latitude = "N/A";
  String longitude = "N/A";
  int latIndex = gpsData.indexOf("$GPGGA");
  if (latIndex != -1) {
    latitude = gpsData.substring(latIndex + 18, latIndex + 27);
    longitude = gpsData.substring(latIndex + 30, latIndex + 40);
  }
  return "Lat: " + latitude + ", Lon: " + longitude;
}

void sendLocationSMS(String location) {
  sim800lSerial.print("AT+CMGS=\"+9779861806001\""); // Replace with actual phone number
  delay(1000);
  sim800lSerial.print(location);
  delay(1000);
  sim800lSerial.write(26); // ASCII code for CTRL+Z to send SMS
  delay(1000);
}

This code initializes the GPS and SIM800L modules, reads GPS data, and sends the location via SMS when the button is pressed twice within a short interval.