Manufactura industrial
Internet industrial de las cosas | Materiales industriales | Mantenimiento y reparación de equipos | Programación industrial |
home  MfgRobots >> Manufactura industrial >  >> Manufacturing Technology >> Proceso de manufactura

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Componentes y materiales

Componente Cantidad Notas
Arduino Mega 2560 1
Módulo GPS NEO 6 1 Muy popular en eBay
Shield tarjeta SD (Adafruit) 1 Para almacenar logs
Shield GPRS Seeedstudio V2.0 1 Comunicación GSM/GPRS
Cables jumper (genéricos) 1 set
Batería 9V 1 Alimentación
Caja/plástico 1 Carcasa

Sobre el proyecto

Hace tiempo decidí construir un rastreador personal/para coche. Este fue mi primer prototipo en esa dirección.

El sistema es muy simple: Arduino Mega, GPS, Shield GPRS y tarjeta SD (opcional, pero la incluí para lanzar un reto a mis amigos en Facebook: llaman al sistema y reciben un SMS con mi posición o mi última posición conocida).

Funcionamiento

El sistema busca constantemente la posición actual. Si alguien llama al número de la tarjeta SIM, el sistema envía un SMS con la posición actual y un enlace a Google Maps. Ejemplo:

Ubicación de Hugo: Lat: 54.315010, Log: 10.130997. https://maps.google.com/maps?q=54.315010,+10.130997

Si el GPS no recibe posición, envía la última conocida:

No puedo localizar a Hugo. Última vez que le vi, estaba en: Lat: 54.315010, Log: 10.130997. https://maps.google.com/maps?q=54.315010,+10.130997

Fecha, hora, posición y estado del SMS se guardan en la tarjeta SD.

Componentes

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Conectar los componentes

Como Arduino Mega usa diferente pinout, hay que recablear:

Shield SD (diseñado para Uno → Mega):

Pines SPI Arduino UNO → Arduino MEGA:

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Shield GPRS:

  1. Configurar pines de comunicación a Software Serial en jumper J7 del shield.
  2. Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS
  3. Conectar pines 7 y 8 del shield GPRS al Serial1 del Mega (pines 18 y 19).
  4. Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Para detalles de tarjeta SIM en GPRS Shield, ver mi otro proyecto en Hackster.

GPS:

Conectado al Serial2 (pines 16 y 17) del Arduino Mega.

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Alimentación del GPS tomada del pin 5V y GND del shield SD.

Alimentación:

Batería 9V al pin Vin o conector jack.

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS
Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS
Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS
Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Código - Notas rápidas

Librería GPRS Shield: Requiere cambios para Arduino Mega:

  1. En GSM.h: comentar #define UNO y descomentar #define MEGA
  2. En HWSerial.h: descomentar #define MEGA

Librería GPS: TinyGPS++

Lógica del programa:

  1. Rutinas de inicio: GPRS, GPS, tarjeta SD
  2. GPS intenta determinar satélites disponibles y coordenadas válidas
  3. Si llaman durante inicio: llamada rechazada automáticamente
  4. Si GPS tiene posición válida y >3 satélites: llamada entrante → SMS con posición actual + log en SD
  5. Si GPS tiene <3 satélites: llamada entrante → SMS con última posición conocida + log en SD

Pros y Contras

Contras (prototipo):

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Por favor, escríbeme si encuentras errores o tienes sugerencias/mejoras/preguntas.

Gracias por leer.
Hugo Gomes

Código

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "call.h"
#include <TinyGPS++.h>
// Para cambiar pines Software/Hardware Serial, usar líneas 27, 28 en GSM.cpp
// Para Arduino Mega definir MEGA en línea 5 de GSM.h
#include <SPI.h>
#include <SD.h>

const int chipSelect = 53; // Pin CS Mega

CallGSM call;
SMSGSM sms;
char number[20];
byte stat = 0;
int value = 0;
char value_str[5];

// Variables GPS
TinyGPSPlus gps;
const char *googlePrefix = "https://maps.google.com/maps?q=";
double Lat, Long;
int day, month, year, hour, minute, second;
int num_sat;
boolean one_point_true = false;

void setup() {
  Serial.begin(9600);
  
  // GPRS
  Serial.print(F("Starting GSM..."));
  if (gsm.begin(9600)) Serial.println(F("READY"));
  else Serial.println(F("IDLE"));
  
  // GPS
  Serial.println(F("Starting GPS"));
  Serial2.begin(9600); // Puerto serie 2 del Mega
  
  // SD Card
  Serial.print(F("Initializing SD card..."));
  pinMode(53, OUTPUT);
  if (!SD.begin(chipSelect)) {
    Serial.println(F("Card failed, or not present"));
    return;
  }
  Serial.println(F("card initialized."));
}

