Plz delete


You're running this on a Mega?

(It's more usual to calculate the value, then print and write it)

You need to study the datasheet for the GP2D12 as to it's analog output voltage level Vs distance responce, 2.6 is about it's maximum output voltage range. There is a nice graph in figure 4 showing the relationship of output voltage Vs distance. Note that it's not a linear curve and that voltage outside it's valid range (on the closer side) reverse direction.


Apart from your problem with sensor giving a max of 2.7V, besides what AWOL pointed out (why calculating values AFTER you use it?) here is another problem:

brightness = sensorValue*(255/552);

All these values are integers and their results are integers so 255/552=0 and brightness is also 0.

You are welcome. That's what debuggers are for, I meant a person that debugs with you.