SmartSpace

SmartSpace is an IoT demonstrator designed to monitor room occupancy and manage student attendance using low-power wireless technology.

IntermediateShowcase (no instructions)32
SmartSpace

Things used in this project

Hardware components

Arduino MKR WAN 1300
Arduino MKR WAN 1300
×1
Joy-it sbc-rfid-rc522
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Buzzer
Buzzer
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Things Stack
The Things Industries The Things Stack
VS Code
Microsoft VS Code

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

Schematics

Code

Arduino MKR1310 code

C/C++
It uses an Arduino MKR WAN 1310 to scan RFID badges, measure the ambient temperature, and send that information wirelessly over a long distance using the LoRaWAN protocol (via The Things Network).
void setLcdColor(String color) { //Gère la couleur du lcd
  if      (color == "green") lcd.setRGB(0,   255, 0);
  else if (color == "red")   lcd.setRGB(255, 0,   0);
  else if (color == "white") lcd.setRGB(255, 255, 255);
}

void lcdIdle() { //remet l'écran dans son état d'attente par défaut
  lcd.clear();
  setLcdColor("white");
  lcd.setCursor(0, 0);
  lcd.print(" Scannez ");
  lcd.setCursor(0, 1);
  lcd.print("   votre badge  ");
  lcdShowingMessage = false;
}

void setup() { //Initialise le matériel et établit la connexion réseau lorawan
  Serial.begin(9600);

  // Init LCD
  lcd.begin(16, 2);
  setLcdColor("white");
  lcd.print("Initialisation");

  // Init RFID
  SPI.begin();
  rfid.PCD_Init();

  // Init modem LoRa
  if (!modem.begin(EU868)) {
    Serial.println("Erreur Modem HS");
    lcd.clear();
    setLcdColor("red");
    lcd.print("Erreur modem ");
    while (1);
  }

  lcd.clear();
  lcd.print("Connexion LoRa..");
  Serial.println("Connexion au réseau LoRaWAN...");

  if (!modem.joinOTAA(joinEUI, appKey, devEUI)) {
    Serial.println("Echec de connexion !");
    lcd.clear();
    setLcdColor("red");
    lcd.print("LoRa not OK");
    while (1);
  }

  Wire.end();
  delay(100);
  Wire.begin();
  lcd.begin(16, 2);

  Serial.println("--- SYSTEME PRET ---");
  lcdIdle();
}

void loop() {
  // Retour à l'écran idle après le délai d'affichage
  if (lcdShowingMessage && (millis() - lcdMessageTime > lcdMessageDuration)) {
    lcdIdle();
  }

  // Lecture badge RFID
  if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {

    if (millis() - lastSendTime > dutyCycleWait) {
      int rawTemp = analogRead(tempPin);
      handleScan(rawTemp);
    } else {
      Serial.println("Attendez 15s entre deux scans (Duty Cycle).");
      lcd.clear();
      setLcdColor("red");
      lcd.setCursor(0, 0);
      lcd.print("  Reessayer !  ");
      lcd.setCursor(0, 1);
      lcd.print(" Attendre 15s  ");
      lcdShowingMessage = true;
      lcdMessageTime = millis();
    }

    rfid.PICC_HaltA();
    rfid.PCD_StopCrypto1();
  }

  delay(100);
}

void envoyerVersTTN(byte* uid, byte uidSize, int val) {
  byte payload[6];
  // On prend les 4 premiers octets de l'UID
  for (byte i = 0; i < 4; i++) payload[i] = (i < uidSize) ? uid[i] : 0x00;
  // Découpage de l'entier de température en 2 octets
  payload[4] = highByte(val);
  payload[5] = lowByte(val);

  Serial.println("Envoi LoRaWAN...");
  modem.beginPacket();
  modem.write(payload, 6);
  int err = modem.endPacket();

  if (err > 0) {
    Serial.println("[OK] Message reçu par TTN !");
  } else {
    Serial.print("[ERREUR] Échec de l'envoi. Code : "); Serial.println(err);
  }
}

Credits

Aurélien Verhaeghe
1 project • 0 followers
Nicolas DAILLY
44 projects • 32 followers
Associated Professor at UniLaSalle - Amiens / Head of the Computer Network Department / Teach Computer and Telecommunication Networks
Hachimi Kasmi
1 project • 0 followers

Comments