VPA
Published © GPL3+

Contactless Temp Control of Employees on RFID Pass-Through

Employee access to the enterprise using RFID tags and employee temp measurement using a contactless thermometer that sends data to the cloud

IntermediateFull instructions providedOver 1 day11,315
Contactless Temp Control of Employees on RFID Pass-Through

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
RFID reader RC522
×1
OLED 0.96" 128x32
×1
MLX90614
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fritzing

Story

Read more

Schematics

STEP 8. Adding a relay to enable / disable the input

Step 2. Connecting an IR temperature sensor MLX90614 to an Arduino MK 1000 Wi Fi Board

Step 3. Connecting an OLED display to an Arduino MCF 1000 WiFi Board

Step 4. Connecting the rc522 RFID reader module to the Arduino MKR 1000 WiFi Board

Code

Scetch Arduino

Arduino
//  
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <MFRC522.h>
#include <WiFi101.h>
//   
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_SSD1306 display(128, 32, &Wire, -1);
MFRC522 mfrc522(7, 6);
WiFiClient client;
// your network SSID (name)
// and password (WPA)
char ssid[] = "my_DLink";        
char pass[] = "marina11";  
// name address 
char server[] = "www.freeparkovka.ru";    

int pinRelay=5;
int status = WL_IDLE_STATUS;  
char response[40];
byte cardUID[4] = {0,0,0,0};
int res=0;
int rr;
float temp;
unsigned long millis1=0;
unsigned long millis2=0;
unsigned long millis3=0;

void setup() {
  Serial.begin(9600);
  // relay
  pinMode(pinRelay,OUTPUT);
  digitalWrite(pinRelay,LOW);
  //  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.clearDisplay();
  display.display();
  //   MLX90614
  mlx.begin(); 
  //  SPI
  SPI.begin();
  //  MFRC522
  mfrc522.PCD_Init();
  Serial.println("connect WiFi ....");
  display.setCursor(10,10);
  display.print(F("Connect WiFi"));
  display.display();

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(5000);
  }
  display.setCursor(30,20);
  display.print(F("ok"));
  display.display();
  printWiFiStatus();
  delay(2000);
  Serial.println("Wait RFID ....");
    
}

void loop() {
   

  switch(res) {
     case 0:  //
        send_display("Wait RFID...."); 
        res=1;
        break;
     case 1:  //  RFID
        //    
        if ( mfrc522.PICC_IsNewCardPresent()) {
           //    .
           if ( mfrc522.PICC_ReadCardSerial()) {   
              //  UID
              Serial.print(F("Card UID:")); 
              display.setCursor(10,20);
              for (byte i = 0; i < 4; i++) {
                 cardUID[i]=mfrc522.uid.uidByte[i];
                 Serial.print(cardUID[i],HEX);
                 display.print(cardUID[i],HEX);
              }
           Serial.println();
           res=2;
           display.display();
           delay(2000);
           Serial.println("send uid to server....");
           }
        mfrc522.PICC_HaltA();
        mfrc522.PCD_StopCrypto1();
        }
        display.display();
        break;
     case 2:  //    UID  
        send_display("Send server..."); 
        rr=send_uid_to_server();
        if(rr==1) {
           res=3;
           display.setCursor(10,0);
           display.print(F("uid ok"));
           millis3=millis();
        }
        else if(rr==2) {
           res=0;
           display.setCursor(10,0);
           display.print(F("incorrect")); 
        }
        else  {
           res=0;
           display.setCursor(10,0);
           display.print(F("error 404")); 
        }
        display.display();
        delay(3000);
        break;
     case 3:  //   
        if(millis()-millis3<10000) {
           send_display("Wait temp....");
           temp=mlx.readObjectTempC();
           display.setCursor(10,20);
           display.print(temp);
           display.print(F(" *C"));
           display.display();
           if(temp>34.0 && temp<42.0) {
              res=4;
              delay(2000);
           }
        }
        else {
          res=0;
        }
        break;
     case 4:  //     
         send_display("Wait temp....");
         send_temp_to_server();
         res=5;
         delay(2000);
         break;
     case 5:  //    
         display.clearDisplay();
         display.setCursor(10,10);
         display.print(F("Temp="));
         display.print(temp);
         display.print(F("*C"));
         display.setCursor(10,20);
         if(temp<37.5) { // OPEN
            display.print(F("OPEN"));     
            Serial.println("OPEN");
            digitalWrite(pinRelay,HIGH);
         }
         else {  // CLOSE
            display.print(F("CLOSE"));     
            display.setCursor(10,0);
            display.print(F("Temp high!!!"));     
            Serial.println("CLOSE");
            Serial.println("Temp high!!!");
            digitalWrite(pinRelay,LOW);
         }
        display.display();
        delay(3000);
        Serial.println("Wait RFID ....");
        res=0;
        break;
     default:
        break;
  }
}

