Jump to main content

Use the Force! Push & Pull Robots With an Invisible Force

1
2
3
4
5
172 reviews

Abstract

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.

Summary

Areas of Science
Difficulty
 
Time Required
Average (6-10 days)
Prerequisites
You should know how to build a basic car with a LEGO Mindstorms kit, and also be familiar with basic programming in the Mindstorms software (NXT-G or EV3).
Material Availability
This project requires a LEGO Mindstorms EV3 or NXT kit, and a computer with the appropriate programming software. See the Materials and Equipment list for details.
Cost
Very High (over $150)
Safety
No issues.
Credits

Ben Finio, Ph.D., Science Buddies

Science Buddies would like to thank the Tufts University Center for Engineering Education and Outreach for providing the LEGO Mindstorms kit and NXT-G software used to develop this project.

  • LEGO® and Mindstorms® are trademarks of the LEGO Group.

Objective

Build a LEGO® Mindstorms® robot that you can push and pull by programming it to maintain a preset distance from your hand.

Introduction

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 introductory video shows the "invisible force" robot we built at Science Buddies and how it behaves using the ultrasonic sensor and a simple program.

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.

Diagram of an ultrasonic sensor using sound to measure the distance of objects at different lengths
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.

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.

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.

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!

An ultrasonic robot is programmed to move forward or backward so that it stops at a specific distance from an object
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."

Terms and Concepts

Questions

Bibliography

Here are some useful introductions to programming LEGO's official NXT software. Remember that you can also consult the NXT User Guide CD that comes with your NXT kit.

  • Valk, Laurens. The LEGO MINDSTORMS NXT 2.0 Discovery Book: A Beginner's Guide to Building and Programming Robots. San Francisco: No Starch Press, 2010.
  • Griffin, Terry. The Art of LEGO MINDSTORMS NXT-G Programming. San Francisco: No Starch Press, 2010.

You will need to build a basic robot car for this project. You can certainly design your own car, but if you want help, look at the directions that come with your NXT kit, or search online for designs like LEGO's "TriBot" design.

Materials and Equipment

LEGO Mindstorms Availability

Note: The LEGO Mindstorms product line was discontinued at the end of 2022. However, many Mindstorms kits are still in circulation and you can probably borrow one or purchase a used one. The instructions for this project were written for the LEGO Mindstorms NXT 2.0 kit. You can do this project with an EV3 kit, but the programming software is different. Follow LEGO's online resources to learn how to program your EV3 robot.

Experimental Procedure

Build Your Robot

First, you will need to build a basic robot. It should be able to move forward and backward, and have a forward-facing ultrasonic sensor. Feel free to come up with your own design, or use directions from your Mindstorms kit. Directions for the TriBot design are also available online (see Bibliography in the previous section). Figure 3 shows the robot we built at Science Buddies.

Photo of a functional ultrasonic sensing robot built from legos
Figure 3. Science Buddies' simple robot design uses two motors and a forward-facing ultrasonic sensor.

Write Your Program

You have three options to create the program for this project:

  1. If you are an experienced NXT programmer, write your own program based on the information in the introduction (see technical note).
  2. Figure 4 shows a screenshot of the program we used. If you are comfortable with basic programming in NXT-G, you can create your own program and use Figure 4 for guidance (see technical note).
  3. If you are new to NXT programming and need some help getting started, download the program we used: "Use the Force Program (UseTheForce.rbt)".
A screenshot of the LEGO Mindstorms NXT proportional controller program

The LEGO Mindstorms NXT proportional controller program uses blocks to program a robot to maintain a specific distance from certain objects. The program begins with a block representing a sonar sensors input that is run through 6 blocks of math equations and constants before connecting to two motor blocks that adjust the robots position.


Figure 4. This screenshot shows the program we used for the video in the Introduction. Our default values for the "Desired" and "Constant" blocks were 30 cm and -5, respectively.

