Make the motor spin faster or slower depending on how far away an object is.
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 add a While loop, which repeats forever.
- We declare a motor on pins 2, 3 and 4.
- We declare an ultrasonic called ultra, trigger on 5 and echo on 6.
- We create a number variable called reading.
- Inside the loop we set reading to the distance the sensor measures.
- Behind it we put the motor and give it the variable reading as its speed.
When you finish, the app takes you straight to the next tutorial in the path.