//
void printWiFiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}
// 
int send_uid_to_server() {
   int ret=3;
   unsigned long previos;
   int x=0;int f=0;
   char s;
   client.stop();
   if (client.connect(server, 80)) {
     ////     narodmon.ru
     //  
     // uid  
     String str="/firm/get_uid.php?uid=";
     for (byte i = 0; i < 4; i++) {
        str+=String(cardUID[i],HEX);
     }
     Serial.print("str=");Serial.println(str);
     client.println("GET "+str+" HTTP/1.1");
     client.println("Host: freeparkovka.ru");
     client.println("User-Agent: ArduinoWiFi/1.1");
     client.println("Connection: close");
     client.println();
     //  
     previos=millis();
     for(int i=0;i<40;i++)
        response[i]=0; 
     
     do{
        if(client.available() > 0) { 
           //    
           s = client.read();
           if(s=='#') 
              f=1;
           if(f==1) {
              response[x]=s;
              //Serial.print(response[x]);
              x++;
           }
           Serial.write(s);
        }
     }
     while((millis() - previos) < 5000);
     if(response[0]='#') {
        ret=command(response);
     }
     Serial.println(response);
     //client.stop();
     return ret;
  } 
  else {
    //  
   Serial.println("connection failed");
   //client.stop();
   return 3;
  }
}
//
void send_temp_to_server() {
   client.stop();
   if (client.connect(server, 80)) {
     ////     narodmon.ru
     //  
     // uid  
     String str="/firm/get_temp.php?uid=";
     for (byte i = 0; i < 4; i++) {
        str+=String(cardUID[i],HEX);
     }
     str+="&temp="+String(temp);
     Serial.print("str=");Serial.println(str);
     client.println("GET "+str+" HTTP/1.1");
     client.println("Host: freeparkovka.ru");
     client.println("User-Agent: ArduinoWiFi/1.1");
     client.println("Connection: close");
     client.println();
     Serial.println(response);
     delay(10);
     //client.stop();
  } 
  else {
    //  
   Serial.println("connection failed");
   //client.stop();
  }
}
//     
int command(char* arr) {
    String str(arr);
    //
    if(str.indexOf("yes")!=-1) {
       return 1;
    }
    else if(str.indexOf("no")!=-1) {
       return 2;
    }
    return 3;
}
//   
void send_display(String str) {
   display.clearDisplay();
   display.setCursor(10,10);
   display.print(str);
   display.display();
}

Step 2. Connecting an IR temperature sensor MLX90614 to an Arduino MKR 1000 Wi Fi Board

Arduino
#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

void setup() {
  Serial.begin(9600);
  Serial.println("start");  
  mlx.begin();  
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C");
  Serial.print("\tObject = "); Serial.print(mlx.readObjectTempC()); 
  Serial.print("*C");
  Serial.print("\tObject = "); Serial.print(mlx.readObjectTempF()); 
  Serial.println("*F");
  delay(3000);
}

Step 3. Connecting an OLED display to an Arduino MKR 1000 WiFi Board

Arduino
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_SSD1306 display(128, 32, &Wire, -1);

float temp;
unsigned long millis1=0;

void setup() {
  Serial.begin(9600);
  // 
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(WHITE); 
  //
  display.clearDisplay();
  display.display();
  // 
  mlx.begin(); 
  //
  Serial.println("start");
}

void loop() {
  if(millis()-millis1 >= 3000) {
     display.clearDisplay();
     display.setCursor(10,10);
     display.println(F("Wait temp...."));
     temp=mlx.readObjectTempC();
     display.setCursor(10,20);
     display.print(temp);
     display.print(F(" *C"));
     display.display();
     //
     millis1=millis();
  }
}

Step 4. Connecting the rc522 RFID reader module to the Arduino MKR 1000 WiFi Board

Arduino
//  
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <MFRC522.h>
//   
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_SSD1306 display(128, 32, &Wire, -1);
MFRC522 mfrc522(7, 6);

byte cardUID[4] = {0,0,0,0};
int res=1;
float temp;
unsigned long millis1=0;

void setup() {
  Serial.begin(9600);
  //  
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.clearDisplay();
  display.display();
  //   MLX90614
  mlx.begin(); 
  //  SPI
  SPI.begin();
  //  MFRC522
  mfrc522.PCD_Init();
  Serial.println("start");
  Serial.println("Wait RFID ....");
}

