Help in a small project - Control several locks

Hi all,
I bought the Arduino to learn about electronics and hopefully create some cool stuff in the future... I have done lots of small exercises to understand most of the concepts and I came across the 74HC595 shift registers which I got 2 of them.
Now in my first own project I want to lock and unlock about 128 electric locks (can somebody point out any lock which would do this job?).
Basically I want to send data from the PC to the Arduino interprets and lock/unlock the respective lock. I.e.: I send the data to open the lock number 57 and it opens... Or I want to open the lock #102 and it opens.
Can somebody give me ideas on how to implement it?
Any help would be very appreciated. it could be help on how to write the correct code as well as which piece(s) of hardware is needed.

Right below is the code I am using to control 16 LEDs as a concept... I got part of the code in a website and other part I did myself. The hard-code part was done by myself (the if part on line 50 onwards)

Pleeaaase help me on this! I am struggling on this alone...

Regards,
Lauro Ojeda

/*
 Shift Register Example for 74HC595 shift register
 This sketch turns reads serial input and uses it to set the pins of a 74HC595 shift register.

 Hardware:
 * 74HC595 shift register attached to pins 2, 3, and 4 of the Arduino, as detailed below.
 * LEDs attached to each of the outputs of the shift register
 Created 23 Mar 2010
 by Tom Igoe
 */
 
const int latchPin = 8; // Pin connected to latch pin (ST_CP) of 74HC595
const int clockPin = 12; // Pin connected to clock pin (SH_CP) of 74HC595
const int dataPin = 11; // Pin connected to Data in (DS) of 74HC595

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Input the LED number to turn on.");
  Serial.println("Type reset to disable all.");
}

void loop() {
  if (Serial.available() != 0) {
    // ASCII '0' through '9' characters are represented by the values 48 through 57.
    // So if the user types a number from 0 through 9 in ASCII, you can subtract 48 to get the actual value:
    // The -1 value at the end is just to allow the user to enter values from 1-8 instead of 0-7 -> By Lauro
    // By Lauro: from 97 to 122 means from a-z
    int bitToSet = Serial.read() - 97;
//Serial.println(bitToSet);
    registerWrite(bitToSet, HIGH); // write to the shift register with the correct bit set high:
  }
}

// This method sends bits to the shift register:
void registerWrite(int whichPin, int whichState) {
  byte bitsToSend = 0; // the bits you want to send
  unsigned long v = 0;
  unsigned long v1 = 0;
  unsigned long x = 0;
  
  digitalWrite(latchPin, LOW); // turn off the output so the pins don't light up while you're shifting bits:

  //bitWrite(bitsToSend, whichPin, whichState); // turn on the next highest bit in bitsToSend:
  v = 1 << whichPin;
  x = v;
  if(v > 128){
    v1 = v / 256;
    v = 0;
  }
  else{
    v1 = 0;
  }
  shiftOut(dataPin, clockPin, MSBFIRST, v); // shift the bits out:
  shiftOut(dataPin, clockPin, MSBFIRST, v1); // shift the bits out:

  digitalWrite(latchPin, HIGH); // turn on the output so the LEDs can light up:

  Serial.print("Decimal value read: ");
  Serial.print(whichPin);
  Serial.print(" - bitsToSend: ");
  Serial.print(bitsToSend);
  Serial.print(" - abs: ");
  Serial.print(x);
  Serial.print(" - v: ");
  Serial.print(v);
  Serial.print(" - v1: ");
  Serial.println(v1);
}

What sort of locks do you need? Do you mean something that would lock a box, car, room, fence. Would they have to resist attack from a thief?

How far away from the Arduino will the locks be?
If they are a long way off, it may be better to use a different approach, where each lock has a local bit of intelligence.

HTH
GB

HI,
Thank you for update.
Well, I need some sort of locks to use in small safes, just like the ones you can find in train stations or bus terminals where people can leave their stuff while hanging around the city.
Yes, indeed! They must protect people's goods, so they need to be a bit strong.
They wouldn't be too far from each other. Maybe 50cm away from each other and no more than 3 meters away from the Arduino/PC.

Regards,
Lauro

Wow.

I know a pretty sophisticated locksmith, and might see him next week (less than 50:50 chance though), so I will ask him.

Do you want it to fail locked, or fail open?
(I assume you've considered things like liability insurance etc.)

I'd expect locks to be a reasonably large amount of current, so you might want to look at simple driver chips like ULN2803, which can drive about 10x more current than an Arduino pin or 74HC595 pin.

As for communication between host and Arduino, have a look at the Arduino File->Examples->Communication->Dimmer

Focus on the Arduino part first which is

const int ledPin = 9;      // the pin that the LED is attached to

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) {
    // read the most recent byte (which will be from 0 to 255):
    brightness = Serial.read();
    // set the brightness of the LED:
    analogWrite(ledPin, brightness);
  }
}

You can start the Arduino Serial Monitor, and type a single character in, and that will get sent to the Arduino.

Maybe change the program so that instead of analogWrite() you take the 8-bit character value, and switch your LEDs on in the pattern to match.

There was a recent thread where someone wanted to read a number for the PC, and do something with it http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1270827974/all

HTH
GB

Hi GB,
Thanks for interest in the project and in helping me out...
I would appreciate a lot if you could talk to your friend about the project. Any help will be very welcome!
Actually I have managed to make Arduino communicate with PC, but using only letters a-z which gave me the possibility of control 26 LEDs. Over than that I don't know how to make the ASCII/Arduino to "understand" numbers over than 10. That's the first difficulty.
The second is to improve the code allowing it to manage up to 16 shift registers.
The third main difficulty is to find a suitable lock which would be able to be managed by the Arduino.

I am going to read the threads indicated by you... That's a great start, but please don't forget to get the suggestions from your locksmith fella!

Thank you again!

Regards,
Lauro

It might be worth looking at the way that binary numbers work.

Here's a bit of background which might help.
You can write binary numbers in sketches/programs using 0b, and the digits 0 or 1, e.g. 0b11111111
That's 8 binary digits (bits), and fits into a single character, or byte.
Ultimately everything is represented as binary numbers.
A character, for example 'a', is also the number, written in decimal as 97, and the binary pattern 0b01100001, 'z' is 122, or binary 0x01111010
A single character can represent every number from 0 to 255, so you'd only need one or two characters to tell your lock control which lock to act upon.

I can't promise when I'll see the locksmith, sorry.

I did google around, and found lots of sophisticated locks, but I assume you are looking for something lower in cost?

GB