Cricket Tutorial — Light Sensor and the Send Command

Touch sensors produce a true or false reading, but light sensors produce a value that can vary between 0 and 255. To read the value from a light sensor, you use the sensora and sensorb commands.


                     Run Button ^

Let's explore light sensors. Start off by clicking on the Click for Sensor A box. Select Light Sensor.
You should see an image like this, as well as a slider that controls the light level. When you adjust the slider, it simulates the sensor receiving more or less light from the environment. When the sensor’s “sun” is bigger, it’s receiving more light; when it’s smaller, it is receiving less light.

To find out the numerical value produced by the sensor, you can use the send command. This will cause the Cricket to transmit a value back to the computer. This value is displayed in the Monitor Box.

Try it right now. Type into the Command Center, send sensora and press Return. You should see a reading in the Monitor Box.

What value does the sensor return when it is seeing the maximum amount of light (when the sensor’s “sun” is the biggest)? What value does it produce in the dark?

When you are working with light sensors, it’s very important to get an idea of what kind of readings they are producing. When testing, you can download send sensora (or “send sensorb”) in the Run This line; then, each time you press the Cricket’s Run Button, it will transmit the current light sensor value back to your computer.

BACK: Switch Sensor and If

UP to index

NEXT: Light Sensor and Waituntil