Project journal


Project TimeTable:

Today I have been working on creating the website, I started with the database. I have created simple database with a table, the main idea is to display the data saved in the database, then I worked on inserting data to a selected database. I have a success results on doing that. then I succeeded to insert data remotely via the URL, because my project is rely on that. For example:
the website will be waiting for that RFID code then insert it on the database, the results of that will be this tag "54s5d4fsd455421sds4" inserted on the database. I did the basic staff to refresh my memory with the PHP programming.

What's next?


This week I have manage to insert two values and more within the URL that will be transmitted by the Arduino using PHP language, the use of inserting more value is transmitting the unit code and the RFID tag for example:
client.println("GET http://*****.com/****.php?unit=302&RFIDtad=32423j324k234 ");

In this example, the device sends 2 GET query to the website. The first one is for the unit code (which is the keypad input) and the RFID tag code (which is the reading from the students cards). The results were successfully presented, if there is need to add another GET value to be sent via the URL we simply add (&).

In addition, I have manage to establish the keypad connection and displaying the inputs number onto the Serial Monitor.

The keypad connection:

Real life connection:

What's next?

Due to unexpected delivery delay, the scheduled works for RFID will be delayed. for this reason, the work of week 9 moves to week 8:


Database details:

In MySQL, I have used 4 tables to store the data in.
1- Attendance: is a table that contains the data sent by the device. in the meantime this table contains unit code and RFID tag which is remotly inserted by the URL via the device, in addition, an ID row as an auto-increment INT and date which is the date of inserting the data.

2- RFID: is a replacement table to university students ID database, the use of this table is to declare the RFID tags into a student number to be presented on the attendance analyzer. This table contains 3 rows which are ID, tag and student number.

3- Units: is a table that holds the units runs by specific user. This table contains id, user_id, unit code and unit name. The teachers can add the runs unit in the profile page, each user have a unique id, this id will be placed on the user_id row. This row will display the units details that matches the users ID.

4- Users: is a table that contains the users on the website. It has 4 rows which are id, username, password and email. the use of this table is to login and access the units that matches the user. An encryption used for password row for security vulnerabilities, the encryption used is MD5.

Website contents:

The incoming data from the device are unit code and RFID tag. these data transmitted via GET command on the Wifly shield. The user logged in to the website can track the attendance. Tools provided on the website for database management fro example: edit, add and delete units runs by the user, as in the Profile page:

In the image above, the displayed units are for the logged in user, to do this I used a WHERE condition to avoid displaying the data to the wrong user:

$units = mysql_query("SELECT * FROM units WHERE user_id = '".mysql_real_escape_string($loggedin_id)."' ");

The $loggedin_id and $loggedin_username are sessions for the logged in user, it has been defined on the database connection page, as:

