Read a digital sensor and stop the motor when the car leaves the line.
This tutorial is part of the Nairda learning path. You can build it step by step inside the app, which checks every block you place before letting you move on.
The steps
- We create a digital input called eye on pin 4.
- We create a motor called wheel on pins 2, 3 and 5.
- We create a number variable called line.
- We add a While loop, which repeats forever.
- Inside the loop we set line to what the sensor sees.
- Behind it we set the motor to speed 100.
- Behind that an If with a comparison.
- The If asks whether line is 1, meaning the car went off.
- If it went off, inside the If we stop the motor.
When you finish, the app takes you straight to the next tutorial in the path.