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

Arduino Nano-Based GPS Logger and Proximity Alert System with Vibration Feedback

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based GPS Logger and Proximity Alert System with Vibration Feedback

Circuit Documentation

Summary

This circuit is designed to interface with a variety of components including a neo 6m GPS module, an HC-SR04 Ultrasonic Sensor, a DFPlayer MINI audio module, a Micro SD Card Module, and a Vibration Motor. The primary controller for the circuit is an Arduino Nano, which manages data logging from the GPS to the SD card, distance measurement using the ultrasonic sensor, audio playback through the DFPlayer MINI based on the measured distance, and control of a vibration motor under specific conditions.

Component List

neo 6m GPS

HC-SR04 Ultrasonic Sensor

Voltage Regulator

3.7v LiPo Battery

2Pin Push Switch

Micro SD Card Module

Arduino Nano

Resistor (10k Ohms)

DFPlayer MINI

Vibration Motor

Wiring Details

neo 6m GPS

HC-SR04 Ultrasonic Sensor

Voltage Regulator

3.7v LiPo Battery

2Pin Push Switch

Micro SD Card Module

Arduino Nano

Resistor (10k Ohms)

DFPlayer MINI

Vibration Motor

Documented Code

/*
 * Arduino Nano Circuit Project
 * This code interfaces with a neo 6m GPS, HC-SR04 Ultrasonic Sensor,
 * DFPlayer MINI, Micro SD Card Module, and a Vibration Motor.
 * The GPS data is read and logged to the SD card. The ultrasonic sensor
 * measures distance, and the DFPlayer MINI plays audio based on distance.
 * The vibration motor is activated based on specific conditions.
 */

#include <SoftwareSerial.h>
#include <SD.h>
#include <DFPlayer_Mini_Mp3.h>

// Pin definitions
#define TRIG_PIN 2
#define ECHO_PIN 5
#define GPS_TX_PIN 10
#define GPS_RX_PIN 11
#define SD_CS_PIN A2
#define DFPLAYER_BUSY_PIN A1
#define DFPLAYER_TX_PIN A0
#define DFPLAYER_RX_PIN 13
#define VIBRATION_MOTOR_PIN 9

// Global variables
SoftwareSerial gpsSerial(GPS_RX_PIN, GPS_TX_PIN);
SoftwareSerial dfPlayerSerial(DFPLAYER_RX_PIN, DFPLAYER_TX_PIN);
File logFile;

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

  // Initialize pins
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(SD_CS_PIN, OUTPUT);
  pinMode(VIBRATION_MOTOR_PIN, OUTPUT);

  // Initialize SD card
  if (!SD.begin(SD_CS_PIN)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  logFile = SD.open("log.txt", FILE_WRITE);
  if (!logFile) {
    Serial.println("Failed to open log file!");
    return;
  }

  // Initialize DFPlayer
  mp3_set_serial(dfPlayerSerial);
  mp3_set_volume(20);
}

void loop() {
  // Read GPS data
  if (gpsSerial.available()) {
    String gpsData = gpsSerial.readStringUntil('\n');
    logFile.println(gpsData);
    logFile.flush();
  }

  // Measure distance with HC-SR04
  long duration, distance;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1;

  // Play audio and activate vibration motor based on distance
  if (distance < 10) {
    mp3_play(1);
    digitalWrite(VIBRATION_MOTOR_PIN, HIGH);
  } else {
    digitalWrite(VIBRATION_MOTOR_PIN, LOW);
  }

  delay(1000);
}

This code is designed to be uploaded to an Arduino Nano and assumes that the wiring has been done according to the details provided in the wiring section. The code includes comments that describe the functionality and the purpose of each section, making it easier to understand and modify if necessary.