void loop() {
  switch(res) {
     case 1:  //  RFID
        display.clearDisplay();
        display.setCursor(10,10);
        display.print(F("Wait RFID...."));
        //    
        if ( mfrc522.PICC_IsNewCardPresent()) {
           //    .
           if ( mfrc522.PICC_ReadCardSerial()) {   
              //  UID
              Serial.print(F("Card UID:")); 
              display.setCursor(10,20);
              for (byte i = 0; i < 4; i++) {
                 cardUID[i]=mfrc522.uid.uidByte[i];
                 Serial.print(cardUID[i],HEX);
                 display.print(cardUID[i],HEX);
              }
           Serial.println();
           Serial.println("Wait temp....");
           res=3;
           }
        mfrc522.PICC_HaltA();
        mfrc522.PCD_StopCrypto1();
        }
        display.display();
        break;
     case 2:  //    UID  

         break;
     case 3:  //   
        delay(2000);
        display.clearDisplay();
        display.setCursor(10,10);
        display.println(F("Wait temp...."));
        temp=mlx.readObjectTempC();
        display.setCursor(10,20);
        display.print(temp);
        display.print(F(" *C"));
        display.display();
        if(temp>34.0 && temp<42.0) {
           res=5;
        }
        break;
     case 4:  //     
     
         break;
     case 5:  //    
         display.clearDisplay();
         display.setCursor(10,10);
         display.print(F("Temp="));
         display.print(temp);
         display.print(F("*C"));
         display.setCursor(10,20);
         if(temp<37.5) {
            display.print(F("OPEN"));     
            Serial.println("OPEN");
         }
         else {
            display.print(F("CLOSE"));     
            display.setCursor(10,0);
            display.print(F("Temp high!!!"));     
            Serial.println("CLOSE");
            Serial.println("Temp high!!!");
         }
        display.display();
        delay(3000);
        Serial.println("Wait RFID ....");
        res=1;
        break;
     default:  
         break;   
  }
}

Step 6. Creating a database of employees on the company's website and a database for collecting dail

PHP
get_uid.php checks for an ID in the database and returns in the response:
<?php

//Параметры MySQL
$location="localhost";
$user="bhx20666_parking";
$pass="parking12345678";
$db_name="bhx20666_firma";

// connect db
if(! $db=mysqli_connect($location,$user,$pass,$db_name))
 {echo "connect error";}
else
 {;}
 
$query0=" SELECT * FROM users WHERE uid='".$_GET['uid']."' ";
$rez0=mysqli_query($db,$query0);

if(mysqli_num_rows($rez0)>0) {
    $row0=mysqli_fetch_assoc($rez0);
    echo "#yes".";".$row0['name']."$";
}
else {
    echo "#no"."$";
}


    
 
?>

Step 6. Creating a database of employees on the company's website and a database for collecting dail

PHP
get_temp.php sends the employee's temperature to the database
<?php

//Параметры MySQL
$location="localhost";
$user="bhx20666_parking";
$pass="parking12345678";
$db_name="bhx20666_firma";

// connect db
if(! $db=mysqli_connect($location,$user,$pass,$db_name))
 {echo "connect error";}
else
 {;}
 
$query0=" SELECT * FROM users WHERE uid='".$_GET['uid']."' ";
$rez0=mysqli_query($db,$query0);

if(mysqli_num_rows($rez0)>0) {
    $row0=mysqli_fetch_assoc($rez0);
    $query1=" INSERT INTO temp SET 
          id_user='".$row0['id']."',
          temp='".$_GET['temp']."',
          day='".date('Y-m-d H:i:s')."' ";  
    mysqli_query($db,$query1);
    echo "#yes";
}
else {
    echo "#no";
}


    
 
?>

Step 9. Page for remote viewing of employee temperature data

PHP
view_temp.php
<?php

//
$location="localhost";
$user="**********";
$pass="**********";
$db_name="**********";

// connect db
if(! $db=mysqli_connect($location,$user,$pass,$db_name))
 {echo "connect error";}
else
 {;}
 
$query0=" SELECT * FROM temp WHERE uid='".$_GET['uid']."' ";
$rez0=mysqli_query($db,$query0);

$content1.=date('Y-m-d')."<br><br>";
$content1.="<table>";
$query1="SELECT * FROM temp WHERE day >= CURDATE()  ";
$rez1=mysqli_query($db,$query1);  $i=1;
while($row1=mysqli_fetch_assoc($rez1)) {
   $content1.="<tr>";
   $content1.="<td>".$i."</td>";
   $rez2=mysqli_query($db,"SELECT name FROM users WHERE id =".$row1['id_user']."  ");
   $row2=mysqli_fetch_assoc($rez2);
   $content1.="<td>".$row2['name']."</td>";
   $content1.="<td>".mb_substr($row1['day'],10,9)."</td>"; 
   if($row1['temp']>37.5)  
       $content1.="<td style='background-color:red'>".$row1['temp']."</td>";
   else  
       $content1.="<td>".$row1['temp']."</td>";
   $content1.="</tr>";
   $i++;
   }
$content1.="</table>";
echo $content1;

?>

Credits

VPA

VPA

6 projects • 28 followers
Author of more than 10 books on programming (web, Arduino, Raspberry pi, IoT), developer and teacher.

Comments