Note that, even if you download our program, you might need to change a few things, depending on how you built your robot. Make sure that:

  • You have the correct ports assigned to your ultrasonic sensor and motors. The default values in our program are Port 1 for the ultrasonic sensor and Ports A and C for the motors. You can change the ports by clicking on each block and then selecting the appropriate radio button (1, 2, 3, or 4 for sensors, and A, B, and C for motors) at the bottom of the screen.
  • You have the correct sign (positive or negative) for the block labeled "Constant". This will depend on the orientation of the motors on your robot. The default value in our program is -5 (negative 5). If your motors are positioned like the ones in Figure 3, then this value should remain negative. If your motors are flipped upside down relative to the ones in Figure 3, then you should make this number positive. You can change this value by clicking on the "Constant" block and then entering a new value at the bottom of the screen.
Technical Note

If you are writing your own program from scratch or using ours as an example, you might be wondering what the "Compare" block is in Figure 4 (the third block from the right). This block is necessary because the "Motor" blocks only accept a number between 0 and 100 as an input for motor power, not -100 and +100. If you send a negative number to the motor power input, the program will automatically take its absolute value (for example, -50 becomes +50). This is a problem because the motor power calculated by Equation 1 from the Introduction can be either a positive or negative number. Remember:

So, to make the robot go in reverse, you have to change the "direction" input as well. The program works by first calculating the motor power using Equation 1 from the Introduction. Then, it determines if the motor power is positive or negative by comparing it to zero, using the "less than" operation in the "Compare" block. The "Compare" block outputs a binary value (true or false) - true if the motor power is less than zero, and false if the motor power is greater than zero. This binary value is then used as an input to the "Motor" block's direction, which accepts true for forward and false for reverse.

This way of doing things might seem a bit strange — but you need to make sure your robot can go forward and backward!

Download and Test Your Program

First, let's do a simple test to make sure your program is working.

  1. Aim the robot directly at a wall from about a meter away, and start the program. The robot should advance toward the wall and come to a stop.
    1. How quickly did the robot stop? Did it come to a stop smoothly, or jerk back and forth?
    2. Use your tape measure to measure the distance from the front of the ultrasonic sensor where the robot stopped to the wall. How does this distance compare to the desired distance you have set in your program? Note: if your tape measure only has marks for inches and you used centimeters in your program, you will need to convert inches to centimeters.

    If your robot goes the wrong way (backs away from the wall instead of going toward it), then reverse the sign (positive or negative) of the "Constant" block in your program, and try again.

    Now, try using your hand to "push" the robot back and forth.

  2. Put your hand in front of the ultrasonic sensor.
    1. If you pull your hand away from the robot (still being sure to keep it in front of the ultrasonic sensor), does the robot move forward? Do you have to move your hand very slowly, or can the robot keep up if you move your hand quickly?
    2. If you stop your hand, does the robot also come to a stop? Is the motion jerky or smooth?
    3. If you push your hand toward the robot, does the robot back away? Does it stop if you stop moving your hand?

Change the Values in Your Program

Now, find out what happens if you change the values for the "Desired Distance" and "Constant" blocks in your program. It will probably be easier if you change only one number at a time, and use a table to keep track of your results.

Important: as you pick new values for the "Desired Distance" and "Constant" blocks, keep in mind what is physically realistic for the ultrasonic sensor and motors. According to LEGO, the ultrasonic sensor has a range of 0-255 cm — so it doesn't make sense to enter a negative number, or a number greater than 255 cm (note: in practice, we have found the sensor's effective range to be less than that). Remember that the motor power accepts a number from 0 to 100 - so, it probably doesn't make sense to enter a very small number (like .00000001) or a very large number (like a million) for the "Constant." That would result in your robot either not moving at all, or always moving at full speed.

Table 1 shows just one example of how you could keep track of your data. For each trial, record the value for the desired distance and constant in your program. Then, you can also record things like:

  • The actual distance the robot stops from the wall.
  • The robot's speed as it approaches the wall or follows your hand. You could rate this qualitatively (on a scale like "slow/medium/fast") or use a stopwatch to time how long it takes the robot to come to a complete stop after starting a certain distance from the wall.
  • The quality of the robot's stopping — for example, "smooth/medium/jerky."

