How to combine a RFID attendance system and proximity sensor alarm system

I am currently working on my final year project that involves a basic rfid attendance system and a proximity alarm system. The project intends to prevent ManOverboard situations by warning people who get too close to the edge of the deck of a ship. The RFID attendance will log their exit times and save them and the alarm system uses normal ultrasonic sensors and buzzers and leds that change colour according to distance. Each system is run by its own arduino. However,as you can tell, this two systems are separate and not connected in any way. My goal is to be able to log a user's time and also be able to send a warning message to the same attendace system unique to a tag as it gets closer to the ultrasonic sensor and a centralized alarm is raised rather than individual alarms located at each of the ultrasonic sensors. Any ideas?(The RFID code doesnt work for some reason. I am able to connect the nodeMCU to the LAN and also launch the PHP Web app. The issue to the RFID reader does not register the tag and the UID is not sent to the webapp.Please help. This is the link to the RFID project for anyone who wants to try it out:

RFID CODE //NodeMCU and RFID libraries————————– #include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <SPI.h> #include <MFRC522.h>

#define SS_PIN D2 //D2 #define RST_PIN D1 //D1

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.

/* Set these to your desired credentials. */ const char *ssid = "Emaina"; const char password = "emaina@2019"; const char device_token = " b10b94f9491279fa ";

String URL = ""; //computer IP or the server domain String getData, Link; String OldCardID = ""; unsigned long previousMillis = 0;

void setup() { Serial.begin(115200); SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 card WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect) delay(1000); WiFi.mode(WIFI_STA); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("Connected"); Serial.print("IP address: "); Serial.println(WiFi.localIP()); //IP address assigned to your ESP delay(1000); 

} //************************************************************************ void loop() {

if (millis() – previousMillis >= 15000) { previousMillis = millis(); OldCardID=""; } delay(50); //——————————————— //look for new card if ( ! mfrc522.PICC_IsNewCardPresent()) { return;//got to start of loop if there is no card present } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return;//if read card serial(0) returns 1, the uid struct contians the ID of the read card. } String CardID =""; for (byte i = 0; i < mfrc522.uid.size; i++) { CardID += mfrc522.uid.uidByte[i]; } //——————————————— if( CardID == OldCardID ){ return; } else{ OldCardID = CardID; } //——————————————— // Serial.println(CardID); SendCardID(CardID); delay(1000); } //send the Card UID to the website* void SendCardID( String Card_uid ){ Serial.println("Sending the Card ID"); if(WiFi.isConnected()){ HTTPClient http; //Declare object of class HTTPClient //GET Data getData = "?card_uid=" + String(Card_uid) + "&device_token=" + String(device_token); // Add the Card ID to the GET array in order to send it //GET methode Link = URL + getData; http.begin(Link); //initiate HTTP request //Specify content-type header

int httpCode = http.GET(); //Send the request String payload = http.getString(); //Get the response payload 

// Serial.println(Link); //Print HTTP return code Serial.println(httpCode); //Print HTTP return code Serial.println(Card_uid); //Print Card ID Serial.println(payload); //Print request response payload

if (httpCode == 200) { if (payload.substring(0, 5) == "login") { String user_name = payload.substring(5); // Serial.println(user_name); } else if (payload.substring(0, 6) == "logout") { String user_name = payload.substring(6); // Serial.println(user_name); } else if (payload == "succesful") { } else if (payload == "available") { } delay(100); http.end(); //Close connection } 

} }

PROXIMITY SENSOR CODE //include Tone.h lib, that enables playing diffrent sounds on multiple buzzers by using Tone objects #include <Tone.h>

//define the pins you want to connect to the sensors and buzzers //if you want to use more then two sensors, define them the same way as sensor 1 and 2 where defined

//pins, that are connected to "trigger" of ultrasonic sensors #define TRIGGER1 7 #define TRIGGER2 5

//pins, that are connected to "echo" of ultrasonic sensors #define ECHO1 6 #define ECHO2 3

// pins, that are connected to "+" pin of buzzers #define BUZZ1 9 #define BUZZ2 10

//pins connected to LED #define led 13 #define led2 12 #define led3 2 #define led4 8 //define your global variables

//define one Tone object for every buzzer you want to use Tone tone1; Tone tone2;

//define one long for every sensor you want to use and the distance it measures long distance1=0; long distance2=0;

//define one long for every sensor you want to use. Using these make it possible to run the buzzers simultaneously. long t1=-10000; long t2=-10000;

//declare the funtions, we'll be using

//checkDistance will check if the given distance is lower then 200 cm. If it is lower then 200 cm, it plays a tone on the buzzer that is connected with the given tone object. //The length of the tone depends on how close the object is to the sensor. /* long distance – distance you want to check Tone toneobj – tone object you want to play the tone at, if the distance is between 200 and 0 cm int freqeuency – the frequency the played tone should have (we suggest to use different frequencies for each buzzer, so you can tell apart, wich sensor got triggered) long *timer – one of our initialised timers (t1,…,tn), that keeps control, that the sound is played as long as it should be */ void checkDistance(long distance, Tone toneobj, int frequency, long *timer);

//measure will measure and return the distance between the sensor and an object in the way of the sensor in cm. If theres no object within two meter, it will return 0. /* int trigger – trigger pin connected to the sensor, you want to check int echo – echo pin connected to the sensor, you want to check */ long measure(int trigger, int echo);

//setup the pins and connect the tone objects to the buzzers void setup(){

pinMode(TRIGGER1, OUTPUT); pinMode(ECHO1, INPUT); pinMode(TRIGGER2, OUTPUT); pinMode(ECHO2, INPUT); tone1.begin(BUZZ1); tone2.begin(BUZZ2); pinMode(led, OUTPUT); pinMode(led2, OUTPUT);


//constantly measure the distances and checks, if it is necessary to play a tone or not void loop() {

distance1 = measure(TRIGGER1, ECHO1); distance2 = measure(TRIGGER2, ECHO2); checkDistance(distance1, tone1, 660, &t1); checkDistance(distance2, tone2, 440, &t2);


long measure(int trigger, int echo){ long duration = 0; digitalWrite(trigger, LOW);
delay(5); digitalWrite(trigger, HIGH); delay(10); digitalWrite(trigger, LOW); duration = pulseIn(echo, HIGH,11662); return (duration/2) * 0.03432; }

void checkDistance(long distance, Tone toneobj, int frequency, long *timer){ if(distance<200&&distance>0){ if(millis()-*timer > long(5.4*distance-81)||distance<15){ *timer=millis();,100); digitalWrite(led, HIGH); digitalWrite(led2,LOW); digitalWrite(led3, HIGH); digitalWrite(led4,LOW); }

}else{ toneobj.stop(); digitalWrite(led2, HIGH); digitalWrite(led,LOW); digitalWrite(led4, HIGH); digitalWrite(led3,LOW); } }

Touch here for the full post on the Arduino Apprentices tumblr

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s