Découvrez notre Chaîne YouTube "Ingénierie et Projets"
Découvrez notre Chaîne Secondaire "Information Neuronale et l'Ingénierie du Cerveau"

 

Projet-électronique-serrure-codée-à-base-du-PIC-Schéma-du-montage-900x579

Objectifs du projet électronique

  1. Savoir comment utiliser le clavier 3×4 en utilisant des fonctions très simple sur MikroC
  2. Savoir générer des tonalités différentes pour créer des mélodies avec des fonctions déjà existantes
  3. Utilisation du pont H complet pour commencer le sens de rotation du moteur à CC
  4.  Autres astuces de programmations

Principe de fonctionnement

Le projet est constitué d’un clavier 4×3, un afficheur LCD 16×2, des LED d’état, un speaker et un bouton poussoir.

  1. Clavier : Permet d’ecrire le mot de passe, la taille du mot est variable en fonction égal à la valeur du paramètre LengthPassWord, par défaut LengthPassWord=5. Le clavier aussi permet de réactiver le clavier dans le cas de dépassement de nombre de tentatives permises. Le caractère de déblocage = Enable_PW.
  2. Afficheur LCD : Affichage des caractères instruit par le clavier et l’état du mot de passe Erreur’ ou ‘Correct’
  3. LED d’état : 3 LED d’état : Erreur, Mot de passe correct et ouverture de la porte
  4. Speaker : Alarme en cas de dépassement de nombre des tentatives permises
  5. Bouton poussoir : Arrêt d’alarme. Le bouton permet juste de bloquer l’alarme, en cas d’appuie sur l’un des boutons du clavier, l’alarme se met en marche de nouveau. Pour débloquer l’alarme il faut taper le caractère de réactivation du clavier.

Dansle cas d’introduction d’un mot de passe correct, le moteur tourne dans le sens 1 pendant 5 secondes, freiner pendant 3 secondes puis tourner dans le sens 2 pendant 5 secondes. Les temps (frein, rotation sens1/2) sont réglables par les paramètres suivant dans le programme: Temps_ms_sens1, Temps_ms_sens2 et Temps_ms_door.

Projet électronique serrure codée à base du PIC - LED

Circuit de puissance de commande du sens de la rotation du moteur

Projet-électronique-Sérrure-codée-électronique-à-base-du-micro-16F877_pont_H

  1. Sens 1 : VC1= ‘1’, CV2=’0′
  2. Sens 2 : VC1= ‘0’, CV2=’1′
  3. Frein : VC1= ‘0’, CV2=’0′ ou  VC1= ‘1’, CV2=’1′

La courant maximal supporté par le transistor doit être supérieur au courant maximal demandé par la charge( le moteur). La puissance maximale supportée par le transistor de commutation IRF9530 égale à 1.4Kw(100V,14A).

Projet électronique serrure codée à base du PIC - transistor IRF

 Notions de la musique sur le micro (Sonnerie d’Alarme & sonnerie d’ouverture de la porte)

Je ne suis pas un expert de la musique mais je peut vous aider pour développer votre propre piano  et créer des mélodie à base du microcontrôleur.

Tout son musical (ou note) possède une fréquence fondamentale (nombre de vibrations par seconde calculé en hertz) correspondant à sa hauteur. Deux notes dont les fréquences fondamentales ont un rapport qui est une puissance de deux (c’est-à-dire la moitié, le double, le quadruple…) donnent deux sons très similaires et portent le même nom. Cette observation permet de regrouper toutes les notes qui ont cette propriété dans la même catégorie de hauteur.

Dans la musique occidentale, les catégories de hauteurs sont au nombre de douze. Sept d’entre elles sont considérées comme les principales et ont pour noms : do, ré, mi, fa, sol, la et si. L’intervalle compris entre deux hauteurs dont la fréquence de l’une vaut le double (ou la moitié) de l’autre s’appelle une octave. Pour distinguer deux notes de même nom dans deux octaves différentes, on numérote les octaves et donne ce numéro aux notes correspondantes : par exemple, le la3 a une fréquence de 440 hertz dans la norme internationale. Cette fréquence de référence est donnée par un diapason.

