Résultats du mini-rojet parking


Liens vers les comptes rendus élèves
Code du résultat final
Exported from Notepad++
/***********************************************************************************************************
* Didier Petitjean le 06/05/2017
* Mini-projet : récupération d'une maquette de parking
* 1er SSI Lycée Deck sujet : http://jod.petitjean.free.fr/page.php?id=356
* Bibliothèque inséré :
* keypad.h : http://www.mon-club-elec.fr/pmwiki_reference_arduino/pmwiki.php?n=Main.LibrairieKeypad
* PmodCls.h : http://www.arduinolibraries.info/libraries/pmod-cls
* connexion : http://www.mouser.com/ds/2/690/PmodCLS_rm_RevD-E_1-466173.pdf
* RFID.h : http://www.instructables.com/id/Interfacing-RFID-RC522-With-Arduino-MEGA-a-Simple-/
* Connexion :
* Interrupteur : https://www.arduino.cc/en/Tutorial/DigitalReadSerial
* Servo moteur : https://www.carnetdumaker.net/articles/controler-un-servomoteur-avec-une-carte-arduino-genuino/
* Ultra-son : http://www.instructables.com/id/Simple-Arduino-and-HC-SR04-Example/
*************************************************************************************************************/
#include
#include
#include
#include
#include
#define CODE "1234"
#define OUVERTURE "Ouverture "
#define FERMETURE "Fermeture "
#define INVITE "Entrez le code"
#define ERREURCODE "Mauvais code"
#define DETECTE "Carte detectee"
#define PARKINGPLEIN "Parking complet"
#define PASSAGEVOITURE 2000 //temps de passage d'une voiture sous la barrière
#define MAXVOITURE 4 // Nombre de voitures possibles dans le parking
#define DSTOBSTACLE 10 // Distance en cm pour la fermeture de la barriere
#define BARRIEREENTREE true
#define BARRIERESORTIE false
/***** Constantes clavier ***************/
#define PINLIGNECLAVIER1 22
#define PINLIGNECLAVIER2 24
#define PINLIGNECLAVIER3 26
#define PINLIGNECLAVIER4 28
#define PINCOLONNECLAVIER1 30
#define PINCOLONNECLAVIER2 32
#define PINCOLONNECLAVIER3 34
#define PINCOLONNECLAVIER4 36
#define NBLIGNES 4 // Nombre de lignes
#define NBCOLONNES 4 // Nombre de colonnes
/*************************************************/
#define PINDONNEEECRAN 1 // RX de l'écran J2 : pin4 ==> RX, pin5 ==> GND, pin6 ==> 3.3V
/**************************************************************************************/
#define PINBARRIEREENTREE 38 // brun : GND, rouge : 5V, jaune : data
#define PINBARRIERESORTIE 40
/*****************************Ultra son 5V **********************************************************/
#define PINULTRASONTRIGE 42
#define PINULTRASONECHOE 44
#define PINULTRASONTRIGS 46
#define PINULTRASONECHOS 48
/***************************** RFID ************************************************************/
/* Connexion :
RC522 MODULE Uno/Nano MEGA
SDA D10 D9
SCK D13 D52
MOSI D11 D51
MISO D12 D50
IRQ N/A N/A
GND GND GND
RST D9 D8
3.3V 3.3V 3.3V
*/
#define SDA_DIO 9
#define RESET_DIO 8
/****************************** Ouverture barrière sortie **************************************/
#define ITOUVERTURE 49
char touches[NBLIGNES][NBCOLONNES] = {
{'1','2','3', 'A'},
{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}
};
byte lignePins[NBLIGNES] = {PINLIGNECLAVIER1, PINLIGNECLAVIER2, PINLIGNECLAVIER3, PINLIGNECLAVIER4}; // Connexion lignes avec Arduino {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colonnePins[NBCOLONNES] = {PINCOLONNECLAVIER1, PINCOLONNECLAVIER2, PINCOLONNECLAVIER3, PINCOLONNECLAVIER4}; // Colonnes avec Arduino {8, 7, 6}; //connect to the column pinouts of the keypad
Keypad clavier = Keypad( makeKeymap(touches), lignePins, colonnePins, NBLIGNES, NBCOLONNES );
PmodCls ecran{[](uint8_t b) {Serial.write(b);}}; // Utilisation pin1 (TX standard de la liaison série arduino
String codeEntree = CODE;
String codeSaisi = "";
int compteurVoiture = 0;
int compteurCode = 0;
Servo barriereEntree;
Servo barriereSortie;
RFID RC522(SDA_DIO, RESET_DIO);
void setup(){
Serial.begin(9600);
ecran.begin();
maz();
barriereEntree.attach(PINBARRIEREENTREE);
barriereSortie.attach(PINBARRIERESORTIE);
barriereEntree.write(0);
barriereSortie.write(0);
pinMode(PINULTRASONTRIGE, OUTPUT);
pinMode(PINULTRASONECHOE, INPUT);
pinMode(PINULTRASONTRIGS, OUTPUT);
pinMode(PINULTRASONECHOS, INPUT);
pinMode(ITOUVERTURE, INPUT);
SPI.begin();
RC522.init();
}
void loop(){
/*****************************Code entré au clavier Clavier *********/
if(compteurVoiture < MAXVOITURE)
{
char caractereRecu = clavier.getKey();
if (caractereRecu != NO_KEY){
if(compteurCode < 4)
{
codeSaisi += caractereRecu;
compteurCode++;
ecran.print('*');
}
if(caractereRecu == 'C')
maz();
if(compteurCode == 4)
{
if(codeSaisi == codeEntree)
{
ouvre(BARRIEREENTREE);
ferme(BARRIEREENTREE);
maz();
}
else
{
ecran.clear();
ecran.print(ERREURCODE);
delay(2000);
maz();
}
}
}
/*************************** Entrée par RFID ***************************************/
if(carteRFID())
{
ouvre(BARRIEREENTREE);
ferme(BARRIEREENTREE);
maz();
}
}
else
{
ecran.clear();
ecran.print(PARKINGPLEIN);
}
/**************************Ouverture bariière sortie ************************************/
if(compteurVoiture > 0)
if(digitalRead(ITOUVERTURE)==1)
{
ouvre(BARRIERESORTIE);
ferme(BARRIERESORTIE);
maz();
}
}
/**
* Lit la carte RFID
* retourne vrai si la carte est autorisée sinon faux
*/
bool carteRFID()
{
if (RC522.isCard())
{
RC522.readCardSerial();
ecran.clear();
ecran.print(DETECTE);
delay(1000);
if((RC522.serNum[0]==64)&&(RC522.serNum[1]==120)) // 64-120-87-128-239
return true;
else
return false;
}
return false;
}
/**
* Ouvre la barrière
* Si entree est vrai, ouvre la barrière d'entrée sinon ouvre la barrière de sortie
*/
void ouvre(bool entree)
{
ecran.clear();
ecran.setCursor(0, 1);
ecran.print(OUVERTURE);
if(entree)
compteurVoiture++;
else
compteurVoiture--;
for (int position = 0; position <= 90; position++) {
if(entree)
barriereEntree.write(position);
else
barriereSortie.write(position);
delay(15);
}
delay(PASSAGEVOITURE);
}
/*
* Ferme la barrière
* Si entree est vrai, ferme la barrière d'entrée, sinon ferme la barrière de sortie
* Ne ferme la barrière que s'il n'y a pas d'obstacle ==> boucle tant que l'obstacle n'est
* pas retiré
*/
void ferme(bool entree)
{
ecran.clear();
ecran.setCursor(0, 1);
ecran.print(FERMETURE);
if(entree)
while(obstacleE()); //{ }
else
while(obstacleS());
for (int position = 90; position >= 0; position--) {
if(entree)
barriereEntree.write(position);
else
barriereSortie.write(position);
delay(15);
}
delay(1000);
}
/*
* Mise à zéro
*/
void maz()
{
ecran.clear();
ecran.print(INVITE);
ecran.setCursor(0, 1);
compteurCode = 0;
codeSaisi = "";
}
/*
* Détecte s'il y a un obstacle sur la barrière d'entrée à moind de DOBSTACLE
* S'il y a un obstacle, retourne vrai sinon faux
*/
bool obstacleE()
{
long duration, distance;
digitalWrite(PINULTRASONTRIGE, LOW);
delayMicroseconds(2);
digitalWrite(PINULTRASONTRIGE, HIGH);
delayMicroseconds(10);
digitalWrite(PINULTRASONTRIGE, LOW);
duration = pulseIn(PINULTRASONECHOE, HIGH);
distance = (duration/2) / 29.1;
// Serial.println(distance);
if(distance < DSTOBSTACLE)
return true;
else
return false;
}
/*
* Détecte s'il y a un obstacle sur la barrière de sortie à moind de DOBSTACLE
* S'il y a un obstacle, retourne vrai sinon faux
*/
bool obstacleS()
{
long duration, distance;
digitalWrite(PINULTRASONTRIGS, LOW);
delayMicroseconds(2);
digitalWrite(PINULTRASONTRIGS, HIGH);
delayMicroseconds(10);
digitalWrite(PINULTRASONTRIGS, LOW);
duration = pulseIn(PINULTRASONECHOS, HIGH);
distance = (duration/2) / 29.1;
// Serial.println(distance);
if(distance < DSTOBSTACLE)
return true;
else
return false;
}

