Manufaturação industrial
Internet das coisas industrial | Materiais industriais | Manutenção e reparo de equipamentos | Programação industrial |
home  MfgRobots >> Manufaturação industrial >  >> Manufacturing Technology >> Processo de manufatura

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Componentes e Materiais

Componente Quantidade
Arduino Mega 2560 1
Módulo GPS NEO 6 1
Shield SD Card Adafruit 2
Shield GPRS Seeedstudio V2.0 2
Fios jumper (genéricos) 1
Bateria 9V (genérica) 1
Caixa plástica 2

Sobre o Projeto

Há um tempo decidi construir um rastreador veicular/pessoal. Este foi meu primeiro protótipo nessa direção.

O sistema é simples: Arduino Mega, GPS, Shield GPRS e Shield SD Card (opcional, incluí para lançar um desafio aos amigos no Facebook: eles ligam para o número do SIM e recebem SMS com minha posição ou última posição conhecida).

O sistema busca continuamente a posição atual. Se alguém liga para o número do SIM, o sistema envia SMS com a posição atual e link para o Google Maps. Exemplo:

Hugo location is now: Lat: 54.315010, Log: 10.130997. https://maps.google.com/maps?q=54.315010,+10.130997

Se o GPS não estiver recebendo posição, envia a última conhecida:

I can not seem to find Hugo. Last time that I've saw him, was in: Lat: 54.315010, Log: 10.130997. https://maps.google.com/maps?q=54.315010,+10.130997

Data, hora, posição e status do SMS são armazenados no cartão SD.

Componentes

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Conectando os Componentes

Como o Arduino Mega usa pinout diferente, alguns rearranjos são necessários.

Shield SD Card: Projetado para Arduino Uno, usa pinos 10-13 para SPI. No Mega, devem ser redirecionados para pinos SPI do Mega:

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Shield GPRS: Configure jumpers J7 para Software Serial. Conecte pinos 7 e 8 do shield à Serial1 do Mega (pinos 18 e 19).

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS
Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

GPS: Conectado à Serial2 do Mega (pinos 16 e 17). Alimentação do GPS retirada do pino 5V e GND do shield SD.

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Bateria 9V: Conectada ao pino Vin ou ao jack de alimentação.

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS
Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS
Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS
Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Código

Notas rápidas sobre o código:

Funcionamento: após inicialização (GPRS, GPS, SD), o GPS tenta obter satélites e coordenadas válidas. Se ligação recebida durante esse período, a chamada é rejeitada. Quando GPS tem posição válida e ≥3 satélites, uma ligação gera SMS com posição atual. Se <3 satélites, envia última posição conhecida. Tudo gravado no SD.

Prós e Contras

Por ser protótipo, há pontos a melhorar:

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Por favor, reporte erros, sugestões ou dúvidas. Obrigado por ler. – Hugo Gomes

Código

#include "SIM900.h"
#include 
#include "sms.h"
#include "call.h"
#include 
// Para mudar pinos Software/Hardware Serial, veja linhas 27, 28 em GSM.cpp.
// Para usar Arduino Mega, defina MEGA na linha 5 em GSM.h.
#include 
#include 
// Mega CS pin
const int chipSelect = 53;
CallGSM call;
SMSGSM sms;
char number[20];
byte stat = 0;
int value = 0;
char value_str[5];
// Variáveis GPS
TinyGPSPlus gps;
const char *googlePrefix = "https://maps.google.com/maps?q=";
double Lat, Long;
int day, month, year;
int hour, minute, second;
int num_sat;
boolean one_point_true = false;
void setup() {
  Serial.begin(9600);
  Serial.print(F("Starting GSM..."));
  if (gsm.begin(9600)) Serial.println(F("READY"));
  else Serial.println(F("IDLE"));
  Serial.println(F("Starting GPS"));
  Serial2.begin(9600);
  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();
}
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);
  }
}
static void smartDelay(unsigned long ms) {
  unsigned long start = millis();
  do {
    while (Serial2.available()) gps.encode(Serial2.read());
  } while (millis() - start < ms);
}
void Check_call() {
  stat = call.CallStatusWithAuth(number, 0, 0);
  if (stat == CALL_INCOM_VOICE_AUTH) {
    delay(100);
    call.HangUp();
    Send_SMS();
  }
}
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];
  dtostrf(Lat, 5, 6, lat_print);
  char Long_print[10];
  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);
    if (error == 0) Serial.println(F("SMS ERROR"));
    else Serial.println(F("SMS OK"));
  } 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);
    if (error == 0) Serial.println(F("SMS ERROR"));
    else Serial.println(F("SMS OK"));
  } else if (!one_point_true) {
    Serial.println(F("No valid GPS point"));
  }
  // Salva no 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"));
  }
}

Esquemáticos

Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS
Track ME: Rastreador de Carro com Arduino Mega 2560, GPS e GPRS

Processo de manufatura

  1. Construa um Robô Inteligente com a Bridge Shield – Integração Raspberry Pi e Arduino
  2. Sistema de Iluminação DMX Controlado via Web – Controlador Mestre Arduino
  3. Construa um Spybot Controlado por Bluetooth com Arduino
  4. UnifiedWater v1 – Kit Completo de Sensor de Qualidade da Água com Arduino
  5. Relógio HSV: Relógio Vibrante e Personalizável para Entusiastas de Arduino
  6. Robô Limpa-Neve Avançado para Limpeza Eficiente no Inverno
  7. Sistema de Votação Portátil com Conectividade GSM
  8. Jogo Whac-A-Mole Arcade DIY (Edição Botões) – Projeto Arduino
  9. Jukebox Moderna: Raspberry Pi e Arduino com LEDs Reativos à Música
  10. Smartwatch Arduino DIY: Construa Seu Próprio Relógio Estilo Apple Watch