Arduino UNO-Based Ultrasonic and GPS Tracking System with GSM Alert
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit that integrates an Arduino UNO microcontroller with various sensors and modules, including two HC-SR04 Ultrasonic Sensors, a GPS NEO 6M module, and a GSM SIM900 module. The circuit is designed to measure distances, obtain GPS coordinates, and send data via GSM.
Component List
Arduino UNO
- Description: A 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
HC-SR04 Ultrasonic Sensor (1)
- Description: An ultrasonic sensor used for distance measurement.
- Pins: VCC, TRIG, ECHO, GND
HC-SR04 Ultrasonic Sensor (2)
- Description: An ultrasonic sensor used for distance measurement.
- Pins: VCC, TRIG, ECHO, GND
GPS NEO 6M
- Description: A GPS module used for obtaining geographic coordinates.
- Pins: VCC, RX, TX, GND
GSM SIM900
- Description: A GSM module used for sending data over a cellular network.
- Pins: A5, A4, A3, A2, A1, A0, 5V, GND, 3.3V, RESET, D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, AREF
Wiring Details
Arduino UNO
- 5V: Connected to VCC of both HC-SR04 Ultrasonic Sensors, VCC of GPS NEO 6M, and 5V of GSM SIM900.
- GND: Connected to GND of both HC-SR04 Ultrasonic Sensors, GND of GPS NEO 6M, and GND of GSM SIM900.
- D13: Connected to ECHO of HC-SR04 Ultrasonic Sensor (1).
- D12: Connected to TRIG of HC-SR04 Ultrasonic Sensor (1).
- D11: Connected to ECHO of HC-SR04 Ultrasonic Sensor (2).
- D10: Connected to TRIG of HC-SR04 Ultrasonic Sensor (2).
- D9: Connected to D9 of GSM SIM900.
- D5: Connected to RX of GPS NEO 6M.
- D4: Connected to TX of GPS NEO 6M.
HC-SR04 Ultrasonic Sensor (1)
- VCC: Connected to 5V of Arduino UNO.
- TRIG: Connected to D12 of Arduino UNO.
- ECHO: Connected to D13 of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
HC-SR04 Ultrasonic Sensor (2)
- VCC: Connected to 5V of Arduino UNO.
- TRIG: Connected to D10 of Arduino UNO.
- ECHO: Connected to D11 of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
GPS NEO 6M
- VCC: Connected to 5V of Arduino UNO.
- RX: Connected to D5 of Arduino UNO.
- TX: Connected to D4 of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
GSM SIM900
- 5V: Connected to 5V of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- D9: Connected to D9 of Arduino UNO.
Code Documentation
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 2);
#define trigPin 8
#define echoPin 9
int redled = 13;
void setup() {
randomSeed(analogRead(0));
Serial.begin(9600);
mySerial.begin(9600); // original 19200. while enter 9600 for sim900A
Serial.println(" logging time completed!");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redled, OUTPUT);
digitalWrite(redled, LOW);
delay(100);
}
void loop() {
long time_duration, distance_in_cm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
time_duration = pulseIn(echoPin, HIGH);
distance_in_cm = time_duration / 29 / 2;
Serial.print(distance_in_cm);
Serial.println(" cm");
// Ranging Distance − 2cm – 400 cm
// if the distance is equal or more then 10 cm
if (distance_in_cm >= 10) {
digitalWrite(redled, HIGH);
Serial.println("Motion detected!");
Serial.println("calling....");
mySerial.println("AT"); // Once the handshake test is successful, it will back to OK
updateSerial();
mySerial.println("ATD+ +251712973006;"); // change ZZ with country code and xxxxxxxxxxx with phone number to dial
updateSerial();
delay(30000); // wait for 30 seconds...
mySerial.println("ATH"); // hang up
updateSerial();
delay(3000);
} else {
digitalWrite(redled, LOW);
}
}
void updateSerial() {
delay(500);
while (Serial.available()) {
mySerial.write(Serial.read()); // Forward what Serial received to Software Serial Port
}
while (mySerial.available()) {
Serial.write(mySerial.read()); // Forward what Software Serial received to Serial Port
}
}
This code initializes the Arduino UNO to interface with the HC-SR04 Ultrasonic Sensors, GPS NEO 6M, and GSM SIM900. It measures distance using the ultrasonic sensors and sends an alert via GSM if the distance exceeds a certain threshold.