Sound Controls Steering

Control the robot rover by making sound. This obviously needs the sound sensor, only available as an extra. The sensor is assumed to be plugged into sensor port 2.

The official Lego software includes instructions for a 'Sound Controls Speed' project - the more noise you make the faster to robot moves. But it can only go in a straight line so it' s not much fun. Surely it would be better to use the sound to control the steering - that way you could make noise to guide the robot through an obstacle course, for example - an innovative challenge! It's very simple to code, though slightly more complex than controlling the power (speed). The problem is that you want to be able to steer left and right or go straight - you can't use silence to go straight otherwise how would you use sound to choose left or right? The best option is to use silence to turn hard left and then the more noise you make the more the robot turns right. Recall that the 'move steering' block (with the green header below) has a direction parameter which can vary between -100 (turn hard left) and +100 (turn hard right). Now think about the formula in the math block below:

If the sound level is very quiet then the number sent from the sound block to the 'a' input of the math block will be very small. Let's assume the value of 'a' is actually zero (silence) then the formula '2*a-100' will evaluate to -100 and the robot will turn hard left. If the sound is very loud then 'a' will equal 100 (the maximum sound level) and the formula will evaluate to +100, so the robot will turn hard right. If the sound level is 50 (medium loudness) then the formula evaluates to 0 and the robot moves straight ahead. Simple! The 'move steering' block also has a power (speed) value which is set to 30 so the robot moves rather slowly, giving you better control over its motion. The program includes a loop that repeats forever so the robot will keep moving until you stop it by pressing the 'Back' button on the brick.

Click the 'download' button below to download the project file.

Note that if you do not have a sound sensor you could use an upward-pointing ultrasound sensor instead, holding your hand or a book above the sensor and varying the height of the object to control the direction of the rover. You'd have to modify the program, of course.

What do you mean, you don't have an ultrasound sensor either?! Then you could use the light sensor, perhaps facing upwards. Shine a torch at the sensor to control the steering. Or maybe you could use the infrared sensor, but since I have the education version I don't own an infrared sensor and am not familiar with it...