Purple Sky Profile Header
If you have seen any of the "Star Wars" movies, then you probably remember when Jedi knights like Luke Skywalker and Obi-Wan Kenobi used "The Force" to push, pull, and even throw objects — including some helpless battle droids. Have you ever wished you could do that in real life? In this robotics project, you will build and program a LEGO® robot that you can push and pull using an "invisible force" — almost like a real Jedi! We make no promise that you will be taking down the Death Star anytime soon, but this could be a good start.
AREAS OF SCIENCE
Build a LEGO® Mindstorms® robot that you can push and pull by programming it to maintain a preset distance from your hand.

If you saw any of the "Star Wars" movies, you probably remember Jedi knights like Luke Skywalker or villains like Darth Vader using "The Force" to lift, crush, and throw objects. Have you ever wished you could use an invisible force to move objects around in the real world? In this project, you will! Well, not just any object. First, you will have to build and program a robot that will respond to an "invisible force" from your hand. The invisible force will let you push and pull the robot back and forth without actually touching it! Watch this video of the demonstration robot we built at Science Buddies.

This project relies on a few key parts in the LEGO Mindstorms kit. First, you will need to use motors with wheels to build a robot that can move forward and backward. You will also need to use the NXT's ultrasonic sensor. An ultrasonic sensor measures the distance to an object by bouncing sound waves off it. First, the sensor emits a sound wave that travels forward at the speed of sound, away from the sensor. When that sound wave hits an object, part of it bounces back and eventually returns to the sensor. The farther away an object is, the longer it takes sound to bounce back and return. So, by measuring the amount of elapsed time from when the sound is emitted to when it returns, the sensor can determine how far away an object is, as Figure 1 illustrates.

lego-nxt-ultrasonic-sensor-distance_img

Figure 1. The farther away an object is from the ultrasonic sensor, the longer sound has to travel to reach the object and then bounce back — which takes more time. This is how the ultrasonic sensor uses sound to measure distance.

Just building a robot with motors and an ultrasonic sensor won't be enough, however. You need to write a computer program to tell the robot what to do. The program you will write for your NXT robot in this project is based on this equation (this equation is called a proportional controller - see the Technical Note at the end of this section for more information):

Equation 1.
𝑀𝑜𝑡𝑜𝑟𝑃𝑜𝑤𝑒𝑟=𝐶𝑜𝑛𝑠𝑡𝑎𝑛𝑡×(𝑀𝑒𝑎𝑠𝑢𝑟𝑒𝑑𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒𝐷𝑒𝑠𝑖𝑟𝑒𝑑𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒)
  • Motor power in the NXT software is a number between 0 and 100 that tells the motor how fast to spin. At 0 the motor will not move at all, and 100 means it is moving as fast as possible.
  • Constant is a number you pick — it can be anything! The value of the constant will determine how fast your robot reacts when you move your hand.
  • Measured distance is the distance to your hand, measured by the ultrasonic sensor.
  • Desired distance is how far you want the robot to be from your hand.

To help you understand this equation, let's use some examples. Say you pick a value for constant = 2 and desired distance = 30 centimeters (cm). So, your equation is:

Equation 2.
𝑀𝑜𝑡𝑜𝑟𝑃𝑜𝑤𝑒𝑟=2×(𝑀𝑒𝑎𝑠𝑢𝑟𝑒𝑑𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒30)

Now, think about what happens in three cases:

  1. Your hand is less than 30 cm from the robot.
  2. Your hand is exactly 30 cm from the robot.
  3. Your hand is more than 30 cm from the robot.

We'll use the first case as an example. Let's pretend your hand is 10 cm from the robot. So, you plug 10 cm into Equation 2 for the measured distance:

Equation 3.
𝑀𝑜𝑡𝑜𝑟𝑃𝑜𝑤𝑒𝑟=2𝑥(1030)=40

The answer is negative 40 — and a negative number means the robot will move backward, away from your hand. The robot "knows" that it is too close — it should be exactly 30 cm away. Can you use Equation 2 to figure out what will happen if your hand is exactly 30 cm from the robot, or more than 30 cm from the robot? Figure 2 shows what will happen — but make sure you can explain it using Equation 2!

lego-nxt-robot-proportional-controller-distance_img

Figure 2. This shows how the robot will behave if the desired distance in Equation 2 is set to 30 cm. If your hand is too close to the robot, it will back up, and if it is too far, the robot will move forward. If your hand is exactly 30 cm from the robot, the motor power will be 0, so it will stop.

Do you understand how the program will work? If not, go back and watch the video again — does it make more sense this time? Once you think you understand how you will be able to push and pull the robot, you are ready to move on to the Procedure section and start building.

Technical Note

Note: Understanding the information in this box is not required to complete the rest of the project — we include it just in case you are curious!

Equation 1 is called a proportional controller, because the control input is proportional to the error. In Equation 1, the control input is the motor power, and the error is the difference between the measured difference and the desired distance. The desired distance can also be referred to as the set point. The constant that multiplies by the error is called the proportional gain. So, you can write a more general equation:

Equation 4.
𝑢=𝐾𝑝𝑒
  • u is the control input
  • Kp is the proportional gain
  • e is the error

This type of equation is used all the time in robotics and engineering. For example, you could also use it to control the angle of one of the motors in your NXT kit — this time the error would be based on your desired angle, and the measured angle from the NXT motor's built-in angle sensor. A more advanced version of the equation can even be used for things like cruise control in a car, or autopilot in an airplane! We don't have room to explain it all here — but if you are curious, you can do an Internet search for "PID control" or "proportional integral derivative control."

  • Motor
  • Ultrasonic sensor
  • Speed of sound
  • Elapsed time
  • Computer program
  • Motor power
  • Constant
  • Measured distance
  • Desired distance
  • Proportional controller (advanced terms — not necessary to do the project)
  • Control input
  • Error
  • Set point
  • Proportional gain
  • Binary


  • How do ultrasonic sensors work? Can you find examples in nature of animals that use sound to locate things? (Hint: search online for the word "echolocation.")
  • How does Equation 1 work to control the robot's movement? Can you explain each case in Figure 2?
  • How do you think changing the values of the desired distance or the constant in Equation 1 would affect how the robot moves?
  • Can you research other examples in real life where an equation or computer program is used to control something? It doesn't always have to be about robotics - for example, the thermostat in your house controls temperature, so it doesn't get too hot or too cold.