Take the 2-minute tour ×
LEGO® Answers is a question and answer site for LEGO® and building block enthusiasts. It's 100% free, no registration required.

I use Lego Mindstorms NXT 2.0. I want to schedule my robot to move to where there is light αnd then when it finds it (a large amount of light, for example 80%) to stop and move another motor for 30 degrees. Then stay still for 10 seconds and after that to search for another light.

Can you help me please?

I use

port B: right motor

port C: left motor

port A: the degrees motor

port 3: a light sensor

share|improve this question
    
Is the light sensor pointed forward?, down?, on a turntable? –  dfrevert Apr 22 at 21:30
    
forward.for example I want ιτ to follow a lens –  vadim Apr 22 at 21:47
    
Depending on the design of your robot, you may not need the third motor. Just move the left and right motor in opposite directions. –  S.L. Barth Apr 23 at 12:09
    
no..the third motor I want it for other use.how to move the motors in the light beam with one sensor?it is not difficult to make my robot to turn.it is difficult to turn into the light. –  vadim Apr 23 at 12:16
add comment

2 Answers 2

In pseudocode:

LoopBlock (forever)
    MoveBlock (B and C motors, 75% power, forward, forever)
    -- unclear here, probably want to head for brighter light
    -- instead, just wait for 80%
    If LightSensorBlock (port 3, greater than, threshold 80%) Then
         MoveBlock (B and C motors, stop)
         WaitForBlock (time, 10 seconds)
    End If
End Loop
share|improve this answer
    
I want my robot to follow the light.To track where there is light. when the brightness is more than 80% to stop and to move a third motor 30 degrees. –  vadim Apr 22 at 21:46
    
i thing that its beter to use two light sensor to rotate my motors. –  vadim Apr 22 at 22:33
    
"two light sensors to rotate my motors"? I'd suggest using just one light sensor and getting that to work before jumping to two. –  dfrevert Apr 23 at 0:53
    
One light sensor pointed forward suggests that the robot should at regular intervals, stop turn right, turn left, and compare those light sensor values and compare to make sure the robot is still headed in the right direction. Start with just that. Spinning in a circle and finding the brightest value would be a next step. –  dfrevert Apr 23 at 0:56
1  
if i use two sensors and compare the values of the light beam i thing its more easy.if you think something let me know. –  vadim Apr 23 at 1:29
show 1 more comment
#pragma config(Sensor, S3,     lightSensor,         sensorLightActive)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//


task main()
{
   wait1Msec(50);                        // The program waits 50 milliseconds to initialize the light sensor.

   while(true)                           // Infinite loop
   {
      if(SensorValue(lightSensor) < 45)  // If the Light Sensor reads a value less than 45:
      {
        motor[motorB] = 0;                  // Motor B is run at a 0 power level.
        motor[motorC] = 30;                  // Motor C is run at a 30 power level.
      }
      else                               // If the Light Sensor reads a value greater than or equal to 45:
      {
        motor[motorB] = 50;                  // Motor B is run at a 50 power level.
        motor[motorC] = 50;                  // Motor C is run at a 50 power level.
        while (SensorValue(lightSensor) >80) // If the Light Sensor reads a value MORE than 80:

{

  motor[motorC] = 0;  

  motor[motorB] = 0;
  motor[motorA] = 10;

}

      }
   }
}

Finally I got it done!!!!

share|improve this answer
1  
This always turns right if there's not enough light. I'd suggest that when you lose the light source your robot should: 1 turn left a bit, 2 store the current light value, 3 turn right twice of the amount in step1, 4 check if the current light value is higher or lower than the stored one. If higher than the light is probably to the right side, so it can just go forward. But if the stored value is higher, you need to turn back to the left the same amount as in step3 and keep going that way. –  zovits May 2 at 12:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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