Projet électronique serrure codée à base du PIC - notes musical

Projet électronique serrure codée à base du PIC - notes musicales 1

Exemple d’application en format Anglo-saxone :

Happy birthday to you
C4 C4 D4 C4 F4 E4

Happy birthday to you
C4 C4 D4 C4 G4 F4

A vous de faire la conversion des notes en fréquence 🙂

Maintenant on va passer à l’implémentation sur le micro des notes. MikroC dispose d’une fonction spéciale qui permet de générer un signal carré avec une fréquence donnée pendant un durée précis. La fonction s’appelle Sound_play(Freq_Value, Duree_ms).

Exemple :

  • Note C4 pendant 1s : Sound_play(523,1000)
  • Note F4 pendant 400ms : Sound_play(698, 400)

Note : Avant d’utiliser la fonction Sound_play, il faut affecter un pin et un port pour sortir le son grâce à la fonction Sound_Init(&PORT, Num_Pin)  [Sound_init(&PORTD,4)]

Pour Plus des infos sur la limitation en fréquence et des exemples d’utilisation, vous pouvez consulter le lien suivant.

Programme MikroC

#define                 LengthPassWord  5       // Nombre des caractère du mot de passe
#define                 NumCodeRepeat   2       // Nombre de tenation
#define                 Enable_PW       8       // Caractère de réactivation du clavier

#define                 Temps_ms_sens1  5000    // Temps de rotation dans le sens +
#define                 Temps_ms_sens2  5000    // Temps de rotation dans le sens -
#define                 Temps_ms_door   3000    // Temps d'ouvertur de la porte


// LCD module connections
sbit LCD_RS at RB1_bit;
sbit LCD_EN at RB2_bit;
sbit LCD_D4 at RB3_bit;
sbit LCD_D5 at RB4_bit;
sbit LCD_D6 at RB5_bit;
sbit LCD_D7 at RB6_bit;

sbit LCD_RS_Direction at TRISB1_bit;
sbit LCD_EN_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
sbit LCD_D5_Direction at TRISB4_bit;
sbit LCD_D6_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB6_bit;

// Initialisation du clavier dans le port D
char  keypadPort at PORTD;

unsigned short kp, count=0,i;
unsigned short CntWrongPW=0;
unsigned short Password[LengthPassWord]={1,2,3,4,5};


void Tone1() {
  Sound_Play(659, 250);   // Frequency = 659Hz, duration = 250ms
}

void Tone2() {
  Sound_Play(698, 250);   // Frequency = 698Hz, duration = 250ms
}

void Tone3() {
  Sound_Play(784, 250);   // Frequency = 784Hz, duration = 250ms
}

void Melody() {           // Plays the melody "Yellow house"
  Tone1(); Tone2(); Tone3(); Tone3();
  Tone1(); Tone2(); Tone3(); Tone3();
  Tone1(); Tone2(); Tone3();
  Tone1(); Tone2(); Tone3(); Tone3();
  Tone1(); Tone2(); Tone3();
  Tone3(); Tone3(); Tone2(); Tone2(); Tone1();
}

void Melody_Happy_BD(void)
{
    unsigned int Notes_Hz[6]={262,262,294,262,349,330};
    unsigned int Duration_ms[6]={200,200,400,400,400,500};
    unsigned int i;
    
    for(i=0;i<6;i++)
    {
       sound_play(Notes_Hz[i],Duration_ms[i]);
       delay_ms(100);
    }
}

void Melody_alarme_1(void)
{
    Sound_Play(400, 100);
    delay_ms(50);
    Sound_Play(600, 50);
    delay_ms(50);
    Sound_Play(800, 100);
    delay_ms(50);
    Sound_Play(700, 50);
    delay_ms(50);
    Sound_Play(500, 50);
}

