Can't get sensor working.

I'm very new at this, so I might be making a really really stupid mistake, or simply have no idea what I'm talking about, but...

I'm trying to make an ambient light alarm clock with some code I've cobbled together from several examples. I think I have the board set up correctly.
I have a circuit from pin 9 to a buzzer to, I think a 340 Ohm resistor to the ground.
I have a second circuit from 5V to a Mini Photocell to, I believe, a 10K resistor then back to ground.
Between the Mini Photocell and the 10K resistor, I have a wire to analog input pin 0 to read data from the photocell.

The problem is with the code then, if I haven't been doing something horribly wrong above.

const int sensorPin = 0;     // pin that the sensor is attached to
const int ledPin = 9;        // pin that the buzzor is attached to

// variables:
int sensorValue = 0;         // the sensor value

void setup() {
  pinMode(ledPin, OUTPUT);
  buzz(ledPin, 2000, 500);
  buzz(ledPin, 2000, 500);

  Serial.begin(9600);
}

void loop() {
  // read the sensor:
  sensorValue = analogRead(sensorPin);
  Serial.print(sensorValue);//Right now at the time of writing this, it's at 1023
  //It stays the same all the time.  Even when I shine a light on it or cover it up.
  //It just won't change though, no matter what I do....
  Serial.print("\n");

  if(sensorValue < 400){
  //??????? Not sure what to put in here.. 
  //EDIT:  I had it beeping at one point, but was accidentally reading the wrong pin.
//With the correct pin, I haven't gotten it to beep at all.
    buzz(ledPin, 1000, 100);
    delay(70);

  }
}

void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2;
  long numCycles = frequency * length/ 1000;
  for (long i=0; i < numCycles; i++){
    digitalWrite(targetPin,HIGH); 
    delayMicroseconds(delayValue); 
    digitalWrite(targetPin,LOW); 
    delayMicroseconds(delayValue);
}

That's what I have so far, and the problems are all in the comments. I just don't know what I'm doing with the analogRead, and I don't know why it won't change, even when I shine light directly on the sensor. Can anyone point out what I'm doing wrong, please?

The photocell and the resistor are forming a voltage divider. The resistor should be approximately the same resistance as the maximum resistance of the photocell.

Have you measured the maximum resistance of the photocell? Is it maximum in total darkness or in bright light?

The photocell has a dark resistance of 10K Ohms and a light resistance of 1k Ohms.

I am using a 10K resistor, so that should be all right, assuming I have everything hooked up correctly. I figured it was a coding problem, so I brought it over here, but I'm new enough at this that it may just be me doing something stupid with the wiring.

I looked more at the analogRead documentation on line and the value 1023 is apparently the highest it will go, unless I read it wrong, so apparently I maxed out whatever I'm measuring.

Out of curiosity, is the analogRead measuring the resistance or the current?

Sorry for such newby questions...

Out of curiosity, is the analogRead measuring the resistance or the current?

Neither. It is measuring voltage. The voltage divider should, in total darkness, drop the voltage in half between the photocell and the resistor, since the resistance on both sides is the same. In bright light, the resistance of the photocell is small, so, most of the voltage drop will occur in the resistor.

So, in total darkness, analogRead should be returning 512. In bright light, it should be returning values larger than 512, but never quite 1023.

You do have the wire from the photocell/resistor junction going to an analog pin, right?

Maybe try a smaller resistor. Say a 1K.

The website lists the photocells max Voltage at 150, but I've got it plugged to a 5V power. Is that a problem?

Max power is 100 miliWatts.

I double checked the connection and it seems to be fine.

5V -----> Photocell --------> Wire that leads to pin 0 (analog in) --------->10 K resistor ---------> ground.

I'll hunt around and see if I can find a smaller resistor. The arduino and photocell came in a starter kit with a few 10K resistors and a couple 330 resistors, so I figure there must be some way to get it working with those.
Maybe I can run it through 3 of the 330 ohm resistors?

I understand what you're saying, which leads me to think I have something hooked up wrong with the photocell.... It seems to be giving no voltage drop at all....

I have a potentiometer as well
(Rotary Potentiometer - Linear (10k ohm) - COM-09288 - SparkFun Electronics)
so I'll try hooking that up and seeing if I get any different results.

Ok, I think I got everything working. I have two theories about why it went wrong. The first is that I didn't have everything hooked up correctly. If I plug a resistor into a breadboard parallel to the way the pins are running, maybe the electricity takes the path of least resistance and skips the resistor?

x
--|--|------- perhaps the electricity just bypasses the resistor altogether because it can just flow through the pins?

when I hooked it up like this

xxx
/
-----|-- --|----- it worked. Maybe putting the resistor over the break forced the electricity to actually flow through it?
But again, I could just not know what I'm talking about.

That's one theory I have. The other one is more primitive. Maybe I just didn't have the resistor plugged in all the way. The breadboard pins go in pretty far, it's not unlikely that I didn't have the wires jammed in far enough to make a connection.

Anyway, hope that helps someone who's experiencing similar issues, thanks for helping me get the basic electronic theory. I really appreciate it.