IF (isset($_SESSION['loggedin_id'])&&isset($_SESSION['loggedin_username'])) {
$loggedin_id = (int)$_SESSION['loggedin_id'];
$loggedin_username = $_SESSION['loggedin_username'];

For testing purposes, I have used the home page to display the entries of the device (manually via the URL), For example:

The results will be the first line:


Problems and technical solutions for this week:

On 22/03 I received the RFID reader (ID-12), I tried to connect it and make it read, but I faced a problem which is the Pins are narrow to each other and it can't be connected to the breadboard. I used laboratory equipment to print new board to make it fit in breadboard.

2- Keypad
In the Serial Monitor, the input inserted are presented by one input only. Hence, the requirement of keypad is to transmite the lecture/unit code which is 3 characters long. this problem will effect the transmitting method. To solve this problem, I used an array function to store the input data to 3 characters long, I added new control functions to make use of (*) and (#) in the keypad. The (*) will reset the input to 0 for example: input = 54(*)354 the result is 354, as inserting number(s) and made a mistake, the (*) will reset the value. The (#) is to send number smaller than the maximum input, for example: input=34(#) the result is 34.

3- WiFly
In the WiFly connection setup I faced an error of declaring 'Client' I tried to solve it in many ways, the problem is the WiFly library has not supported on the new Arduino program (v1.0). To resolve this problem I had to change the library to edited one by one has the same problem. The second problem was transmitting the data as MySQL query, this problem take more than I expected as the I tried to transmitted in many ways:
client.println("GET http://*****.com/****.php?unit={UnitCode}&rfid={UnitCode} HTTP/1.0"); 

client.println("GET http://*****.com/****.php?unit={'UnitCode'}&rfid={'UnitCode'} HTTP/1.0");

client.println("GET http://*****.com/****.php?unit=(UnitCode)&rfid=(UnitCode) HTTP/1.0");

client.println("GET http://*****.com/****.php?unit=");

And similar changes, all the results are failure. At the end the solution was by controlling the lines using the command "client.println" and "client.print" the different between them is creating new line, as the use of MySQL require the URL once, so the URL should be inserted as one line. The solution for my code is:

The final results:


During the start of this week I have manage to establish the buzzer to alert on the following:
1- Booting the device.
2- Device is connected to a WiFi modem.
3- Inserting numbers through Keypad.
4- Scan RFID tag.
5- Receives the three unit code number.
6- Error on connection.
7- Clear keypad input.

The buzzer used to achieve this results is (8 ohm small speaker) connected to 100 ohm resistor as the circuit below:

The buzzer tones are represented on certain frequencies, these frequencies are defined on external file, for example:

tone name freq
#define NOTE_D3 147

Tones frequency for each alert:
1- Booting the device. [Frequency: 698 Hz]
2- Device is connected to a WiFi modem.[Frequency: 698 Hz, 880 Hz and 784 Hz]
3- Inserting numbers through Keypad.[Frequency: 1175 Hz]
4- Scan RFID tag.[Frequency: 3520 Hz]
5- Receives the three unit code number.[Frequency: 1568 Hz]
6- Error on connection.[Frequency: 62 Hz]
7- Clear keypad input. [Frequency: 123 Hz]

The code to play the tones connected to digital pin 9:

At this stage I have finished doing the following:
  1. Keypad (include an array to store three numbers to represent the unit code)
  2. Buzzer (include alerting on each stage of the device)
  3. Wifly shield connection (include transmitting values)
  4. Database tables to store the data and simple php code to display it.


The RFID (ID12) reader is not functional to read the student ID card, attempts were made after sourcing a more complete datasheet and 7 separate tutorials were failed . Then I tried to test 125kHz RFID tag the results were succeed. The RFID (ID12) cannot read the student cards ID as it is 13.56MHz frequency. UoP student cards has been tested and the result is:

This test has been made last year by one of the university of Portsmouth students link.

After a lot of effort made to make the RFID transmit the data via Wifly shield, all the results are failed, the reason behind the failure was, both the RFID and wifly shield uses RX serial port (also known as a UART or USART) to receive data. The only solution is to change the RFID serial port, this is done by using SoftwareSerial.h then define the RX and TX to different ports, in my project I used the analog inputs as I'm running out of digital ports, the code used to identify them is:

SoftwareSerial rfidSerial(15, 14); // (RX, TX)

The circuit to connect RFID is:

The results of scanning RFID cards:

After success connection between the RFID and Keypad:

Then, after changing the RX port to the RFID, I have mange to connect it to the database, results from Serial Monitor of Arduino program:

Successful transmitted to the database:

At this stage I have successfully connected the hardware part, that's include:
  1. Keypad (include an array to store three numbers to represent the unit code)
  2. Buzzer (include alerting on each stage of the device)
  3. Wifly shield connection (include stay connected and transmitting unit code and RFID tag)
  4. RFID (read/transmit)
Next stage (Software part):


The device has been programmed to read the RFID tag then transmit it to the web-server, to do this steps we should make sure that we have the unit (lecture) code before start reading and transmitting the tags. In addition, the WiFly connection should be obtained before doing all of this processes.
Flowcharts of device process:

At the start the device will determine the input and output pins, then establish the wifly connection. If the device connected, it will process to an array to obtain the 3 numbers unit code via the Keypad. At this point, the RFID start working to read tags, each tag will be transmitted after reading it. the value of unit code will not change in each reading. In other hand, the value of RFID tag reset after each reading.

Device schematic diagram:

Recently I have been working on the user interfaces, at the start I did the layout design to have clear idea on what to display on the website. First, I have draw the sketch of the layout, then design it.

Sketches of user interfaces:

The design:

Layout specification:
1- Body width 900px.
2- Content width 560 px.
3- Side width 240px.
4- Menu, header and footer width 900px.

Today I received 10x 125kHz RFID tags (cards). At the start I read the cards tag to create a database with a fake students names and numbers. I used this website to generate the names for me (link)

Then, I edited the RFID table in the database to include the student name, I placed the RFID tag, generated name and student number in the database.


Today I have rearranged my Logbook to be sorted by day as I was using most updated first, then I moved uploaded photos to the photo gallery. Then I have started to program the user interface with PHP language. At home page, recent logs to display the overall attendance in each lecture has been scanned by the device, in this case I'm going to use the table 'attendance' where the device create this logs. to display the following:

(unit code)
Number of students attending the lecture on (date) are (number of student) students

The text colored by red means changing value depend on what information is displaying, To this step I have used SQL query to get the data from 'attendance' table with using 'count', 'GROUP BY' and 'ORDER BY DESC'.

    $rfid = mysql_query("SELECT ID, unit_code, date, COUNT(tag) AS students_count FROM attendance GROUP BY date, unit_code ORDER BY ID DESC ");
    IF (mysql_num_rows($rfid)>=1) {
   while ($rfid_row = mysql_fetch_assoc($rfid)) {
   $id = $rfid_row['ID'];
   $unit = $rfid_row['unit_code'];
   $date = $rfid_row['date'];
   $students_count = $rfid_row['students_count'];
   echo '
         Number of students attending the lecture on '
.$date.' are '.$students_count.' students</p>

In this code, the use of 'GROUP BY date' is to display each log separately by day and adding to it 'GROUP BY date, unit_code' is to separate the units. as the result of only using date, will occur gathering all students attending in the selected day into one unit.

The use of 'COUNT(tag)' is to count the tags that has same unit code and date to display the number of students attending.

The use of 'ORDER BY ID DESC' is to display the data on descending order as the most recent first.

The result of this code is:

In page we can see we have three units with same unit code but different date and two units with same date but different unit code.

Need to modify in this code:
- Display the units data matching the user units.
- Calculate percentage.


Today I have successfully modified the Recent Changes on the home page to display units matching the account holder units, as if user1 have 3 units, user2 won't have the same units on the recent changes. In addition calculating the overall percentage, this done by adding a unit row to table UNITS then taking the attendance number of each log and do the math which is ( (number of student attend / total number of attendance) *100) with taking only two decimal places.

The code for displaying the units matching the user account:
$rfid = mysql_query("SELECT attendance.ID, attendance.unit_code, attendance.date, units.unit, units.students , units.user_id, COUNT(attendance.tag) AS students_count FROM attendance LEFT JOIN units ON attendance.unit_code = units.unit WHERE units.user_id = '".mysql_real_escape_string($loggedin_id)."' GROUP BY date, unit_code ORDER BY ID DESC");

The changes made is to take from two tables (LEFT JOIN units ON) and a condition to display the units that have same number as logged-in user from table units row user_id.

Calculating percentage:
$percentage = number_format((($students_count/$students)*100), 2, '.', '');

The result of this code is to display the percentage as (23.66) instead of (23.66666666666).

While testing the code, student can scan the card more at the same session which will occur a failure on tracking attendance (i.e Percentage and number of students attend). For that reason, I have modified the reception code from the device to check if the details received already been scanned or not, if NO then insert them. If YES then return error.

To check the scanned data:
$checksql = mysql_query("SELECT date, tag, unit_code FROM attendance WHERE tag='$rfid' AND unit_code='$unit' AND date='$date' ");
$check = mysql_num_rows ($checksql);
IF ($check!=0){
  echo'Already exists!';
} else {

The next step is to create the attendance sheet.


During the Easter break, I have manage to display the attendance sheet which display student's number and their attendance for selected unit. It has an auto date creation where if a student has a log on new date the attendance sheet automatically create a date for all the student and calculate the percentage. At the start I had problem for doing this sheet where the data displayed only for students attende the lecture and not ordered in the correct position, to fix this problem I used a loop to display the dates and check attendance at the same time with using an additional SQL query to check the tags and place (√) or (x) on each field.

$sheet = mysql_query("SELECT * FROM attendance WHERE unit_code='$unit' GROUP BY date ");
         IF (mysql_num_rows($sheet)>=1) {
            while ($sheet_row = mysql_fetch_assoc($sheet)) {
                $date = $sheet_row['date'];
                echo '<td valign="top">
                <table width="100%" border="0">'
                echo '<tr><td><strong>'.$date.'</strong></td></tr>';

                  $studentx = mysql_query("SELECT tag FROM rfid");
                  while ($rowx = mysql_fetch_assoc($studentx)) {
                     $tag = $rowx['tag'];

                                                        $checksql = mysql_query("SELECT tag, unit_code, date FROM attendance WHERE date='$date' AND unit_code='$unit' AND  tag='$tag'");
                                                        $check = mysql_fetch_assoc ($checksql);
                                                        $tag1 = $check['tag'];
                                                        $date1 = $check['date'];
                     IF ($tag==$tag1) {
                                                                IF ($date1==$date) {
                          $isattend = '&#8730;'; //yes
                                                                } else {
                                                                  $isattend = '&#215;'; //no
                     } else {
                       $isattend = '&#215;';  //no

                     echo '<tr><td>'.$isattend.'</td></tr>';
                                      echo '</td></table>';

For calculating percentage:

$totaldates = mysql_query("SELECT unit_code, date FROM attendance WHERE unit_code='$unit' GROUP BY date");
                        $dates = mysql_num_rows ($totaldates);

                        echo '<td valign="top">
                             <table width="100%" border="0">'
                        echo '<tr><td><strong>Avrage</strong></tr></td>';

                        $studentss = mysql_query("SELECT tag FROM rfid");
         while ($row = mysql_fetch_assoc($studentss)) {
                        $tag = $row['tag'];
                             $rfid = mysql_query("SELECT unit_code, tag, COUNT(tag) AS attendance_count FROM attendance WHERE unit_code = '$unit' AND tag ='$tag' GROUP BY unit_code");
                             $rfid_row = mysql_fetch_assoc($rfid);
                        $attendance = $rfid_row['attendance_count'];
                        $tag1 = $rfid_row['tag'];
                                   IF ($tag1){
                                      $math = (number_format((($attendance/$dates)*100), 0, '.', ''));
                                      $pecentage = ''.$math.'%';
                                   } else {
                                      $pecentage = '-';
                                   echo '<tr><td>'.$pecentage.'</td></tr>';


The final results:

Then I created a page to add, delete and modify the unites run by the lecturer. This page created to have management of the runs units, where the user can add units with three fields (unit code, unit name and number of students) this information can be edited or deleted.


LCD display has been connected and programmed to the device to display information to the user. The 8*2 character LCD chosen for the small size that's match the dimensions of the device as it 2.3*3.6 cm. 11 I/O pins are used to interface to this LCD screen. Includes LED backlight. The use of this LCD is to show three main things:

1- Device is power and connected to the internet.
2- Unit code to avoid any mistakes.
3- Number of scans, which could be use for realtime student attendance.

Welcome message ( which display AAR stand for Auto Attendance Recorder, Which means the device is powered)

Unit code:

Number of scans:

The overall device connection:


Today I have finish building the website to display the data include charts as attendance analyzer, at the stage of doing the attendance analyzer I have tried to install many libraries to display the graphs such as JpGraph, pChart and PHPGraphLib. I have faced some problem using them as it has to be included in the web which make it slow to run. After a multiple attempts I found a simple library to install as it only require a script link. at the <head> tag, this library called 'Google Chart API' which is under Google Developers.

Using this tools I have manage to display Line Chart for each date the unit runs and Column Chart for Student Attendance Average.

This picture shows the Line Chart for each date for unit 101

This picture shows the Column Chart for Student Attendance Average for unit 101

After a success result with the Google Chart API, I have created a search engine to display all the information about a selected student, this data includes his/her name, student number, a Column Chart for all units attendance percentage and all units attendance table.

Example of student number (675502) search results:

Note: the yellow box that shows an error of not finding the logs in the system means that this unit has no record at all in the system and the unit has not been used yet.

the box design had been designed by Page Janko and the icons used are from Knob Toolbar icons collection.

Due of using a large number of components in the hardware part the device become 3 times larger than the required dimensions which effect the main aim of this project of being portable. The parts used in this project are:
  1. RFID.
  2. Keypad.
  3. LCD display.
  4. Buzzer.
  5. LED.
  6. 10K resister.

I have manage to use Eagle program to design the circuit digram to print circuit board (PCB) at 1.8"x2" which it will fit above the Arduino device, using this PCB I'll manage to make the device in the same dimensions as the requirements.

Circuit Digram:



After receiving the PCB I had many problems connecting it, as it has a 2 side wiring which make it harder to connect. I have solved this problem by using a thin wire to connect the bins in both sides. Another problem occur because of not using headers to connect all the bins where the soldering breaks the linked bins.

Due to this problem I have designed new PCB to avoid these problems, the new PCB has only bottom connection and I used headers in each bin and using thin wires to connect between the Arduino and the PCB, I have manage to make it work finally.

In the other hand, I have booked an appointment with the mechanical labs monday the 14th of May to cut parts of my case design to make a room for keypad, LCD and switch. this all will be done as the case design below:

The current connection:

Update date 29/05/12

On monday the 14th of May I went to the mechanical lab and I have manage to build the case with placing the keypad on the bottom of the device and the LCD display on the top of the device.

I had so much problem connecting the WiFly shield to a portable hotspot (iPhone) to make a demonstration on the project day. The device is fully working at home broadband with all the Arduion Program specially on V1.0 . This problem takes much time and delayed the work.
Solving the problem was by changing the code to the lower version (0023) and connecting the device to Android smartphone. by doing that I manage to send 2 to 3 tags and the device stop responding, then I deleted this line:

client.println( "Host: www.naderr.com" );

After doing that, the device fully working on the portable hotspot, but not responding at home broadband. I tried to apply the same changes to the Arduion version 1.0 , the problem stay the same.

The conclusion of the wifly connection:
1- Wifly shield has more support on version 0023.
2- The Alpha2 library support the portable hotspot.
3- some functions in the code may affect the connection.

Moving back to the case design, I have used Google Sketchup application to design the case in 3D with the dimensions, I have manage to come up with this design:

The device is fully working. Special thanks to Mr Chi Nguyen for his support and help.

The end of the Logbook

Attachment Timestamp Size