void Melody_alarme_2(void)
{
    Sound_Play(400, 100);
    delay_ms(50);
    Sound_Play(500, 70);
    delay_ms(50);
    Sound_Play(600, 80);
    delay_ms(50);
    Sound_Play(700, 48);
    delay_ms(50);
    Sound_Play(800, 102);
    Sound_Play(900, 150);
    delay_ms(50);
    Sound_Play(1000, 40);
}
void Melody_alarme_3(void)
{
    Sound_Play(1500, 100);
    delay_ms(50);
    Sound_Play(2000, 50);
}

unsigned short GetKeyPressed(void)
{
    kp=0;
    do
      //kp = Keypad_Key_Press();
      kp = Keypad_Key_Click();
    while (!kp);

    switch (kp)
    {
      case  1: kp = 49; break; // 1
      case  2: kp = 50; break; // 2
      case  3: kp = 51; break; // 3
      case  4: kp = 65; break; // A
      case  5: kp = 52; break; // 4
      case  6: kp = 53; break; // 5
      case  7: kp = 54; break; // 6
      case  8: kp = 66; break; // B
      case  9: kp = 55; break; // 7
      case 10: kp = 56; break; // 8
      case 11: kp = 57; break; // 9
      case 12: kp = 67; break; // C
      case 13: kp = 42; break; // *
      case 14: kp = 48; break; // 0
      case 15: kp = 35; break; // #
      case 16: kp = 68; break; // D
    }
    return kp ;
}

void Sens_1_motor(void)
{
    PORTC.F5=1;
    PORTC.F6=0;
    delay_ms(Temps_ms_sens1);
}

void Sens_2_motor(void)
{
    PORTC.F5=0;
    PORTC.F6=1;
    delay_ms(Temps_ms_sens2);
}

void Frein_motor(void)
{
    PORTC.F5=0;
    PORTC.F6=0;
    
    // Ou bien
    //PORTC.F5=1;
    //PORTC.F6=1;
}


void main()
{

  TRISB = 0x01;
  TRISC = 0x00;
  PORTC=  0x00;
  
  Keypad_Init();                           // Init clavier
  Sound_Init(&PORTC, 4);                   // Init Sound
  Lcd_Init();                              // Init LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Effacer LCD
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Désactiver le curseur

  Lcd_Out(1, 1, "1");
  Lcd_Out(1, 1, "Key  :");                 // Write message text on LCD
  Lcd_Out(2, 1, "Password:");


  while(1)
  {
    for(i=0;i<LengthPassWord;i++)
    {
        kp=GetKeyPressed();
        Lcd_Chr(1, 10+i, kp);
        Lcd_Chr(2, 10+i, '*');
        if(Password[i]+48==kp  ) count++;
    }

    if (count==LengthPassWord)
    {
      count = 0;
      Lcd_Out(2,10,"Correct");
      // LED ON
      PORTC.F0=1;
      
      // DOOR ON
      PORTC.F3=1;
      Melody_Happy_BD();
      
      // Ouverture de la porte
      Sens_1_motor();
      Frein_motor();
      delay_ms(Temps_ms_door);
      Sens_2_motor();
      Frein_motor();
      
      // INIT
      PORTC=0x00;
    }
    else
    {
      count++;
      Lcd_Out(2,10,"Erreur");
      PORTC.F1=1;
      delay_ms(1000);
      PORTC=0x00;
      
      CntWrongPW++;
      
      if(CntWrongPW==NumCodeRepeat)
      {
         CntWrongPW=0;
         count=0;
         while(kp=GetKeyPressed()-48!=Enable_PW)
         {
             Lcd_Out(2,1,"Password Blocked");
             Lcd_Out(1,1,"Password Blocked");
             PORTC.F1=1;
             
             while(1)
             {
                 Melody_alarme_1();
                 //Melody_alarme_2();
                 //Melody_alarme_3();
                 //Melody();
                 if(PORTB.F0==1) break;
             }
             PORTC=0x00;
             
         }
      }
    }

    delay_ms(1000);

    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Out(1, 1, "Key  :");
    Lcd_Out(2, 1, "Password:");

  }
}

 

