🏠 HomeLe ricetteL'elettronicaFatto in casaLe storieLa scienzaGiochi e barzelletteVivere in FranciaVivere in Italia
🧰 Livello · Niveau : medio · moyen⏱️ Durata · Durée : 2 h💶 Costo · Coût : ~50 €

Materiale · Matériel

Componenti / Composants Quantità · Quantité
Arduino Mega 1
Lettore Codice QR · Lecteur de QR Code 1
Servo Motore 180° · Servo Moteur 180° 1
Schermo LCD 4 linee 20 caratteri (fac.) · Écran LCD 4 lignes 20 caractères (fac.) 1

Montaggio · Montage

Il lettore di codice QR
  • 5 volt ➡️ 5 volt
  • GND ➡️ GND
  • TX ➡️ RX
  • RX ➡️ TX
Il motore
  • 5 volt ➡️ 5 volt
  • GND ➡️ GND
  • Signal ➡️ Pin 10
Lo schermo (fac.)
  • 5 volt ➡️ 5 volt
  • GND ➡️ GND
  • SDA ➡️ SDA
  • SCL ➡️ SCL
Le lecteur de QR Code
  • 5 volts ➡️ 5 volts
  • GND ➡️ GND
  • TX ➡️ RX
  • RX ➡️ TX
Le moteur
  • 5 volts ➡️ 5 volts
  • GND ➡️ GND
  • Signal ➡️ Broche 10
L'écran (fac.)
  • 5 volts ➡️ 5 volts
  • GND ➡️ GND
  • SDA ➡️ SDA
  • SCL ➡️ SCL