void loop() {
  Get_GPS();
  Check_call();
}

// Obtener posición del GPS
void Get_GPS() {
  while (Serial2.available() > 0)
    if (gps.encode(Serial2.read()))
      num_sat = gps.satellites.value();
  
  if (gps.location.isValid()) {
    Lat = gps.location.lat();
    Long = gps.location.lng();
    if (Lat != 0 && Long != 0) one_point_true = true;
  }
  
  if (gps.date.isValid()) {
    day = gps.date.day();
    month = gps.date.month();
    year = gps.date.year();
  }
  
  if (gps.time.isValid()) {
    hour = gps.time.hour();
    minute = gps.time.minute();
    second = gps.time.second();
  }
  
  smartDelay(500);
  
  if (millis() > 5000 && gps.charsProcessed() < 10) {
    Serial.println(F("No GPS detected: check wiring."));
    while (true);
  }
}

// Delay inteligente que "alimenta" al objeto GPS
static void smartDelay(unsigned long ms) {
  unsigned long start = millis();
  do {
    while (Serial2.available()) gps.encode(Serial2.read());
  } while (millis() - start < ms);
}

// Verificar llamada entrante
void Check_call() {
  stat = call.CallStatusWithAuth(number, 0, 0);
  if (stat == CALL_INCOM_VOICE_AUTH) {
    delay(100);
    call.HangUp(); // Rechazar llamada
    Send_SMS();
  }
}

// Enviar SMS con posición actual o última conocida
void Send_SMS() {
  int error;
  char Date[13];
  sprintf(Date, "%02d/%02d/%04d ", day, month, year);
  char time1[10];
  sprintf(time1, "%02d:%02d:%02d ", hour, minute, second);
  
  delay(100);
  char lat_print[10], Long_print[10];
  dtostrf(Lat, 5, 6, lat_print);
  dtostrf(Long, 5, 6, Long_print);
  
  if (num_sat >= 3 && one_point_true) {
    char sms_OK[160];
    sprintf(sms_OK, "Hugo location is now: Lat: %s, Log: %s. %s%s,+%s\n", 
            lat_print, Long_print, googlePrefix, lat_print, Long_print);
    Serial.println(sms_OK);
    error = sms.SendSMS(number, sms_OK);
    delay(500);
  } else if (num_sat < 3 && one_point_true) {
    char sms_NOK[150];
    sprintf(sms_NOK, "I can not seem to find Hugo. Last time that i've saw him, was in: Lat: %s, Log: %s. %s%s,+%s\n",
            lat_print, Long_print, googlePrefix, lat_print, Long_print);
    Serial.println(sms_NOK);
    error = sms.SendSMS(number, sms_NOK);
  } else if (!one_point_true) {
    Serial.println(F("No valid GPS point"));
    return;
  }
  
  // Guardar en SD
  File dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.print(Date);
    dataFile.print(" ");
    dataFile.print(time1);
    dataFile.print(" ");
    dataFile.print(number);
    dataFile.print(" ");
    dataFile.print(lat_print);
    dataFile.print(", ");
    dataFile.print(Long_print);
    dataFile.print(" ");
    dataFile.print(error);
    dataFile.println();
    dataFile.close();
  } else {
    Serial.println(F("error opening datalog.txt"));
  }
}

Esquemas

Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS
Track ME: Rastreador de Coche Prototipo con Arduino Mega 2560, GPS y GPRS

Proceso de manufactura

  1. Construye un robot inteligente con Bridge Shield – Integración Raspberry Pi y Arduino
  2. Sistema de Iluminación DMX Controlado por Web – Controlador Maestro Arduino
  3. Construye un Spybot controlado por Bluetooth con Arduino
  4. UnifiedWater v1 – Kit completo de sensor de calidad de agua con Arduino
  5. Reloj HSV: Reloj Vibrante y Personalizable para Entusiastas de Arduino
  6. Robot Quitanieve Avanzado para Limpieza Invernal Eficiente
  7. Sistema de votación portátil con conectividad GSM
  8. Juego Arcade Whac-A-Mole DIY (Edición Botones) – Proyecto Arduino
  9. Jukebox Moderna: Reproductor Musical Raspberry Pi + Arduino con LEDs Reactivos
  10. Smartwatch Arduino DIY: Construye tu Propio Reloj Estilo Apple Watch
  11. Muestra Agradecimiento a Conductores Cortéses con Pantalla LED Programable