0% found this document useful (0 votes)
45 views3 pages

Code Final

This document contains code for an RFID attendance system using an ESP8266 microcontroller. It initializes WiFi and various hardware components like an LCD screen and RFID reader. The main loop scans RFID tags, displays the scan on the LCD, plays a buzzer sound, and sends the tag ID to a web server using HTTP POST requests. It also defines functions for reading RFID tags and converting the binary tag ID to a string.

Uploaded by

Lucille Atillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

Code Final

This document contains code for an RFID attendance system using an ESP8266 microcontroller. It initializes WiFi and various hardware components like an LCD screen and RFID reader. The main loop scans RFID tags, displays the scan on the LCD, plays a buzzer sound, and sends the tag ID to a web server using HTTP POST requests. It also defines functions for reading RFID tags and converting the binary tag ID to a string.

Uploaded by

Lucille Atillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <ESP8266WebServer.

h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define buzzer D8
#define SS_PIN D4
#define RST_PIN D3
MFRC522 mfrc522(SS_PIN, RST_PIN);
#define ON_Board_LED 2
const char* ssid = "PLDTWIFI2.4g";
const char* password = "Pldtwifi_garciano13";
ESP8266WebServer server(80);
int readsuccess;
byte readcard[4];
char str[32] = "";
String StrUID;
void setup()
{
Wire.begin(D2, D1); //(SDA, SCL)
lcd.init();
lcd.backlight();
Serial.begin(115200);
SPI.begin //--> Init SPI bus
mfrc522.PCD_Init();
delay(500);
WiFi.begin(ssid, password);
Serial.println("");
pinMode(buzzer, OUTPUT);
pinMode(ON_Board_LED, OUTPUT);
digitalWrite(ON_Board_LED, HIGH);

Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
digitalWrite(ON_Board_LED, LOW);
delay(250);
digitalWrite(ON_Board_LED, HIGH);
delay(250);
}
digitalWrite(ON_Board_LED, HIGH);
Serial.println("");
Serial.print("Successfully connected to : ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Please tag a card or keychain to see the UID !");
Serial.println("");
}
void loop()
{
lcd.setCursor(0,0);
lcd.print(" WELCOME "); // Welcome Note
lcd.setCursor(0,1);
lcd.print("PROCEED TO SCAN ");
readsuccess = getid();
lcd.setCursor(0,0);

if (readsuccess) {
lcd.setCursor(0,0);
lcd.print(" ATTENDANCE "); // Attendance Recorded
lcd.setCursor(0,1);
lcd.print(" RECORDED ");

digitalWrite(buzzer, HIGH); //buzzer


delay(200);
digitalWrite(buzzer, LOW);
delay(200);
digitalWrite(ON_Board_LED, LOW);
HTTPClient http;
String UIDresultSend, postData;
UIDresultSend = StrUID;
postData = "UIDresult=" + UIDresultSend;
http.begin("http://192.168.1.8/NodeMCU-and-RFID-RC522-IoT-Projects/getUID.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST(postData);
String payload = http.getString();

Serial.println(UIDresultSend);
Serial.println(httpCode);
Serial.println(payload);

http.end();
delay(1000);
digitalWrite(ON_Board_LED, HIGH);
}

}
int getid()
{
if (!mfrc522.PICC_IsNewCardPresent()) {
return 0;
}
if (!mfrc522.PICC_ReadCardSerial()) {
return 0;
}

Serial.print("THE UID OF THE SCANNED CARD IS : ");

for (int i = 0; i < 4; i++) {


readcard[i] = mfrc522.uid.uidByte[i]; //storing the UID of the tag in readcard
array_to_string(readcard, 4, str);
StrUID = str;
}
mfrc522.PICC_HaltA();
return 1;
}
void array_to_string(byte array[], unsigned int len, char buffer[]) {
for (unsigned int i = 0; i < len; i++)
{
byte nib1 = (array[i] >> 4) & 0x0F;
byte nib2 = (array[i] >> 0) & 0x0F;
buffer[i * 2 + 0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
buffer[i * 2 + 1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA;
}
buffer[len * 2] = '\0';
}

You might also like