Télécharger gratuitement le fichier du projet : Serrure codée à base du microcontrôleur PIC16F877 (Schéma ISIS + Code MikroC)

 

************

Un petit commentaire de vous, un Grand encouragement pour nous 🙂 

 

Click to rate this post!
[Total: 3 Average: 4.3]

14 commentaires

Hadef Brahim · 2022-09-06 à 6:14

Mes remerciements pour vos efforts

    ElecM · 2022-09-08 à 6:33

    Avec plaisir 🙂

Zakaria · 2020-05-28 à 5:59

Pouvez-vous gmail 🙏🙏🙏

mohamed ousaid · 2019-04-23 à 7:18

bonjour,svp j’ai un PFE dont sont objectif est de  » conception d’un horloge à laide d’un pic16f84A « j’ai un problème de comment ajouté une réveil à mon programme svp c’est tu des aider sur ça et mrc d’avance

Mickael · 2019-04-05 à 1:53

Svp j’ai besoin du montage

yassine bellil · 2019-03-07 à 12:53

le mot de passe svp

    admin · 2019-03-16 à 11:19

    Voir la ligne 50 du code dans le fichier « SerrCodee.c ». Le code est configurable à volanté

    unsigned short Password[LengthPassWord]={1,2,3,4,5};

Simon · 2019-03-02 à 10:56

Bjr svp bien vouloir m’envoyer le schéma de montage

SAAD · 2018-09-27 à 1:45

Merci infiniment pour vos éffort

Germain · 2018-03-30 à 5:24

Bonjour, svp vous pouvez m’envoyer le schéma par e-mail.

Ahmed · 2018-03-18 à 1:07

Merci infiniment pour vos éffort merci encore une autre fois

feriel · 2017-12-17 à 7:05

svp,vous pouvez m’envoyer le schéma du montage

abidi · 2015-08-07 à 6:52

trés bien

Laisser un commentaire

Avatar placeholder

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Anti-Robot *

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.
Cookies settings
Accept
Decline
Privacy & Cookie policy
Privacy & Cookies policy
Cookie name Active

Privacy Policy

What information do we collect?

We collect information from you when you register on our site or place an order. When ordering or registering on our site, as appropriate, you may be asked to enter your: name, e-mail address or mailing address.

What do we use your information for?

Any of the information we collect from you may be used in one of the following ways: To personalize your experience (your information helps us to better respond to your individual needs) To improve our website (we continually strive to improve our website offerings based on the information and feedback we receive from you) To improve customer service (your information helps us to more effectively respond to your customer service requests and support needs) To process transactions Your information, whether public or private, will not be sold, exchanged, transferred, or given to any other company for any reason whatsoever, without your consent, other than for the express purpose of delivering the purchased product or service requested. To administer a contest, promotion, survey or other site feature To send periodic emails The email address you provide for order processing, will only be used to send you information and updates pertaining to your order.

How do we protect your information?

We implement a variety of security measures to maintain the safety of your personal information when you place an order or enter, submit, or access your personal information. We offer the use of a secure server. All supplied sensitive/credit information is transmitted via Secure Socket Layer (SSL) technology and then encrypted into our Payment gateway providers database only to be accessible by those authorized with special access rights to such systems, and are required to?keep the information confidential. After a transaction, your private information (credit cards, social security numbers, financials, etc.) will not be kept on file for more than 60 days.

Do we use cookies?

