The sensorValue range is 0 to 1023 theoretically. Practically it goes between about 0 and 700 for daylight and the chosen component values.

ledLevel will be 0 to 6 for example (if NbrLEDs = 6), over that same input range.

All you have to do then is use a for loop to turn ON the LEDs based on the ledLevel.

Step 4: Here’s the code

/*
Bargraph sketch example
Recipe 7.5 from the Arduino Cookbook by Michael MargolisTurns on a series of LEDs proportional to a value of an analog sensor.
Six LEDs are controlled but you can change the number of LEDs by changing
the value of NbrLEDs and adding the pins to the ledPins array
*/