If you can think of other ways to rate your robot's performance, feel free to add more columns to your table. What combination of settings gives you the "best" results (movement that is fast, but smooth and not jerky)?

Trial Desired DistanceConstant Actual Distance Speed Stopping
1 30 -1   
2 30 -5    
3 30 -10   
4 20 -1   
5 20 -5   
6 20 -10   
Table 1. A suggested format for keeping track of your data as you change the values.
icon scientific method

Ask an Expert

Do you have specific questions about your science project? Our team of volunteer scientists can help. Our Experts won't do the work for you, but they will make suggestions, offer guidance, and help you troubleshoot.

Global Connections

The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.

This project explores topics key to Industry, Innovation and Infrastructure: Build resilient infrastructure, promote sustainable industrialization and foster innovation.

Variations

  • This project will also work with the NXT's light sensor, since it can measure reflected light from your hand. You will have to change your code, though — not only to use the right sensor block, but because the light intensity value increases as you move your hand closer to the robot — this is the opposite of what happens with the ultrasonic sensor. Can you figure out why?
  • If you increase the value of the "Constant" block in the program too much, your robot might become unstable — it will bounce back and forth when it approaches a wall, without ever actually coming to a complete stop. Can you find out how big the constant has to be before this happens? What happens as you continue to increase the value?

Careers

If you like this project, you might enjoy exploring these related careers:

Career Profile
Have you watched "The Transformers" cartoon series or seen the "Transformers" movies? Both shows are about how good and evil robots fight each other and the humans who get in the middle. Many TV shows and movies show robots and humans interacting with each other. While this is, at present, fantasy, in real life robots play a helpful role. Robots do jobs that can be dangerous for humans. For example, some robots defuse landmines in war-stricken countries; others work in harsh environments like… Read more
Career Profile
Mechanical engineers are part of your everyday life, designing the spoon you used to eat your breakfast, your breakfast's packaging, the flip-top cap on your toothpaste tube, the zipper on your jacket, the car, bike, or bus you took to school, the chair you sat in, the door handle you grasped and the hinges it opened on, and the ballpoint pen you used to take your test. Virtually every object that you see around you has passed through the hands of a mechanical engineer. Consequently, their… Read more
Career Profile
Just as a potter forms clay, or a steel worker molds molten steel, electrical and electronics engineers gather and shape electricity and use it to make products that transmit power or transmit information. Electrical and electronics engineers may specialize in one of the millions of products that make or use electricity, like cell phones, electric motors, microwaves, medical instruments, airline navigation system, or handheld games. Read more
Career Profile
Computers are essential tools in the modern world, handling everything from traffic control, car welding, movie animation, shipping, aircraft design, and social networking to book publishing, business management, music mixing, health care, agriculture, and online shopping. Computer programmers are the people who write the instructions that tell computers what to do. Read more

News Feed on This Topic

 
, ,

Cite This Page

General citation information is provided here. Be sure to check the formatting, including capitalization, for the method you are using and update your citation, as needed.

MLA Style

Science Buddies Staff. "Use the Force! Push & Pull Robots With an Invisible Force." Science Buddies, 8 Feb. 2023, https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p013/robotics/push-pull-robot-sensors. Accessed 19 Mar. 2024.

APA Style

Science Buddies Staff. (2023, February 8). Use the Force! Push & Pull Robots With an Invisible Force. Retrieved from https://www.sciencebuddies.org/science-fair-projects/project-ideas/Robotics_p013/robotics/push-pull-robot-sensors


Last edit date: 2023-02-08
Top
We use cookies and those of third party providers to deliver the best possible web experience and to compile statistics.
By continuing and using the site, including the landing page, you agree to our Privacy Policy and Terms of Use.
OK, got it
Free science fair projects.