The project is a self service bar ...the customer pay's let's say £10 + deposit for card . The RFID reader on the bar reads the card if there is any credit left
on the card pin 13 gives 5v to relay that opens selenoid to allow beer to be dispensed .the customer would press a button on the bar they have filled there pint that would send 5v to pin 10 that would close selenoid and look for next card .when there is no credit left pin 13 will go low closing the selenoid . this works fine as long as I don't loose power to arduino as this would reset
all cards to there original value and I would be giving beer away .
but that is not my main problem . what I would like to do is have more than one self service bar and to be able to read card at any bar and know what credit is left on card
I would be very grateful of any help anyone could offer…..
this code reads a RFID card and adds one to count every time it gets a pulse from flow meter until the count reaches
the value of "maxcount" then it prints no credit left . if at any time pin 10 gets 5v the program returns to the bailout line in the program . the next time
this card is detected the count will continue where it left off ....
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
// Take note of the pin numbers
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
static int lastState = 0;
static int count = 0 ; //number of pulses for each card
static int countb = 0 ;
byte data[5]; //For holding the ID we receive
int val = 0;
byte jeremy[5] = {
0x3E,0x00,0xFC,0xBD,0x88};
byte david[5] = {
0x45,0x00,0x6A,0x8B,0x9B};
int outputPin = 1; //names pins
int inputPin =2;
int breakPin =5;
int maxCount ; //number of pulse's before this card shuts off
int timeout = 0 ;
//int newcard =
void setup()
{
//lcd.setCursor(0,7);
// Print a message to the LCD.
// lcd.setCursor(0, 1);
//lcd.print(" Mad Dave's Bar");
Serial.begin(19200); //just for now so i can see what's going on
Serial.print(0xFF,BYTE); //Header
Serial.print(0x01,BYTE); //Reserved
Serial.print(0x09,BYTE); //Length (Command + Data)
Serial.print(0x87,BYTE); //Command (0x87 sets auto mode behavior
Serial.print(0x01,BYTE); //Data 1: Enable Auto-Read
Serial.print(0x03,BYTE); //Data 2: Mode – Parity decoded – Manchester RF/64
Serial.print(0x02,BYTE); //Data 3: Total number of block to be read (2)
Serial.print(0x00,BYTE); //Data 4: No password expected
Serial.print(0x10,BYTE); //Data 5: Password byte 1
Serial.print(0x20,BYTE); //Data 6: Password byte 2
Serial.print(0x30,BYTE); //Data 7: Password byte 3
Serial.print(0x40,BYTE); //Data 8: Password byte 4
Serial.print(0x37,BYTE); //Checksum
delay(500);
Serial.flush();
Serial.println();
pinMode(outputPin,OUTPUT);
pinMode(inputPin, INPUT); //make's pin 10 input pin
pinMode(breakPin, INPUT); //this is used to breakout of while loop
}
void loop()
{
bailout: // this is for the goto statment ( sorry but i can not thing of any other way but goto )
digitalWrite (outputPin, LOW);
lcd.begin(16, 2);
lcd.print("Waiting for Card ");
val = Serial.read();
while (val != 0xff)
{ //On Successful read, first byte will always be 0xFF
val = Serial.read();
delay(1000);
}
//we already read the header (0xff)
Serial.read(); // reserved
Serial.read(); // length
Serial.read(); // command (indicates tag data)
data[0] = Serial.read(); // we read data 1
data[1] = Serial.read(); // we read data 2
data[2] = Serial.read(); // we read data 3
data[3] = Serial.read(); // we read data 4
data[4] = Serial.read(); // we read data 5
Serial.read(); // checksum
// Indentify RFID Card
boolean j_card = true;
boolean d_card = true;
Serial.print("Card found ");
for (int i=0; i<5; i++)
{
if (data[i] < 16) Serial.print("0");
//Serial.print(data[i], HEX);
//cross-check
if (data[i] != david[i]) d_card = false;
}
digitalWrite (outputPin, HIGH);
if (d_card)
{
Serial.println("Credit On Card ");
while(digitalRead(5))
{
int maxCount =20;
if (count > maxCount) //when count gets to the set number sends 5v to pin 13
{
Serial.println("NO CREDIT LEFT REMOVE CARD");
digitalWrite(outputPin, LOW); // power to relay to shut flow
goto bailout;
}
digitalWrite (outputPin, HIGH);
int newState = digitalRead(inputPin); //pulse from flow meter
if (newState != lastState) //detect change
{
count ++; //adds one to count
lastState = newState;
}
}
}
// looks for next card number
//The program will repeat the for the next card but change count to countb and maxcount to maxcountb and so on
}