Lucas TardifNicolas DAILLYBaptiste Morelfcaron
Published © GPL3+

BeerConnect

Connected Tap Machine, works with RFID badge links to an account on a Virtual Machine. Use LoRa and Node-RED for datas processing.

IntermediateShowcase (no instructions)Over 2 days267
BeerConnect

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Arduino Leonardo
Arduino Leonardo
It was a Arduino UNO TheThingsNetworks who was reccognized as an Arduino Leonardo
×1
RFID reader (generic)
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
To print the state of our System
×1
Breadboard (generic)
Breadboard (generic)
×1
Industrial IoT Wireless Water Detect Sensor
National Control Devices Industrial IoT Wireless Water Detect Sensor
I didn't found a water pump.
×1
Relay (generic)
RELAY 5V, GT1080
×1

Software apps and online services

Arduino IDE
Arduino IDE
For the main program
The Things Stack
The Things Industries The Things Stack
Node-RED
Node-RED
To link our datas with the DB
Visual Studio Code Extension for Arduino
Microsoft Visual Studio Code Extension for Arduino
For the web-site
Adobe Photoshop
For pictures
Adobe After Effect
For the video
SQL mariadb
For the Database

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
to make the BOX
Tape, Scotch
Tape, Scotch
To attach our Hardware on the BOX

Story

Read more

Schematics

morel-tardif_system.png

Code

code

Arduino
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal_I2C.h>
#include <TheThingsNetwork.h>

const char *appEui = "1202200009022002";
const char *appKey = "C2EF2AC186AB04937AAC87E0E7ADA12E";

#define loraSerial Serial1
#define debugSerial Serial

#define freqPlan TTN_FP_EU868

TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);

#define RST_PIN         9          
#define SS_PIN          10         

LiquidCrystal_I2C lcd(0x27, 16, 2);  
MFRC522 mfrc522(SS_PIN, RST_PIN);  

const int RELAY_PIN = 7;  

void setup() {
  loraSerial.begin(57600);
  debugSerial.begin(9600);

  while (!debugSerial && millis() < 10000)
    ;
  ttn.onMessage(message);
  debugSerial.println("-- STATUS");
  ttn.showStatus();

  debugSerial.println("-- JOIN");
  ttn.join(appEui, appKey);
  while (!Serial);   
  SPI.begin();     
  mfrc522.PCD_Init();
  delay(4);
  mfrc522.PCD_DumpVersionToSerial(); 
  pinMode(RELAY_PIN, OUTPUT);
  
  lcd.init();                   
  lcd.backlight();
  lcd.setCursor(2,0);
  lcd.print("Presentez ");
    lcd.setCursor(3,1);
  lcd.print("un badge !");

}

void loop() {

  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

 byte payload[4];
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    debugSerial.print(mfrc522.uid.uidByte[i], HEX);
    RFID= RFID+mfrc522.uid.uidByte[i];

  
    int length = mfrc522.uid.size;


    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print(" Verification !");

    for(int i = 0; i < length; i++) {
      payload[i] = mfrc522.uid.uidByte[i];
    }
  }    
    ttn.sendBytes(payload, sizeof(payload));

  byte data[64];

  int length = ttn.poll(data, sizeof(data));
  
  //je teste si j'ai une rponse
  if (length > 0) {
    String response = "";
    
    for (int i = 0; i < length; i++) {
      // je transforme ma reponse en string
      response += (char)data[i];
    }

    if (response == "SoldeIn") {
      //badge reconnu et budget suffisant pour tirer une bire
      //je spare ma rponse en fonction des positions des virgules pour pouvoir rcuprer le nom, le prnom ainsi que le solde du compte li au badge
    int index1 = dataStr.indexOf(',');
    int index2 = dataStr.indexOf(',', index1 + 1);
    int index3 = dataStr.indexOf(',', index2 + 1);

    String etat = dataStr.substring(0, index1);
    String nom = dataStr.substring(index1 + 1, index2);
    String prenom = dataStr.substring(index2 + 1, index3);
    float solde = dataStr.substring(index3 + 1).toFloat();


    //j'affiche les donnes sur l'cran
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print(nom +" "+ prenom);
    lcd.setCursor(1, 1);
    lcd.print("Solde : "+ String(solde)+" e");
    delay(3000);
    lcd.clear();
    lcd.setCursor(1, 0);
    lcd.print("OK");
    lcd.setCursor(1, 1);
    lcd.print("EN COURS");
    digitalWrite(RELAY_PIN, HIGH);
    delay(9000); //attention a ne pas mettre un temps trop lev pour viter de faire dborder votre verre :/
    digitalWrite(RELAY_PIN, LOW);
    lcd.clear();
    lcd.setCursor(2,0);
    lcd.print("MERCI ");
    lcd.setCursor(3,1);
    lcd.print("BEAUCOUP !");
    delay(3000);
    lcd.clear();
    lcd.setCursor(2,0);
    lcd.print("Presentez ");
    lcd.setCursor(3,1);
    lcd.print("un badge !");

    } else if (response == "SoldeOut") {
      //badge reconnu MAIS budget insuffisant pour tirer une bire
      //je spare ma rponse en fonction des positions des virgules pour pouvoir rcuprer le nom, le prnom ainsi que le solde du compte li au badge
      int index1 = dataStr.indexOf(',');
      int index2 = dataStr.indexOf(',', index1 + 1);
      int index3 = dataStr.indexOf(',', index2 + 1);

      String nom = dataStr.substring(index1 + 1, index2);
      String prenom = dataStr.substring(index2 + 1, index3);
      float solde = dataStr.substring(index3 + 1).toFloat();


      //j'affiche les donnes  l'cran
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print(nom +" "+ prenom);
      lcd.setCursor(1, 1);
      lcd.print("Solde : "+ String(solde)+" e");
      delay(2000);
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print("SOLDE");
      lcd.setCursor(1, 1);
      lcd.print("INSUFFISANT");
      delay(3000);
      lcd.clear();
      lcd.setCursor(2,0);
      lcd.print("Presentez ");
      lcd.setCursor(3,1);
      lcd.print("un badge !");
    } else {
      //badge inconnu 
      lcd.clear();
      lcd.setCursor(1, 0);
      lcd.print("BADGE INCONNU");
      delay(3000);
      lcd.clear();
      lcd.setCursor(2,0);
      lcd.print("Presentez ");
      lcd.setCursor(3,1);
      lcd.print("un badge !");
    }
  }  
  //je m'assure que la pompe soit bien teinte  chaque fin de loop.
  digitalWrite(RELAY_PIN, LOW);
}


void message(const uint8_t *payload, size_t size, port_t port)
{
  debugSerial.println("-- MESSAGE");
  debugSerial.print("Received " + String(size) + " bytes on port " + String(port) + ":");

  for (int i = 0; i < size; i++)
  {
    debugSerial.print(" " + String(payload[i]));
  }

  debugSerial.println();
}

Credits

Lucas Tardif

Lucas Tardif

1 project • 1 follower
Nicolas DAILLY

Nicolas DAILLY

28 projects • 16 followers
Associated Professor at UniLaSalle - Amiens / Head of the Computer Network Department / Teach Computer and Telecommunication Networks
Baptiste Morel

Baptiste Morel

1 project • 1 follower
fcaron

fcaron

12 projects • 1 follower

Comments