Answers.Body: <p>Light sensors are mainly affected by three independent variables:  </p>
  
  <ul>
  <li>Distance between the sensor and the surface  </li>
  <li>Color of the surface  </li>
  <li>Amount of ambient light  </li>
  </ul>
  
  <p>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.  </p>
  
  <p>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.  </p>
  
  <p>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.  </p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-08T14:55:18.797Z
Answers.Text: 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.
Answers.UserDisplayName: weiterleiter
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-08T19:35:49.500Z
Answers.Text: 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](https://stemrobotics.cs.pdx.edu/node/5200) regarding color sensor usage with LeJOS EV3. Hopefully there's something useful in there.
Answers.UserDisplayName: MindS1
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-09T02:04:01.267Z
Answers.Text: 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. :-)
Answers.UserDisplayName: weiterleiter
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-08T06:28:48.270Z
Answers.LastActivityDate: 2019-03-08T06:33:53.090Z
Answers.LastEditDate: 2019-03-08T06:33:53.090Z
Answers.UserDisplayName: MindS1
Answers.Body: <p>I solved my problem:</p>
  
  <p>I was experimenting with the sensor and its modes and I came up with following solution:</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>I also assembled a kind of light protection around my sensor, but this allone did not result in same values on white places. </p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-09T18:10:01.900Z
Answers.LastActivityDate: 2019-03-09T18:10:01.900Z
Answers.UserDisplayName: weiterleiter
Body: <p>I am experimenting with the light sensor shipped within the mindstorms ev3 package.</p>
  
  <p>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? :-(</p>
  
  <p>I am using the Red mode:</p>
  
  <pre><code>SensorMode t = sensor.getRedMode();
  
  float[] sample = new float[1]; 
  t.fetchSample(sample,0);
  return sample [0];
  </code></pre>
  
  <p>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. </p>
  
  <p>Which sensor modes do you guys use for getting reliable information about underground colour? Or let's say underground brightness? </p>
  
Tags: <ev3><mindstorms><sensor-colour>
Title: Color sensor reliable?
UserDisplayName: weiterleiter
ThreadText: # Color sensor reliable?
  
  (Asked by: username_0 on 2019-03-07)
  
  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?
  
  **Tags:** ev3, mindstorms, sensor-colour
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-03-08. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_1**: 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](https://stemrobotics.cs.pdx.edu/node/5200) regarding color sensor usage with LeJOS EV3. Hopefully there's something useful in there.  
  > **username_0**: 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. :-)  
  
  ---
  
  ### Answer by username_0 on 2019-03-09. Score: 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.
  
  
  ---
  
  