In this episode I will show you how to program the touch sensor part of the LEGO Mindstorms education robotics sets. I have given answers to questions like - how the touch sensor works or how you can use it.
- 11 Aug 2013
Basic NXT Tutorials
The next episode in this series is Episode 36, where I'm explaining how to program and use the sound sensor.
In this episode of the basic tutorial series I will go through the Touch sensor. By the end of this tutorial you will know how does the Touch sensor works. How to program it, how to attach it to the robot and last but not least how you can use it.
So let's begin with looking at the programming possibilities of the Touch sensor. First I have the yellow block then I have the orange block. And of course we can you the Touch sensor as condition of the loop. And of the switch block. In all four cases I have the same settings. First we have to chose on which port the sensor is connected. And then we have to chose from the three actions. Pressed, Released and Bumped. Now let's take a look at a program which will help us to understand the differences between the three states of the Touch sensor. So let's go to the view menu. There we chose the Touch sensor and I have connected my Touch sensor on port 1 so I chose port 1. As you can see the screen is shown 0. If I pres the touch sensor it will become 1. So the touch sensor has only two states Pressed and Released or 1 and 0. But in the setting we have three states Pressed, Released and Bumped. So how do we get three states? If we take a look at the orange block of the Touch sensor.
What happens actually is that if we take the Pressed option the robot will wait until the touch sensor is Pressed. If we take the Released option the robot will wait until the Touch sensor is Released. Which means that at the beginning the Touch sensor must be Pressed. And if we go to the Bumped option. We have the robot waiting for the Touch sensor. to be Pressed and afterwards Released. So actually if in the beginning I have the Touch sensor Pressed then the robot will wait to be Released. Then Pressed and Released again. We got familiar with the basic settings of the Touch sensor. Now let's see how does the touch sensor work. Let's say I have a battery . Тhis was an ugly one. So I have a battery. And we take a paper clip which will connect the + and the - sides of the battery. What will happen with the paper clip? Well it will get hotter, that is because electricity will flow through the paper clip. But now let's break the paperclip in two pieces.
Here for instance. Now electricity won't flow anymore through the paper clip and the paper clip will get cooler. But if we have another paper clip and connect the two pieces with it.
The paper clip will get hotter again. So we can make a switch that can connect and disconnect the two pieces. On similar basis works the Touch sensor. There is a plate connected to the orange button which when the button is pressed closes the circuit and electricity flows. In that way the brick understands that the touch sensor is Pressed. If we Release the orange button of the Touch sensor a spring pushes back the sensor and the plate disconnects the circuit and electricity does not flow anymore. So basically this is the principle on which works the Touch sensor. Now let's see several programs to see how we can use the Touch sensor. So let's begin with the simplest program possible. I will make my robot stop when it hits a wall. First I take a move block which will move unlimited until the Touch sensor is Pressed. I cannot chose Released or Bumped because the sensor of the robot will be Released from the beginning. And with Bumped the problem is that the robot waits for the Touch sensor to be Pressed and then Released. And when the robot hits the wall the Touch sensor will be only Pressed. So after the Touch sensor is Pressed I take another Move block and make my robot to stop. So let's download and see how it works. So I use the five minute bot which can be found in episode 0. And I have attache a Touch sensor to it. The Touch sensor is on port 1 and the motors are on port B and C. So let's run the program. And imagine that my hand is a wall. And I start the program. And the robot stops. Now let's take our program one step further. I want the robot to start when the Touch sensor is Pressed and afterwards stop when the Touch sensor is Pressed. So the only difference I should make is to put a Touch sensor in the beginning. With the same option and download our program. So let's run the program. I started and the robot isn't moving I Press the Touch sensor. And unfortunately the robot does not start, but the program finished. What actually happened is that my touch of the Touch sensor has been detected twice. Because the microcontroller inside the Brick is way faster than my hand. How I can fix this? Well it is simply by choosing Bumped option on the first Touch sensor. Now the robot will wait until I Release my hand. And afterwards it will start moving until the Touch sensor is pressed. Let's see how does the program work this time. So now the program should work. I started it and the robot is waiting the Touch sensor to be Bumped. If I Press the Touch sensor the robot won't start moving until it is Released. So when I Release it, it will start and then stop when the Touch sensor is Pressed. This was the tutorial about the Touch sensor . In the next tutorial from the series I will show you more about the Sound sensor. Meanwhile you can check other videos at fllcasts.com