330 likes | 1.16k Views
THE LIGHT SENSOR. The Light Sensor gives your robot some kind of vision. It can distinguish between light and dark assigning a number between 0 (completely dark) and 100 (maximum light).
E N D
THE LIGHT SENSOR The Light Sensor gives your robot some kind of vision. It can distinguish between light and dark assigning a number between 0 (completely dark) and 100 (maximum light). It can also detect the light intensity of colored surfaces thanks to its Light Emitting Diode, so that it is possible to recognize colors.
SENSOR HARDWARE SCHEMATIC The circuit is not so simple, but it is easy to recognize the LED and the light sensor. On the right the input port connection is drawn. The NXT Light Sensor has a range of states between 0 and 100. The lower the number, the darker the reading is.
Connecting the light sensor to the NXT The input port and the cable have six connections. The connection can be used to get digital, analog and I2C signals and to supply power to the connected sensor.
What can you do with a light sensor? You can use the Light Sensor detect the light in a room. The Light Sensor can be use to follow a black line on a white floor. You can write a program that makes your robot move on a table without fall down.
Programming the Light Sensor with NXC NXC, is a high-level programming language for NXT. NXC has a syntax similar to C language. Before using a sensor you have to declare its connecting input: SetSensorLight( port numberS1 to S4 ); To read a value and store it in a variable: x = Sensor(port number);
EXAMPLE PROGRAM task main() { SetSensorLight(S1); int x; while(true) { ClearScreen(); x=Sensor(S1); NumOut(10,LCD_LINE1,x); Wait(200); } }