Il programma · Le programme


  // ########################
  // # LETTORE DI CODICE QR #
  // #      GUY  MAGLI      #
  // #   28  AGOSTO 2026    #
  // ########################
  
  // ###############
  // # BIBLIOTECHE #
  // ###############
  
  #include <Wire.h>
  #include <LiquidCrystal_I2C.h> // Per lo schermo
  LiquidCrystal_I2C loSchermo(0x3F, 20, 4);
  #include <Servo.h> // Per il motore
  Servo ilMotore;
  
  // #####################
  // # VARIABILI GLOBALI #
  // #####################
  
  String cLettura = ""; // Frase letta sul lettore
  String cGeneralita = ""; // Identità dell'utente
  bool bAprire = false; // Per dare il permesso
  bool bTrovato = false; // È nel database
  
  // #########
  // # SETUP #
  // #########

  void setup()
  {
    loSchermo.begin(); // Per lo schermo
    loSchermo.backlight();
    ilMotore.attach(9); // Per il motore
    ilMotore.write(45); // Secondo la posizione del motore
    ilMotore.detach(); // Spegnere il motore per ridurre il consumo
    delay(5000);
    Serial.begin(9600); // Moniteur Série USB pour le PC
    Serial1.begin(9600); // Port UART1 connecté au GM67
    identificazione();
  }

  // ########
  // # LOOP #
  // ########
  
  void loop()
  {
    letturaQR(); // Lettura del codice QR
    if (bAprire == true) // Se la persona ha il permesso di entrare
    {
      apertura(cGeneralita); // Aprire la barriera e scrivere un messaggio
      chiusura(); // Chiudere la barriera e scrivere un messaggio
    }
    else // Se la persona non ha il permesso di entrare
    {
      sospeso(cGeneralita); // Scrivere un messaggio
    }
    identificazione(); // Ricominciare
  }

  // #############
  // # PROCEDURE #
  // #############

  // IDENTIFICAZIONE

  void identificazione() // Scrivere un messaggio
  {
    loSchermo.setCursor(0, 0);
    loSchermo.print(" IDENTIFICAZIONE ");
    loSchermo.setCursor(0, 1);
    loSchermo.print(" ");
    loSchermo.setCursor(0, 2);
    loSchermo.print(" PRESENTARE ");
    loSchermo.setCursor(0, 3);
    loSchermo.print(" IL CODICE QR ");
    delay(500);
  }

  // APERTURA

  void apertura(String cNome) // Scrivere un messaggio
  {
  while (cNome.length() < 20) // Centrare il nome e i cognome { cNome=" " + cNome + " " ; } loSchermo.setCursor(0, 0); loSchermo.print(cNome); loSchermo.setCursor(0, 1); loSchermo.print(" ");
    loSchermo.setCursor(0, 2);
    loSchermo.print(" ACCESSO CONSENTITO ");
    loSchermo.setCursor(0, 3);
    loSchermo.print(" APERTURA ");
    ilMotore.attach(9);
    for (int t = 145; t >= 55; t--) // Aprire lentamente
    {
      ilMotore.write(t);
      delay(10);
    }
    ilMotore.detach(); // Spegnere il motore per ridurre il consumo
    delay(10000);
  }
  
  // SOSPESO
  
  void sospeso(String cNome) // Scrivere un messaggio
  {
    while (cNome.length() < 20) // Centrare il nome e i cognome
    {
      cNome = " " + cNome + " ";
    }
    loSchermo.setCursor(0, 0);
    loSchermo.print(cNome);
    loSchermo.setCursor(0, 1);
    loSchermo.print(" ");
    loSchermo.setCursor(0, 2);
    loSchermo.print(" ACCESSO SOSPESO ");
    loSchermo.setCursor(0, 3);
    loSchermo.print(" NON OLTREPASSARE ");
    delay(5000); // Aspettare cinque secondi
  }
  
  // CHIUSURA
  
  void chiusura() // Scrivere un messaggio
  {
    loSchermo.setCursor(0, 0);
    loSchermo.print(" ");
    loSchermo.setCursor(0, 1);
    loSchermo.print(" ATTENZIONE ");
    loSchermo.setCursor(0, 2);
    loSchermo.print(" CHIUSURA IN CORSO ");
    loSchermo.setCursor(0, 3);
    loSchermo.print(" ");
    ilMotore.attach(9);
    for (int t = 55; t <= 145; t++) // Chiudere lentamente
    {
      ilMotore.write(t);
      delay(20);
    }
    ilMotore.detach(); // Spegnere il motore per ridurre il consumo
    delay(2000);
  }
  
  // LETTURA
  
  void letturaQR() // Leggere il QRCode
  {
    bTrovato = false;
    while (bTrovato == false) // Fino a quando nessun codice QR non è stato letto
    {
      if (Serial1.available())
      {
        String code = Serial1.readStringUntil('\n'); // Ascoltare i caratteri letti
        code.trim();
        bAprire = false;
        if (code == " http://www.magli.fr") 
        { 
          cGeneralita="AUGUSTE  MAGLI" ; // Nome da scrivere sullo schermo 
          bAprire=true; // La barriera sarà aperta 
          bTrovato=true; // Non ascoltare più 
        } 
        if (code=="http://www.grazian.it" )  
        { 
          cGeneralita="FIORELLA GRAZIAN" ; 
          bAprire=true; bTrovato=true; 
        } 
        if (code=="http://www.pallino.it")
        {
          cGeneralita="PINCO  PALLINO";
          bAprire=false; // La barriera rimarrà chiusa
          bTrovato=true;
        }
        if (code=="http://www.pignon.fr")
        {
          cGeneralita="FRANCOIS PIGNON";
          bAprire=true;
          bTrovato=true;
        }
        if (code=="https://www.sadette.fr")
        {
          cGeneralita="HONORE SADETTE";
          bAprire=false;
          bTrovato=true;
        }
        if (code=="https://www.tartampion.fr")
        {
          cGeneralita="YOANN TARTAMPION";
          bAprire=false;
          bTrovato=true;
        }
        if
          (code=="https://www.edroit.fr")
        {
          cGeneralita="KID EDROIT";
          bAprire=true;
          bTrovato=true;
        }
        if (code=="https://www.morant.fr")
        {
          cGeneralita="MARITE  MORANT";
          bAprire=true;
          bTrovato=true;
        }
        if (code=="https://www.bavvat.fr")
        {
          cGeneralita="LUCIEN  BAVVAT";
          bAprire=true;
          bTrovato=true;
        }
      }
    }
  }

auguste@magli.fr
Questa pagina è stata modificata il 16.11.26
È stata pubblicata su
bluesky 27.08.26 · mastodon xx.xx.xx · tweet (NON X) xx.xx.xx · wsocial 13.10.26