j'ai essayer ce code, mais il ne fonctionne pas , je reçois tous les sms mais je ne reçois pas la localisation, je veux recevoir un sms de localisation quand la voiture est déverrouillée mais j'arrive pas à intégrer le gps dans le code, [j'utilise ARDUINO UNO , le circuit contient : RFID (lecteur RC522),GPS neo 6m,GSM SIM800L,5 Détecteurs TTP223,mini serrure 12v,relais 5v, mini buzzer ,leds, résistances.]
#include <SPI.h>
#include <MFRC522.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
SoftwareSerial sim(3, 2); // Déclaration de sim comme variable globale
SoftwareSerial gps(A3, A2);
TinyGPSPlus gpsModule;
const int detecteur1 = A5;
const int detecteur2 = A4;
const int detecteur3 = A0;
const int detecteur4 = A1;
const int detecteur5 = 5;
const int ledvert = 8;
const int ledrouge = 4;
const int buzzer = 7;
const int relayPin = 6 ;
int etatPrecedentdetecteur1 = LOW;
int etatPrecedentdetecteur2 = LOW;
int etatPrecedentdetecteur3 = LOW;
int etatPrecedentdetecteur4 = LOW;
int etatPrecedentdetecteur5 = LOW;
String lastKnownLocation = "";
void setup() {
pinMode(detecteur1, INPUT);
pinMode(detecteur2, INPUT);
pinMode(detecteur3, INPUT);
pinMode(detecteur4, INPUT);
pinMode(detecteur5, INPUT);
pinMode(ledvert, OUTPUT);
pinMode(ledrouge, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(relayPin, OUTPUT);
Serial.begin(9600);
sim.begin(9600);
gps.begin(9600);
SPI.begin();
rfid.PCD_Init();
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
Serial.println(F("Utilisation de la clé suivante :"));
}
void loop() {
int etatDetecteur1 = digitalRead(detecteur1);
int etatDetecteur2 = digitalRead(detecteur2);
int etatDetecteur3 = digitalRead(detecteur3);
int etatDetecteur4 = digitalRead(detecteur4);
int etatDetecteur5 = digitalRead(detecteur5);
sim.listen();
if (sim.isListening()) {
Serial.println("sim800l is listening!");
} else {
Serial.println("sim800l is not listening!");
}
if (gps.isListening()) {
Serial.println("gps is listening!");
} else {
Serial.println("gps is not listening!");
}
// Vérification des détecteurs
if (etatDetecteur1 == HIGH || etatDetecteur2 == HIGH || etatDetecteur3 == HIGH || etatDetecteur4 == HIGH) {
for (int i = 0; i < 3; i++) {
digitalWrite(ledrouge, HIGH); // Allume la LED rouge
delay(300);
digitalWrite(ledrouge, LOW); // Éteint la LED rouge
tone(buzzer, 1000); // Émet un son avec le buzzer
delay(300); // Pendant 300 ms
noTone(buzzer); // Arrête le son
delay(300); // Attend 300 ms
}
sendSMS("QUELQU'UN TOUCHE LES PORTES DE LA VOITURE!");
} else {
etatPrecedentdetecteur1 = LOW;
etatPrecedentdetecteur2 = LOW;
etatPrecedentdetecteur3 = LOW;
etatPrecedentdetecteur4 = LOW;
}
// Réinitialisation du module SIM800L
sim.println("ATZ");
delay(1000);
// Vérification du détecteur 5
if (etatDetecteur5 == HIGH ) {
for (int i = 0; i < 3; i++) {
digitalWrite(ledrouge, HIGH); // Allume la LED rouge
delay(300);
digitalWrite(ledrouge, LOW); // Éteint la LED rouge
tone(buzzer, 1000); // Émet un son avec le buzzer
delay(300); // Pendant 300 ms
noTone(buzzer); // Arrête le son
delay(300); // Attend 300 ms
}
sendSMS("QUELQU'UN TOUCHE LA CAMERA DE RECULE DE LA VOITURE!");
} else {
etatPrecedentdetecteur5 = LOW;
}
// Réinitialisation du module SIM800L
sim.println("ATZ");
delay(1000);
// Vérification de la présence d'une carte RFID
if (!rfid.PICC_IsNewCardPresent()) {
return;
}
if (!rfid.PICC_ReadCardSerial()) {
return;
}
Serial.print(F("Type PICC : "));
MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
Serial.println(rfid.PICC_GetTypeName(piccType));
if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && piccType != MFRC522::PICC_TYPE_MIFARE_1K && piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
Serial.println(F("Votre carte n'est pas de type MIFARE Classic."));
return;
}
byte nuidPICC[4];
for (byte i = 0; i < 4; i++) {
nuidPICC[i] = rfid.uid.uidByte[i];
}
while (gps.available() > 0) {
if (gpsModule.encode(gps.read())) {
displayInfo();
}
}
if (nuidPICC[0] == 0x13 && nuidPICC[1] == 0xD6 && nuidPICC[2] == 0x49 && nuidPICC[3] == 0x10) {
digitalWrite(ledvert, HIGH);
digitalWrite(buzzer, HIGH);
delay(500);
digitalWrite(ledvert, LOW);
digitalWrite(buzzer, LOW);
digitalWrite(relayPin, HIGH); // Active le relais pour ouvrir la serrure
delay(2000); // Délai pour éviter la répétition des messages
digitalWrite(relayPin, LOW);
sendSMS("LA VOITURE EST DEVERROUILLEE. Localisation: " + lastKnownLocation);
delay(5000);
} else {
for (int i = 0; i < 5; i++) {
digitalWrite(ledrouge, HIGH);
delay(300);
digitalWrite(ledrouge, LOW);
tone(buzzer, 950);
delay(300);
noTone(buzzer);
delay(300);
}
digitalWrite(relayPin, LOW); // Désactive le relais pour fermer la serrure
delay(2000);
sendSMS("QUELQU'UN ESSAIE DE DEVERROUILLER LA VOITURE!");
delay(5000);
}
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
void sendSMS(String message) {
sim.println("AT");
delay(1000);
if (sim.find("OK")) {
Serial.println("AT OK");
} else {
Serial.println("AT Error");
return;
}
sim.println("AT+CMGF=1");
delay(1000);
if (sim.find("OK")) {
Serial.println("AT+CMGF=1 OK");
} else {
Serial.println("AT+CMGF=1 Error");
return;
}
sim.print("AT+CMGS=\"+\"");
sim.write(0x0D);
delay(1000);
sim.write(0x0A);
delay(1000);
sim.print(message);
sim.write(0x1A);
delay(1000);
}
void displayInfo() {
if (gpsModule.location.isValid()) {
lastKnownLocation = String(gpsModule.location.lat(), 6) + ", " + String(gpsModule.location.lng(), 6);
} else {
lastKnownLocation = "Localisation indisponible";
}
}