Photoresistor is not working, is there something wrong in the code? I am trying to make the photoresistor work in a simple project. 

The project is as follows:
The LED light should light up brighter and brighter as the photoresistor reads less light in the room.

The problem:
The reading is fixed on 1023. Therefore the LED never lights up. I cannot understand why.. Sometimes if I cover the sensor the readings go down to 900- 950 but never less even though it is completely dark around the sensor. Is there something wrong in the code? What could have gone wrong?
Please note that the resistor connected to the sensor is 10k Ohm as is the one connected to the LED.

Here is the code

int photoPin = 0;
int pReading; // analog readings

int LED = 11; // red LED connected to pin 11
int LEDbrightness; //

void setup() 
{
  //set up the serial connection
  Serial.begin(9600);
}

void loop() 
{
  pReading = analogRead(photoPin);
  Serial.print("Photocell reading = ");
  Serial.println(pReading); // Analog reading

  pReading = 1023 - pReading;
  //map 0-1023 to 0-255
  LEDbrightness = map(pReading, 0, 1023, 0, 255);

  analogWrite(LED, LEDbrightness);
  delay(50);
}


Here are the connections


thank you!
The code looks OK. It looks like it's your circuit which is the problem.

The main role of a photoresistor is to restrict the amount of current flowing through it when the light level is reduced. It won't directly affect voltage the way you're expecting (the analog pins respond to voltage).

However, it's pretty easy to make it affect voltage with a slightly different circuit. Try creating a voltage divider circuit, such that the supply voltage (5V) goes through the photoresistor, then through another resistor, and then to ground. The Arduino's analog pin should be connected between the photoresistor and resistor. (See the image below, although the resistor on the output probably isn't necessary in this case.)

This should cause the voltage on the analog pin to decrease when the light level decreases. You may need to experiment a little to find a suitable resistor value on the ground connection, although 2K Ohms is probably a good starting point. It basically affects the sensitivity of the circuit.


Image credit: Morteza Lahijanian (source)