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!
Image credit: Morteza Lahijanian (