E-Cheque : Paper Free Billing System

AIM:

The aim was to create an automated billing system which operates on RFID tags to store balance and customer information.

The RFID module is interfaced to an Arduino which in turn is programmed to store data in a MySQL database. The connection between an Arduino and MySQL database is achieved through the use of Python.

STEPS EXPLAINED:

After interfacing the RFID Reader EM-18, Arduino UNO Board and 4×3 Keypad, we proceed to the next stage i.e, coding.

  1. Arduino Uno IDE – The Arduino Uno is programmed to make it functional with the 4×3 Keypad and the RFID Reader EM-18.
  2. A MySQL Database is created by the name of ‘Minor’. This database has our prime table ‘Student_info’.

Student_info table has the following attributes :

  • RFID_no – The unique RFID tag number that is issued to each student. (this is the primary key)
  • Student_name – Name of the holder of RFID tag. This information has to be submitted by the student upon creation of a new account with the issue of tag.
  • Bal_deducted – The balance deducted after the last transaction.
  • Balance – The total remaining balance in the card.

Each student is credited with Rs.1000 upon creation of account.

  1. Python programming is done with the objective of serial communication between the USB that connects the Arduino to PC and the MySQL database created in the previous step.

Assuming successful connection of Arduino with the PC, the following steps are performed:

 floq

CODE USED IN ARDUINO :

#include "Keypad.h"
#ifndef ARDPRINTF
#define ARDPRINTF
#define ARDBUFFER 16
#include "stdarg.h>
#include

int ardprintf(char *str, ...)
{
  int i, count=0, j=0, flag=0;
  char temp[ARDBUFFER+1];
  for(i=0; str[i]!='\0';i++)  if(str[i]=='%')  count++;

  va_list argv;
  va_start(argv, count);
  for(i=0,j=0; str[i]!='\0';i++)
  {
    if(str[i]=='%')
    {
      temp[j] = '\0';
      Serial.print(temp);
      j=0;
      temp[0] = '\0';

      switch(str[++i])
      {
        case 'd': Serial.print(va_arg(argv, int));
                  break;
        case 'l': Serial.print(va_arg(argv, long));
                  break;
        case 'f': Serial.print(va_arg(argv, double));
                  break;
        case 'c': Serial.print((char)va_arg(argv, int));
                  break;
        case 's': Serial.print(va_arg(argv, char *));
                  break;
        default:  ;
      };
    }
    else
    {
      temp[j] = str[i];
      j = (j+1)%ARDBUFFER;
      if(j==0)
      {
        temp[ARDBUFFER] = '\0';
        Serial.print(temp);
        temp[0]='\0';
      }
    }
  };
  Serial.println();
  return count + 1;
}
#undef ARDBUFFER
#endif 

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
int val;
int ch;
char key;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

#define RELAYPIN 13
#define WARNLEDPIN 12

char tag[] ="19004B3BB1D81"; // Replace with your own Tag ID
char input[12];				// A variable to store the Tag ID being presented
int count = 0;				// A counter variable to navigate through the input[] character array
boolean flag = 0;
int sum=1000;
int ch1;

void setup()
{
	Serial.begin(9600);		// Initialise Serial Communication with the Serial Monitor
	pinMode(RELAYPIN,OUTPUT);	// RELAY OUTPUT
	pinMode(WARNLEDPIN,OUTPUT); //WRONG TAG INDICATOR
}
void loop()
{

	if(Serial.available())// Check if there is incoming data in the RFID Reader Serial Buffer.
	{
		count = 0; // Reset the counter to zero
		/* Keep reading Byte by Byte from the Buffer till the RFID Reader Buffer is	empty
		   or till 12 Bytes (the ID size of our Tag) is read */
		while(Serial.available() && count < 12)
		{
			input[count] = Serial.read(); // Read 1 Byte of data and store it in the input[] variable
			count++; // increment counter
			delay(5);
		}
		/* When the counter reaches 12 (the size of the ID) we stop and compare each value
		    of the input[] to the corresponding stored value */
		if(count == 12) //
		{
			count =0; // reset counter varibale to 0
			flag = 1;
			/* Iterate through each value and compare till either the 12 values are
			   all matching or till the first mistmatch occurs */
			while(count<12 && flag !=0)
			{
				if(input[count]==tag[count])
				flag = 1; // everytime the values match, we set the flag variable to 1
				else
				flag= 0;
                               /* if the ID values don't match, set flag variable to 0 and
                                  stop comparing by exiting the while loop */
				count++; // increment i
			}
		}
		if(flag == 1) // If flag variable is 1, then it means the tags match
		{

			Serial.println("Access Allowed!");
                       Serial.print("your balance is = ");
                          Serial.println(sum);
                       Serial.println("enter amount that is to be deducted");

                       keypadk();

                      Serial.print("Deducted amount is=");
                      Serial.println(val);

                       sum= sum-val;
                      Serial.print("new balance is =");
                      Serial.print(sum);

                       ardprintf(" %s Ashmita %d",tag, sum);

                        digitalWrite(RELAYPIN,HIGH);
			delay (5000);
			digitalWrite (RELAYPIN,LOW);

                       int famt=final();
                       Serial.println("your final amount is =");
                       Serial.println("famt");

                       }
		else
		{
			Serial.println("Access Denied"); // Incorrect Tag Message
			digitalWrite(WARNLEDPIN,HIGH);
			delay(5000);
			digitalWrite(WARNLEDPIN,LOW);
		}
		/* Fill the input variable array with a fixed value 'F' to overwrite
		all values getting it	empty for the next read cycle */
		for(count=0; count<12; count++)
		{
			input[count]= 'F';
		}
		count = 0; // Reset counter variable
	}
}

void keypadk()
{val=0;
while(key!='#')

{
char key = keypad.getKey();

if (key != NO_KEY){
Serial.print(key);

if(key=='#')
{
return;
}
ch=(int)key;
ch1=ch-48;
val=((val*10)+ch1);
}
}}

CODE USED IN MySQL :

create database Minor;
use Minor;
create table Student_info
( RFID_no varchar(40) NOT NULL PRIMARY KEY,
Student_name varchar(20),
Bal_deducted varchar(5)
Balance integer(10));

CODE USED IN PYTHON:

#header files
import serial
import time
import MySQLdb

#establish connection to MySQL.
dbConn = MySQLdb.connect("localhost","root","pass","Minor") or die ("could not connect to database")
#open a cursor to the database
cursor = dbConn.cursor()

#specify port number and baudrate
ser = serial.Serial('COM27', 9600)
while 1:
         #time.sleep(10)
         data = ser.readline()
         info = data.split()
         cursor.execute("INSERT INTO Student_info(Bal_deducted,RFID_no,Student_name,Balance) VALUES (%s,%s,%s,%s)",(info[0],info[1],info[2],info[3]))
         print info[0],info[1],info[2],info[3]
         dbConn.commit()
         cursor.execute("SELECT * from Student_info")
         cursor.close()
Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s