Yes (Cookies are small files that a site or its service provider transfers to your computers hard drive through your Web browser (if you allow) that enables the sites or service providers systems to recognize your browser and capture and remember certain information We use cookies to help us remember and process the items in your shopping cart, understand and save your preferences for future visits, keep track of advertisements and compile aggregate data about site traffic and site interaction so that we can offer better site experiences and tools in the future. We may contract with third-party service providers to assist us in better understanding our site visitors. These service providers are not permitted to use the information collected on our behalf except to help us conduct and improve our business. If you prefer, you can choose to have your computer warn you each time a cookie is being sent, or you can choose to turn off all cookies via your browser settings. Like most websites, if you turn your cookies off, some of our services may not function properly. However, you can still place orders by contacting customer service. Google Analytics We use Google Analytics on our sites for anonymous reporting of site usage and for advertising on the site. If you would like to opt-out of Google Analytics monitoring your behaviour on our sites please use this link (https://tools.google.com/dlpage/gaoptout/)

Do we disclose any information to outside parties?

We do not sell, trade, or otherwise transfer to outside parties your personally identifiable information. This does not include trusted third parties who assist us in operating our website, conducting our business, or servicing you, so long as those parties agree to keep this information confidential. We may also release your information when we believe release is appropriate to comply with the law, enforce our site policies, or protect ours or others rights, property, or safety. However, non-personally identifiable visitor information may be provided to other parties for marketing, advertising, or other uses.

Registration

The minimum information we need to register you is your name, email address and a password. We will ask you more questions for different services, including sales promotions. Unless we say otherwise, you have to answer all the registration questions. We may also ask some other, voluntary questions during registration for certain services (for example, professional networks) so we can gain a clearer understanding of who you are. This also allows us to personalise services for you. To assist us in our marketing, in addition to the data that you provide to us if you register, we may also obtain data from trusted third parties to help us understand what you might be interested in. This ‘profiling’ information is produced from a variety of sources, including publicly available data (such as the electoral roll) or from sources such as surveys and polls where you have given your permission for your data to be shared. You can choose not to have such data shared with the Guardian from these sources by logging into your account and changing the settings in the privacy section. After you have registered, and with your permission, we may send you emails we think may interest you. Newsletters may be personalised based on what you have been reading on theguardian.com. At any time you can decide not to receive these emails and will be able to ‘unsubscribe’. Logging in using social networking credentials If you log-in to our sites using a Facebook log-in, you are granting permission to Facebook to share your user details with us. This will include your name, email address, date of birth and location which will then be used to form a Guardian identity. You can also use your picture from Facebook as part of your profile. This will also allow us and Facebook to share your, networks, user ID and any other information you choose to share according to your Facebook account settings. If you remove the Guardian app from your Facebook settings, we will no longer have access to this information. If you log-in to our sites using a Google log-in, you grant permission to Google to share your user details with us. This will include your name, email address, date of birth, sex and location which we will then use to form a Guardian identity. You may use your picture from Google as part of your profile. This also allows us to share your networks, user ID and any other information you choose to share according to your Google account settings. If you remove the Guardian from your Google settings, we will no longer have access to this information. If you log-in to our sites using a twitter log-in, we receive your avatar (the small picture that appears next to your tweets) and twitter username.

Children’s Online Privacy Protection Act Compliance

We are in compliance with the requirements of COPPA (Childrens Online Privacy Protection Act), we do not collect any information from anyone under 13 years of age. Our website, products and services are all directed to people who are at least 13 years old or older.

Updating your personal information

We offer a ‘My details’ page (also known as Dashboard), where you can update your personal information at any time, and change your marketing preferences. You can get to this page from most pages on the site – simply click on the ‘My details’ link at the top of the screen when you are signed in.

Online Privacy Policy Only

This online privacy policy applies only to information collected through our website and not to information collected offline.

Your Consent

By using our site, you consent to our privacy policy.

Changes to our Privacy Policy

If we decide to change our privacy policy, we will post those changes on this page.
Save settings
Cookies settings

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

FPGA | Arduino | Matlab | Cours will use the information you provide on this form to be in touch with you and to provide updates and marketing.