In this episode of the Basic NXT Programming series I will cover the sound sensor. I will explain how to program the sound sensor, stop on common problems faced, when the sound sensor is used and finally we will build a program that will allow us to control the robot's speed through the volume of the sound.
- 18 Aug 2013
In this tutorial we use the robot, built in Episode 13, and we have the sound sensor connected on port 2 and the motors on ports B and C
- Download the NXT-G source code of the program, built in the tutorial for controlling the speed of the robot through the level of the sound.
- Download the NXT-G source code of the program, built in the tutorial for controlling when the robot starts moving and when stops.
In this episode of the basic NTX programing series. We will go through the features of the Sound sensor in the Mindstorms NXT set. Although it is prohibited during the competition and could be hardly used there because of the noise. It could have some interesting applications. During the tutorial I will stop on some key problems using the sensor. And make a program where the speed of the robot is controlled by the volume level. GO FASTER.
So let's begin with going through the blocks where the Sound sensor is used. As all other sensor there is a Yellow sensor block and an Orange sensor block. The orange one is used for waiting until given event occurs. So for instance the sound is over fifty. And the yellow one is used for reading the value of the sensor. The Sound sensor can be used as a condition for the Loop block. This is by going to Sensors-Sound sensor. Or as a condition for the Switch block.
In all four block the settings are almost the same. First we need to chose the port on which the Sound sensor is connected. And then we need to chose the threshold value with which we compared the value detected by the sensor. And whether we want it to be greater than our threshold value or less than this value.
Okey, so now we know the basic settings of the Sound sensor. Now let's see how we should attach it. Due to the sensitiveness of the Sound sensor a common problem is how to attach it the to robot. There are two important aspects: The first on is that the sensor should be at least 15 centimeters away from the motors. Because otherwise it will hear the noise produced by the work of the motors. Next it should be solidly attached because it can hear the vibrations during the movement of the robot. So in our case I will use an 11 bar. I will attach it here. And then I will attach the Sound sensor to it. So it's like this. And finally I will connect it with a cable to port number 2. So now I have our Sound sensor attached. Another thing that we can do in order to improve the accuracy of the Sound sensor is to calibrate it. This can be done the same way as the calibration of the Light sensor which is shown in episodes 11 and 14. Now we know the basic settings of the Sound sensor blocks. And also how we should attach the sensor to the robot. Now let's put our knowledge in use. I'll make a program for making my robot to start moving when I clap. And then stop when I clap again. So assuming that the Sound sensor is connected on port 2 and the motor are connected on port B and port C. The program should look like this: I will wait until the Sound is over fifty well let's say over eighty if we are in a louder room. Then we should start the motors moving forward and that should be unlimited. Because then we will wait until the Sound sensor detects another clapping which is again over eighty. And finally the robot should stop after the second clap. Okay so let's test our program.
As we saw the program does not work properly . But where is the problem? Well it is almost the same as the problem we faced in the previous tutorial with the Touch sensor. The microcontroller inside the brick detects the same Sound wave twice. This is a common problem that you can face while you are using the Sound sensor.
You must be sure that there is a silence for at least one second between two decetions of the Sound sensor. In order to be sure that your program will work. So in our case I will add another wait block but this time I won't wait something to accur on the sensors. But I will wait for one second. So now our program looks like this: The robot will wait for my clap. Then it will start moving forward for one second. And then it will continue moving forward waiting for my second clap. And when it hears it, it will stop. So now let's download and try our program.
Finally our program is ready and working properly, now let's focus on another program. I would like to make a program where I can control the speed of the robot with the volume level. For this purpose I will delete all these blocks. And take an yellow Sound sensor block. As I said with it we can read the value of the sensor. So I will connect the Sound level with the power of a move block. So now the value detected by the Sound sensor will be the power with which the motors will move forward. I will set the move block to unlimited, and put the two blocks in a loop that will repeat itself for forever. And our program is ready. If you would like you can use some Math blocks to change or modify the value of the Sound sensor. In order to make your program more interesting. But for now I will leave it like this. So let's download and try it.