I'm a college student and am planning a to do project, most likely using Arduino. I'm fairly new to programming, but I am a quick learner. What I want it to do is to be able to read a sort of "key" that has holes punched in it, representing an 8-bit code (ex. 00010010) which has been preassigned to a name or something. I'm trying to figure out the best way to make it read the key, access the assigned thing, and be able to display it, either to a PC monitor or LCD screen. Any suggestions on how I can do this?
How many keys? How big are they?
You could use a LED/LDR (Light emitting diode/Light detecting resistor) pair that the key passes through. Read the value of the LDR at appropriate times, to see if it's a 0 or a 1 at the position. The problem with this scheme is moving the key at the correct speed past the sensor.
You could have the key hold still, and use 8 LED/LDR pairs. The problem here is getting the LDR/LDR pairs to match the spacing on the key.
Once you are able to read the number from the key, the rest is trivial, if the number of key/value pairs is small. It's less trivial if the number of keys is large.
Well, to sense the holes you have a couple options (I won't go into the Hollerith pins-into-pools-of-mercury switch concept):
- optical
- electrical
For optical, you could build a reader that has 8 LEDs on one side of the card, and phototransistors or photoresistors on the other side; since you are using an Arduino, and you only have 6 analog inputs, and this is a first project, using phototransistors would be the better option (wire them to 8 digital i/o lines on the Arduino). Where the light passes thru the card, read it as a 1 or a 0 (whatever the "holes" mean in your logic).
For electrical, you simply use spring contacts (pieces of spring steel bent mental contact "fingers"), so that when you slide the card into the reader, where there are holes, contact is made with the pad underneath the spring finger, completing the switch circuit. You would want to add some pull-down resistors to this as well, contact would indicate a HIGH value, no contact with the pull-down would indicate a LOW.
The benefits of the first option are non-contact usage, long life for the reader. The downsides are it is more difficult to build for a beginner. The benefits of the second option are that it is easier for a beginner to build, but the downsides are a shorter life; but since this doesn't seem to be a long-term usage project (unless it is - you didn't say what the reason for the project was for?), that might not matter.
Once you have read the card (using digitalRead() function calls), you would then take the bits read, assemble them into the byte value you are looking for, then you have a couple of options (you didn't specify where the names were stored):
-
If you store them on the Arduino as a character array, just use your value you assembled as the index to look up the string in the array, and store it in a variable.
-
If you are storing them on a PC, things get tougher - you will have to communicate serially to the PC, the PC would read the value (with some kind of program waiting for data on the serial port), look up the data based on that value (the "key" - perhaps as an index into a database table?), then return that data back to the Arduino over the serial line, which would then read and store it in a variable.
Then, if you wanted to print it to an LCD, use one of the LCD libraries and a character LCD (2 line by 16 character ones would work fine) to dump the value of the variable (the char array "string" of the name) to the LCD.
If you wanted it to be returned to the PC: If the lookup was done on the Arduino, then you could dump it over the serial line, and a program reading the serial line could decide how to display it; if the lookup was done on the PC - then just have the program monitoring the serial line for the numeric key value print it out however you need to, instead of sending it back to the Arduino (although ultimately, you should send -something- back to the Arduino to let it know "hey, I got your message OK").
Hope this helps!
Thank you. This will be extremely helpful for me.
Basically the "key" is something similar to a house key. It's a physical object with a long tab or bar that has holes drilled into it, kind of like a punch card.
I was thinking of LED's and LDR's to read the key, since it would be more reliable than having physical contact and possible read errors
The project I have in mind is a robot that could be introduced into a classroom or workshop, which students have a key that has their name or ID assigned to each binary number
(John Smith 000001
Jane Doe 000010...etc.)
when the key is read, their name or ID number will be displayed, and a list can be recalled to see all the ones didn't key in.
Another way to do that was perhaps have a group of LEDs, depending on the number of people, and a corresponding LED will light up when someone keys in, although that may be too complicated.
You will want to use phototransistors, not LDRs (which are another name for photoresistors):
Also known as "CdS" cells (cadmium sulphide cells):
You only need to detect on/off values, not levels, and there aren't enough analog input pins on the Arduino for LDRs anyhow.
I might also add a "fully inserted" switch for the card, this way the Arduino knows if/when a card is inserted all the way, then can do the read properly. That, or add an extra hole and sensor, or something like that.