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

Arduino UNO-Based GPS and GSM Controlled Motor System with LED Indicators

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based GPS and GSM Controlled Motor System with LED Indicators

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with various components including a 12V 200Ah battery, a SIM800L GSM module, a Neo 6M GPS module, multiple LEDs, a buzzer, a DC motor, and an L298N DC motor driver. The Arduino UNO controls the components based on received GSM messages and GPS data. The circuit is designed to perform actions such as turning on/off the motor and LEDs, and sending location data via SMS.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. 12V 200Ah Battery

    • Description: Power source for the circuit.
    • Pins: GND, 12V
  3. SIM800L GSM Module

    • Description: GSM module for sending and receiving SMS.
    • Pins: NFT, RING, VCC, DTR, RST, MIC +, RXD, MIC-, TXD, SPK+, GND, SPK-
  4. Neo 6M GPS Module

    • Description: GPS module for obtaining location data.
    • Pins: GND, TX, RX, VCC
  5. LED: Two Pin (red)

    • Description: Red LED for visual indication.
    • Pins: cathode, anode
  6. Buzzer

    • Description: Buzzer for audio indication.
    • Pins: PIN, GND
  7. DC Motor

    • Description: DC motor for mechanical movement.
    • Pins: pin 1, pin 2
  8. L298N DC Motor Driver

    • Description: Motor driver for controlling the DC motor.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB

Wiring Details

Arduino UNO

12V 200Ah Battery

SIM800L GSM Module

Neo 6M GPS Module

LED: Two Pin (red)

Buzzer

DC Motor

L298N DC Motor Driver

Code Documentation

#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(led