Follow a line

Hi! I’m a new programmer (who will have to teach programming to teenagers) and I’m still trying to understand some basics so I need your help!

I make my robot follow a black line with the optic sensor. It works just fine but I’m always trying to find many ways to solve the same challenge. I put you a picture of two programs that, in my mind, should do the exact same thing but in fact doesn’t. The left one works and the right one just makes the robot make circles… I tried to change the sign, the value, etc… but only the first option seems to work (I find it weird that there is only one answer).

If one of you could explain to me why the first one works and not the other (and tell me how to make the second work) I would be really greatful! Thank you in advance!

If you use the sensor in the menus and see the difference in the reported values, that may give you some clues. The device info page can be incredibly helpful for doing some of these basic checks to verify assumptions.

The only likely thing I would expect here would be that the luminosity is coming back at 80%+, and that’s why the left side/1st example works and the right side/2nd example does not.

Hope that helps!


I tried it and I understand it better now. It’s not perfect but learning is always a work in progress! Thank you!


Here’s an iq line follower in action. It checks the sensor and turns left (about 30 degrees total) if the sensor detects white. If it does not find black color after turning left, it turns right. It would be better if there were 2 sensors. Then you could tell which way to turn by seeing which sensor detected white first.