This circuit is designed to interface a GPS module and a GSM module with an Arduino Nano microcontroller. It includes functionality for receiving GPS data, sending SMS messages, and making calls. The circuit also features two pushbuttons with pull-up resistors and a power supply section that includes a LiPoly battery, a charger module, and a buck converter to regulate the voltage.
D0/RX
connected to TX
of GPS NEO 6MD6
connected to MIC+
of SIM800c GSM ModuleD7
connected to MIC-
of SIM800c GSM ModuleD10
connected to one pushbutton and a 10k resistorD11/MOSI
connected to another pushbutton and a 10k resistorGND
connected to the common ground net5V
connected to the power supply netTX
connected to D0/RX
of Arduino NanoGND
connected to the common ground netVCC
connected to the power supply netRING
connected to a 10k resistor and the common ground netMIC+
connected to D6
of Arduino NanoMIC-
connected to D7
of Arduino NanoSPK-
connected to the power supply netD10
or D11/MOSI
of Arduino NanoOUT-
connected to the common ground netOUT+
connected to the power supply netIN+
connected to OUT+
of LiPo Battery Charger ModuleIN-
connected to OUT-
of LiPo Battery Charger Modulepositive
connected to B+
of LiPo Battery Charger Modulenegative
connected to B-
of LiPo Battery Charger ModuleB+
connected to positive
of LiPoly BatteryB-
connected to negative
of LiPoly BatteryOUT+
connected to IN+
of LM2956 Buck ConverterOUT-
connected to IN-
of LM2956 Buck Converter#include <TinyGPS++.h>
#include <SoftwareSerial.h>
TinyGPSPlus gps; // Use TinyGPSPlus class
SoftwareSerial Gsm(6, 7); // GSM module connected to pins 6 (RX) and 7 (TX)
char phone_no[] = "+91xxxxxxxxxx"; // Replace with actual phone number
int buttonPin = 10; // Button pin
int state;
String textMessage;
void setup() {
Serial.begin(9600); // For GPS module
Gsm.begin(9600); // For SIM800L GSM module
// Set GSM to text mode and configure SMS reception
Gsm.print("AT+CMGF=1\r");
delay(100);
Gsm.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
pinMode(buttonPin, INPUT); // Button input
enterIdleMode(); // Start in idle mode
}
void loop() {
state = digitalRead(buttonPin); // Check if button is pressed
if (state == LOW) { // If button is pressed
wakeUp(); // Exit idle mode
sendEmergencyAlert(); // Send alert and call
enterIdleMode(); // Return to idle mode after task completion
}
if (Gsm.available() > 0) { // If an SMS is received
textMessage = Gsm.readString();
textMessage.toUpperCase(); // Convert text to uppercase for case-insensitive comparison
if (textMessage.indexOf("SEND LOCATION") >= 0) { // If "SEND LOCATION" command is received
wakeUp(); // Exit idle mode
sendLocation(); // Send current location
enterIdleMode(); // Return to idle mode
}
}
}
void sendEmergencyAlert() {
if (getGPSData()) { // If GPS data is valid
Gsm.print("AT+CMGF=1\r");
delay(400);
Gsm.print("AT+CMGS=\"");
Gsm.print(phone_no);
Gsm.println("\"");
Gsm.println("Alert! I need help.");
Gsm.print("http://maps.google.com/maps?q=loc:");
Gsm.print(gps.location.lat(), 6); // Latitude
Gsm.print(",");
Gsm.print(gps.location.lng(), 6); // Longitude
delay(200);
Gsm.println((char)26); // End of SMS
delay(200);
Serial.println("Emergency SMS Sent");
// Make an emergency call
Serial.println("Calling...");
Gsm.println("ATD+91xxxxxxxxxx;"); // Replace with actual phone number
delay(20000); // 20 seconds call duration
Gsm.println("ATH"); // Hang up the call
delay(1000);
} else {
Serial.println("Failed to get GPS data.");
}
}
void sendLocation() {
if (getGPSData()) { // If GPS data is valid
Gsm.print("AT+CMGF=1\r");
delay(400);
Gsm.print("AT+CMGS=\"");
Gsm.print(phone_no);
Gsm.println("\"");
Gsm.println("Here is my current location:");
Gsm.print("http://maps.google.com/maps?q=loc:");
Gsm.print(gps.location.lat(), 6); // Latitude
Gsm.print(",");
Gsm.print(gps.location.lng(), 6); // Longitude
delay(200);
Gsm.println((char)26); // End of SMS
delay(200);
Serial.println("Location SMS Sent");
} else {
Serial.println("Failed to get GPS data.");
}
}
bool getGPSData() {
bool newData = false;
unsigned long start = millis();
while (millis() - start < 10000) { // Retry for 10 seconds
while (Serial.available()) {
char c = Serial.read();
gps.encode(c); // Process GPS data
if (gps.location.isUpdated()) {
newData = true; // New GPS data received
}
}
}
if (!newData) {
Serial.println("GPS fix failed.");
}
return newData;
}
void enterIdleMode() {
// Code to reduce power consumption (e.g., disabling unused peripherals)
Serial.println("Entering idle mode...");
delay(100);
}
void wakeUp() {
// Code to re-enable peripherals and prepare for operation
Serial.println("Waking up from idle mode...");
delay(100);
}
This code is designed to run on the Arduino Nano and provides the logic for the circuit's operation. It includes functions for sending emergency alerts, sending the current location, and managing power consumption modes. The code uses the TinyGPS++ library to parse GPS data and the SoftwareSerial library to communicate with the GSM module.