The white background clearly generates a higher value than the black line. For example, the un-calibrated value from the Light Sensor over a white background might be 52 and the un-calibrated value when over a black line might be 26. If you have not configured the light sensor for your particular "environment", then the sensor will return un-calibrated values. The white background, black lines, and ambient room lighting form the "environment" in which the robot operates. So, there will be two common values that you will be measuring, the value of the Light Sensor when on the white background and the value when on the black line. These lines are usually shown against a light background. Light Sensor CalibrationIf your program uses a Light Sensor, then you are probably using lines for navigation (either following a line, stopping on a line, or counting lines). A Non-Functioning EV3 (i.e., frozen or dead).
#Robotc light sensor how to
Next time, we will look at the light sensor more and I will show you how to follow lines. So, while the touch sensor is pressed, it will run the function “one”, and when there is an object in the robot’s way, it will run the function “two”. Now, how can we incorporate functions into this? Let’s take a look. When everything is clear, the robot will simply go forward. Also, while there is an object in the way, it will stop and play an annoying beeping sound until you move the object. This program codes the robot to, while the touch sensor is pressed, back up and turn. This is an infinite loop so the program will run forever (or until you stop it.) I use that to loop the program. What you might notice here is the “while(true)”. #pragma config(Sensor, S4, sonar, sensorSONAR) #pragma config(Sensor, S1, touch, sensorTouch) Now here is a more complex program using ultrasonic and touch sensors.
I don’t use the sound sensor very often because I think it does not have much value in programs. For the ultrasonic sensor, the value is distance, and for color, the value is the reflected light. For the touch sensor, there are only two values, 0 (not pressed) or 1 (pressed). For the first line here, you put the name of the sensor, in this case “touch” in the parenthesis, use an equality (=) or inequality (!=) sign, and a set a value. This tells the robot to go forward while the touch sensor is not pressed, the go back a little when it is pressed. In this tutorial, though, I will just be going over the while statement. These are the “While” and “If” statements. In order to program sensors, we need to learn two simple but very helpful statements. You need these lines to have the sensors work. Click OK and the text should be at the top of your code. Now we dont want to type that every time, so to automatically insert it, go to Robot>Motors and Sensors Setup, and go to the sensor tab to fill in the sensor info. What’s this, you say? It is saying that the sensor is in sensor port 1, named “touch”, and it is a touch sensor. Later models come with a color sensor that replaces light, but I prefer the light over color.
The NXT has four types sensors that come with it: the ultrasonic sensor, the light sensor, the touch sensor, and the sound sensor. Sensors are the main part of the NXT, and are the items that the NXT is most useful for.