My Cart

Arduino Punched Card ReaderJune 11, 2012

A simple card reader using two pins of the Arduino.

Each card represents a Byte,  characters  can be seen in the terminal of the Arduino IDE .

The Sketch:

/* PunchCardReader
   Arduining.com 29/06/2011
*/
#define  clock  8   //clock input in digital pin 8. 
#define  data   9   //data input in digital pin 9.
byte Byte;          //store the incoming 8 bits.

void setup() {                
  digitalWrite(clock, HIGH);    // Connect Pull-Up resistor.
  digitalWrite(data, HIGH);     // Connect Pull-Up resistor.
  Serial.begin(9600);  
}

void loop() {
  Byte=0;
  while(digitalRead(clock)==0);     //wait for card in(rising edge).
  delay(20);                        //debounce
  for(int i=0; i<8 ;i++){
    while(digitalRead(clock)==1){}; //wait for a falling edge.
    delay(20);                      //debounce
    while(digitalRead(clock)==0);   //wait for a raising edge.
    delay(20);                      //debounce
    Byte= Byte << 1;
    Byte= Byte | !(digitalRead(data));
    Serial.print(!(digitalRead(data)));        
    }
  while(digitalRead(clock)==1){};   //wait for card out.
  delay(20);                        //debounce 
  Serial.print(" = ");
  Serial.println(Byte,BYTE);
}

Via and Source: Arduining

Leave a Reply