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

Arduino UNO Based GSM and GPS Tracking System with Motor Control

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based GSM and GPS Tracking System with Motor Control

Circuit Documentation

Summary

The circuit is designed to interface an Arduino UNO with a variety of components including a Neo 6M GPS Module, a SIM800L GSM module, a DC motor with a speed controller, and multiple LEDs and a buzzer for signaling purposes. The Arduino UNO is the central processing unit, controlling the motor's operation, receiving GPS data, and communicating via GSM. The circuit is powered by a 12V 200Ah battery, and a rocker switch is used to control the power supply to the motor driver. The DC motor's speed is regulated by a PWM speed controller, and the L298N motor driver interfaces the motor with the Arduino.

Component List

Wiring Details

Arduino UNO

12V 200Ah Battery

DC 12V PWM Speed Controller

Neo 6M GPS Module

SIM800L

LEDs (Red)

Buzzer

DC Motor

Rocker Switch

L298N DC Motor Driver

Documented Code

#include <SoftwareSerial.h>
#include <TinyGPS++.h>

SoftwareSerial gsmSerial(6, 7);  // TX for GSM, RX for GSM
SoftwareSerial neo(2, 12);       // TX for GPS, RX for GPS
TinyGPSPlus gps;

// Motor and LED pins
int led1 = 11;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int motorEN = 10;
int motorIN1 = 9;
int motorIN2 = 8;

String textMessage = "";
String lati = "";
String longi = "";

// Variables for non-blocking blinking
unsigned long lastBlinkTime = 0;
bool isBlinking = false;

void setup() {
  Serial.begin(9600);
  gsmSerial.begin(9600);
  delay(5000);
  Serial.println("Initializing GSM...");
  gsmSerial.println("AT");
  checkGSMResponse();
  gsmSerial.println("AT+CMGF=1");
  checkGSMResponse();
  gsmSerial.println("AT+CNMI=2,2,0,0,0");
  checkGSMResponse();
  
  neo.begin(9600);

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(motorEN, OUTPUT);
  pinMode(motorIN1, OUTPUT);
  pinMode(motorIN2, OUTPUT);

  analogWrite(motorEN, 0);
  digitalWrite(motorIN1, LOW);
  digitalWrite(motorIN2, LOW);
  Serial.println("System initialized.");
}

void loop() {
  gsmSerial.listen();
  delay(2);

  if (gsmSerial.available() > 0) {
    textMessage = gsmSerial.readString();
    textMessage.trim();
    Serial.println("Received message: " + textMessage);
    
    if (textMessage.indexOf("ON") != -1) {
      handleOnMessage();
    } else if (textMessage.indexOf("OFF") != -1) {
      handleOffMessage();
    } else if (textMessage.indexOf("GETLOC") != -1) {
      handleGetLocMessage();
    }
    textMessage = "";
  }

  blinkLeds34Continuously();
}

void handleOnMessage() {
  Serial.println("Executing ON command");
  digitalWrite(led1, HIGH);
  digitalWrite(motorIN1, HIGH);
  digitalWrite(motorIN2, LOW);
  analogWrite(motorEN, 255);
  stopBlinkingLeds34();
}

void handleOffMessage() {
  Serial.println("Executing OFF command");
  digitalWrite(led1, LOW);
  blinkLED2();
  reduceMotorSpeed();
  startBlinkingLeds34();
}

void blinkLED2() {
  for (int i = 0; i < 5; i++) {
    digitalWrite(led2, HIGH);
    delay(300);
    digitalWrite(led2, LOW);
    delay(300);
  }
}

void reduceMotorSpeed() {
  int reductionDelay = 100;
  int steps = 255 / (10000 / reductionDelay);
  for (int speed = 255; speed >= 0; speed -= steps) {
    analogWrite(motorEN, speed);
    delay(reductionDelay);
  }
  analogWrite(motorEN, 0);
}

void blinkLeds34Continuously() {
  if (!isBlinking) return;

  unsigned long currentMillis = millis();
  if (currentMillis - lastBlinkTime >= 100) {
    lastBlinkTime = currentMillis;
    digitalWrite(led3, !digitalRead(led3));
    digitalWrite(led4, !digitalRead(led4));
  }
}

void startBlinkingLeds34() {
  isBlinking = true;
  lastBlinkTime = millis();
}

void stopBlinkingLeds34() {
  isBlinking = false;
  digitalWrite(led3, LOW);
  digitalWrite(led4, LOW);
}

void handleGetLocMessage() {
  Serial.println("Executing GETLOC command");
  neo.listen();
  smartDelay(1000);
  sendLocationSMS();
}

void sendLocationSMS() {
  gsmSerial.println("AT+CMGS=\"+250728418241\"");
  delay(500);
  String pesan = "https://maps.google.com/?q=" + lati + "," + longi;
  gsmSerial.print(pesan);
  gsmSerial.write(0x1a);
  delay(1000);
  gsmSerial.println("AT+CMGD=1,4");
  Serial.println("Location sent: " + pesan);
}

static void smartDelay(unsigned long ms)