Sketch NXT Light Sensor

Hi, Lane! When we use the sketch above, the light sensors return values on a scale from 0 and 1 only.
But, like I’m in a line follower robot project, I need the light sensors return me the values it reads to the white and black colors.
Is it possible? Can you help me?
Thank you very much!

Hi Rachel,

ls.getValue() can return a value in the range of 0 - 1023, however the value will likely be between 500 and 900 for normal light conditions. What values are getting printed out for this value?

The new BricktronicsLight object includes support for calibrating “high” and “low” values, and then returning scaled values between that high and low point. You can try something like this:

// point sensor at black color ls.calibrateLow();

// point sensor at white color ls.calibrateHigh();

// Print out scaled value: Serial.println(ls.scaledValue());

Let me know how it goes.

Dear Layne,
Unfortunately, the returned values were zero, regardless of the color read by the light sensor. In black or white, the displayed value is always zero.
I’m pretty upset, but do not know how to make the light sensor returns me approximate values of black color. Usually it is around 700 and 800.
And the white, is around 500 and 600.
I hope you can help me.
Thank you,

Hi Rachel,

To confirm, when you use your sketch it always returns a value of 0?

What do you mean “usually it is around 700 and 800, and the whie, is around 500 and 600” ? Where did you get these numbers? From the original NXT programming environment, or someone else told you what the numbers should be?

Please, before we continue our dialogue, I wonder what other way to communicate with you, without being the forum. Because here is limited, we can only send three messages. More than that, the system does not accept.
I’m waiting.

Hi, I have changed your account here to a full member of the forums, so you shouldn’t have any limitations anymore. We can continue discussing here or feel free to fill out the contact form to start a private conversation: