1

I am experimenting with the light sensor shipped within the mindstorms ev3 package.

My Problem is that the bot is standing quiet at one place. Each value returned by sensor is different, although the bot is not moving. Why? :-(

I am using the Red mode:

SensorMode t = sensor.getRedMode();

float[] sample = new float[1]; 
t.fetchSample(sample,0);
return sample [0];

I tried putting the sensor in different positions and tried different distances to the floor. When it is on a black line the values differ a lot.

Which sensor modes do you guys use for getting reliable information about underground colour? Or let's say underground brightness?

2 Answers 2

2

Light sensors are mainly affected by three independent variables:

  • Distance between the sensor and the surface
  • Color of the surface
  • Amount of ambient light

What this means is, in order to measure one of these things, the other two variables must be held constant. So, in order to measure color, the distance must be constant and the ambient light should be constant.

You can maintain a constant distance between the sensor and the floor by attaching the sensor, pointing downward, to a fixed point on the robot. Simple enough. In my experience the sensor should be about 1cm from the floor for best results.

You can maintain a constant ambient light by avoiding shadows or bright lights. If this isn't possible, you can build a shroud over the sensor to block out external light. You should also recalibrate the sensor at program startup to account for ambient light.

After doing the previous two things, you can measure the reflected light from the surface by shining one of the colored LEDs and taking a sample. Using only 1 LED should be sufficient to detect differences in grayscale, but to actually measure "color" you can quickly cycle between the Red, Green, and Blue LEDs, taking samples with each, to get a crude estimate of the RGB components of the surface.

3
  • Thanks for your reply. The three variables are stable. I set up the sensor around 1 cm far away from the ground. Robot is not moving. No Shadow is changing the ambient. When i take 10 measurements, results jump between 0.1 to 0.6...:-( I was thinking about trying a light sensor instead of the color sensor. But as far as i understood, the reflected light mesaruement is quite the same. Mar 8, 2019 at 14:55
  • What are the expected values here? Are they supposed to be between 0 and 1? I'm not quite familiar with using LeJOS for this purpose, but it sounds like there's some option that needs to be set for this to work properly. I found this tutorial regarding color sensor usage with LeJOS EV3. Hopefully there's something useful in there.
    – MindS1
    Mar 8, 2019 at 19:35
  • 1
    Yes...in reflection mode it is supposesd to be between 0 and 1, which samples the reflection in percent. I found out that shadows are really a big problem for making the sensor reliable. I will think about putting protection around do keep the sensor from outside light. I will also think about calibrationg the sensor, meaning: Measure current white and black value and use theese values as reference. Will see how far i come with that. :-) Mar 9, 2019 at 2:04
0

I solved my problem:

I was experimenting with the sensor and its modes and I came up with following solution:

I am using the RGB mode and read the three samples. The samples are much too accurate, so I round them at the second place after decimal delimiter and use the red value only.

In this way I can place my robot on the paper and each time I get the same value for white or black (light or dark).

I also assembled a kind of light protection around my sensor, but this allone did not result in same values on white places.

I was now able to implement a line follower which works with intervals for light, neutral and dark zone, each one in a seperate behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.