Home > Exploring Ideas > Arduino Punched Card Reader

Arduino Punched Card Reader

A simple card reader using two pins of the Arduino.
A travel in time to the old days when programs were typed on punch cards.

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

In the following diagram you can see the timing.
When the CLOCK changes from LOW to HIGH the DATA is loaded.

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);
}

Enjoy the Youtube presentation:

Advertisements
Categories: Exploring Ideas
  1. January 5, 2013 at 2:55 PM

    I’m having problem using your code on Arduino 1.0.2.

    The error says: the keyword ‘BYTE’ is no longer supported

    What should I do?

    I also have Arduino 0.22 because some libraries are no supported by the 1.0 and later versions of the IDE

  2. January 9, 2013 at 10:48 PM

    Replace::
    Serial.println(Byte, BYTE);
    By:
    Serial.write(Byte);
    Serial.println(“”); // To send a LF

    Will be desirable that the Arduino environment keep compiler backwards compatibility to avoid
    rewriting old code. I think Arduino 1.0.3 solve this, I have to check.

  3. alex
    March 10, 2013 at 2:43 PM

    Replace::

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

    By:

    void setup() {
    pinMode(strobe, INPUT_PULLUP);
    pinMode(databit, INPUT_PULLUP);
    Serial.begin(115200); //use 115200 for stellaris of texas instrument
    }

  4. Leonardo
    September 2, 2013 at 9:59 PM

    Hi, very nice project! Is it possible to use a more user friendly java text interface for the output? I’m gonna use this for educational purpose, and I’d like to show the output more stylish, you know?
    Thanks.

  1. June 11, 2012 at 8:51 PM

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

%d bloggers like this: