0% found this document useful (0 votes)
2 views

Code Balise

Uploaded by

Camille BINAZON
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Code Balise

Uploaded by

Camille BINAZON
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

#include <SoftwareSerial.

h>

#include <Keypad.h>

#include <SPI.h>

#include <LiquidCrystal_I2C.h>

#include <TinyGPS++.h>

#include <TinyGPSPlus.h>

const byte ROWS = 4; //four rows

const byte COLS = 4; //three columns

char Tab_Pass[12] = {};

char Num_Pass[12] = {};

String Num_Prec;

char key;

byte i, j;

boolean remote, ctrl, val, def, appel, loc, envoi_SMS, etat_VBR, com;

byte call;

unsigned long tB, tA, tH;

float Latitude, Longitude, Vitesse;

char keys[ROWS][COLS] = {

{'D', '#', '0', '*'},

{'C', '9', '8', '7'},

{'B', '6', '5', '4'},

{'A', '3', '2', '1'}

};

byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad

byte colPins[COLS] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad

#define VIB 13

//Create an object of keypad

TinyGPSPlus Gps;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

LiquidCrystal_I2C lcd (0x27, 16, 2);

SoftwareSerial gsm(11, 10);

void receive_data_GPS() {

if (Serial.available() > 0) {

if (Gps.encode(Serial.read())) {

if (Gps.location.isValid()) {

loc = 1;

Latitude = Gps.location.lat();

Longitude = Gps.location.lng();

Vitesse = Gps.speed.value();

} else {

loc = 0;

void sendSMS() {

if (envoi_SMS == 1) {

gsm.println("AT+CMGF=1");

delay(50);

gsm.println("AT+CMGS=\"+22901" + String(Num_Pass) + "\"" ); // Numéro de correspondant

delay(50);

lcd.setCursor(2, 0);

lcd.print("Sending...");

lcd.setCursor(4, 1);

lcd.print(Num_Pass);

Num_Prec = Num_Pass;

gsm.print("INFO BALISE\n");
gsm.print("Location: ");

if (loc == 1) {

gsm.println(" https://maps.google.com/maps/place/" + String(Latitude, 6) + "," +


String(Longitude, 6));

} else {

gsm.print("No available");

delay(50);

gsm.write(26);

delay(2000);

envoi_SMS = 0;

call = 4;

void setup() {

Serial.begin(9600);

gsm.begin(9600);

delay(100);

pinMode(VIB, OUTPUT);

gsm.println("AT+CMGF=1");

delay(500);

gsm.println("AT+CNMI=1,2,0,0,0");

delay(500);

lcd.init();

lcd.backlight();

lcd.clear();

delay(100);

digitalWrite(VIB, LOW);

i = 0;

remote = 0;

ctrl = 0;
val = 0;

call = 0;

def = 0;

appel = 0;

envoi_SMS = 0;

com = 1;

void loop() {

receive_data_GPS();

key = keypad.getKey();// Read the key

if (key != NO_KEY) {

switch (call) {

case 0:

if (key == 'C') {

com = !com;

if (key != 'D') {

if (key == 'A') {

if (i >= 0) {

i--;

if (i > 15) i = 0;

Num_Pass[i] = 0;

lcd.setCursor(i + 4, 1);

lcd.print(' ');

} else {

if (key == 'B') {

if (Num_Prec == 0) {

lcd.setCursor(4, 1);

lcd.print("No data.");
delay(1000);

call = 4;

i = 0;

j = 0;

} else {

for (byte i = 0; i < 8; i++) {

Num_Pass[i] = Num_Prec[i];

delay(100);

lcd.setCursor(i + 4, 1);

lcd.print(Num_Pass[i]);

j = i;

} else {

if (key != 'C') {

lcd.setCursor(i + 4, 1);

lcd.print(key);

Num_Pass[i] = key;

i++;

j = i;

} else {

i = 0;

j = 0;

lcd.clear();

if (com == 1) {

//Serial.println("ATD+ +229" + String(Num_Pass) + ";");

gsm.println("ATD+ +22901" + String(Num_Pass) + ";");

tA = millis();
Num_Prec = Num_Pass;

while (call == 0) {

while (gsm.available()) {

String rep = gsm.readString();

Serial.println(rep);

if (rep.indexOf("OK") != -1) {

call = 3;

def = 0;

} else if (rep.indexOf("ERROR") != -1) {

lcd.clear();

lcd.setCursor(1, 0);

lcd.print(" Calling. LOST! ");

delay(1000);

call = 4;

def = 0;

if (millis() - tA > 2000) {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print(" Default GSM! ");

delay(1000);

call = 4;

} else {

envoi_SMS = 1;

sendSMS();

break;
case 1:

if (key == 'D') {

gsm.println("ATH");

call = 4;

appel = 0;

} else if (key == 'E') {

gsm.println("ATA");

call = 4;

appel = 1;

break;

case 2:

if (key == 'D') {

gsm.println("ATH");

call = 4;

appel = 0;

break;

case 3:

if (key == 'D') {

gsm.println("ATH");

call = 4;

appel = 0;

break;

switch (call) {

case 0:

lcd.setCursor(0, 0);

lcd.print(" Input Tel. ");


if (com == 1) {

lcd.print("A");

} else {

lcd.print("M");

if (gsm.available() > 0) {

String rep0 = gsm.readString();

//Serial.println(rep);

if (rep0.indexOf("RING") != -1) {

lcd.clear();

call = 1;

break;

case 1:

lcd.setCursor(0, 0);

lcd.print(" Ring... ");

if (gsm.available() > 0) {

String rep1 = gsm.readString();

//Serial.println(rep);

if (rep1.indexOf("OK") != -1 || rep1.indexOf("NO CARRIER") != -1) {

if (appel == 0) {

call = 4;

lcd.clear();

} else {

call = 2;

lcd.clear();

appel = 0;

}
break;

case 2:

lcd.setCursor(0, 0);

lcd.print(" Dial... ");

if (gsm.available() > 0) {

String rep2 = gsm.readString();

//Serial.println(rep);

if (rep2.indexOf("OK") != -1 || rep2.indexOf("NO CARRIER") != -1) {

if (appel == 0) {

call = 4;

lcd.clear();

break;

case 3:

lcd.setCursor(2, 0);

lcd.print("Calling...");

lcd.setCursor(4, 1);

lcd.print(Num_Pass);

if (gsm.available() > 0) {

String rep3 = gsm.readString();

if (rep3.indexOf("OK") != -1 || rep3.indexOf("NO CARRIER") != -1) {

//memset(Num_Pass, 0, sizeof(Num_Pass));

if (appel == 0) {

call = 4;

break;

case 4:
lcd.clear();

memset(Num_Pass, 0, sizeof(Num_Pass));

call = 0;

break;

You might also like