Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just started looking into electronics and circuits. I purchased the Arduino Starter Kit to help get me started. I have a question regarding one of the 15 projects it comes with. Specifically with project 4. Basically the the project introduces photoresistors, in this case 3, and the multi light LED, which I believe is a standard RGB LED.

The part I don't understand is that we have to make a calculation for the resistor readings. We have to convert the reading, which would be in a range of 0-1023 to a range of 0-255 for the analogWrite() function. The calculation is very simple, just divide the reading by 4 and you get a measurement within the 0-255 range.

I don't understand the need for the conversion. What is the need for it? Why is the sensor range 0-1023 and not some other range? All I get from the reading is that it is needed for the function and doesn't go into any more detail other than that. I'm sure it is something fundamental that I am just not seeing.

Any point in the right direction would be appreciated. Thanks!

share|improve this question
up vote 2 down vote accepted

If you look at the datasheet for the MCU at the center of the Arduino, the ATmega328, you'll see that it has 10-bit ADCs and 8-bit PWM (some can be 9- or 10-bit, but the Arduino libraries restrict them to 8).

Dividing the 10-bit ADC result (0 to 1023, 210-1) by 4 (22) scales it down to a 8-bit value (0 to 255, 28-1), which will fit in the PWM registers.

share|improve this answer
Ahh ok interesting. I looked up ATmega328 looks like I have a ton of learning to do. I don't fully ADC but it seems to make sense. Thanks – Schanckopotamus Feb 24 '14 at 0:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.