Build a Motion-Activated Guard Robot (BlueBot Project #1)
AbstractDo you ever wish you could hire someone to guard your favorite toys, or keep certain people from coming into your room? What if you could make a robot to do it for you? This project will show you how to build a simple security robot controlled by a motion-detecting sensor. When someone comes near your valuables or enters the room, the robot will spring to life and (hopefully) scare them away!
Recommended Project Supplies
Build a motion-activated guard robot and adjust its behavior to avoid false alarms.
Have you ever seen a movie with a guard robot or a battle droid, and wished you could have your own? While this project will not show you how to build a robot that can fly or shoot lasers, you can build a simple motion-activated robot that will suddenly come to life to scare away intruders. Figure 1 shows a picture of the robot, followed by a video demonstration.
Figure 1. The motion-activated guard robot you will build in this project.
How does the robot detect motion and know when to turn on? The robot can detect infrared (IR) light, which is a type of electromagnetic radiation. Humans can only see a small part of the electromagnetic spectrum (visible light), but there are many other types of electromagnetic radiation, like radio waves, x rays, and ultraviolet light. Infrared light is given off by warm objects, like a human body or a hot stove top, but it is just outside the range of what humans can see.
The robot relies on a special type of sensor to detect infrared light. Sensors are electronic components that can tell a robot or computer something about its surroundings. For example, cameras and microphones are types of sensors (very similar to eyes and ears for a human). This robot uses a passive infrared (PIR) sensor, which is designed to detect changes in infrared light. So, if a person is not moving, even though they still emit infrared light, they will not trigger the sensor. If a person walks by the sensor, however (or an intruder walks past the robot!), the sensor will detect a moving source of infrared light. The sensor is connected to a circuit, or group of other electronic parts, that turn on the robot's motors to make it move.
You might have actually encountered PIR sensors in everyday life, even if you did not realize it. They are very commonly used in home security systems, since they can "see" a person walking through a room, even at night! They are also used in energy-saving lighting systems to make motion-activated lights. The lights can automatically turn on when someone walks into a room, and will turn off if no movement has been detected for a certain period of time. Figure 2 shows the type of PIR sensor you might see in a house, school, or other building.
Figure 2. The type of PIR sensor you might see as part of a home security system or motion-controlled lighting system.
PIR sensors are usually designed to have a very wide field of view, or area that the sensor can "see." This can be great for a security system when you need a sensor to see an entire room, but it can be annoying if you only want your robot to guard a specific area. Watching for changes over a large area can create a false alarm and cause the robot to turn on accidentally. In this project, you will follow directions to build a motion-activated robot, then follow the Engineering Design Process to make adjustments to your PIR sensor's field of view to help avoid false alarms.
The rest of the Introduction contains more details about the electronic components used in the circuit. The following information is provided as a reference, and you do not need to fully understand it in order to do the project. If are ready to just start building the robot, you can move on to the Procedure.
If you would like to read the rest of the Introduction, it will help if you are familiar with basic electronics terms like voltage, current, and resistance. Science Buddies has many beginner and intermediate level electronics projects, an Electronics Primer, and an Electricity, Magnetism, & Electromagnetism Tutorial that can help you learn more about these topics. You can also refer to the Bibliography section for more information.
For a complete technical explanation of how the circuit works, including a circuit diagram, see the Help section.
The circuit you will build in this project requires a variety of electronic components. All of the components are combined on a chassis, or plastic base for the robot, which includes wheels. Some of the components, like batteries and switches, you probably use every day (even if you do not notice it). Others, like diodes and transistors, might be new to you if you have not done an electronics project before. Table 1 has pictures and descriptions of each component you will use in this project. For a more detailed explanation of what each component does in the circuit, see the Help section.
||This is the power supply for your robot. Battery packs come in all shapes and sizes. The one in this project holds 4 AA batteries.|
||A breadboard allows you to quickly and easily connect wires and electronic components in order to build a circuit. The connections are not permanent, so you can easily move things around if you make a mistake.|
||You use switches every day to turn lights and appliances on and off. This is a tiny switch that fits on a breadboard, to let you turn your robot on and off.|
||Jumper wires are short wires used to make electrical connections on a breadboard. They come with many colors of plastic insulation, which makes it easy to color-code and organize complicated circuits.|
||Electrical current causes a motor to spin. Two motors drive the robot's wheels. This type of motor runs on direct current (DC) from a battery (as opposed to alternating current [AC] from a wall outlet).|
||A MOSFET is a special type of transistor, which acts like a control valve to let electrical current flow. As an analogy, think of how a valve can control the flow of water through a garden hose. In this circuit, the MOSFETs control the flow of current through the motors. See the Help section for more detailed information about MOSFETs, including what MOSFET stands for.|
||A diode is like a one-way valve for electricity. It only lets current flow in one direction. In this circuit, diodes are used to protect the MOSFETs from voltage spikes that can be caused by abruptly stopping the motors.|
||The passive infrared sensor acts as a motion detector. It has an output put that stays "low" (0 volts [V]) when it does not detect motion, and goes "high" (3.3 V) when it detects motion. This output can be used to activate other things in the circuit.|
|Male-female jumper wire||
||This is a special type of jumper wire that comes with a female connector on one end and a male connector on the other end.|
How do you combine all these components to control the motors and make the robot move forward? While the full details are in the Help section, there are two basic things that will help you understand:
- The PIR sensor outputs a high voltage when it detects motion, and a low voltage when it does not detect motion.
- The MOSFETs act like valves that control the flow of electricity through the motors. When a MOSFET's input receives a high voltage, the MOSFET makes the motor turn on (which spins a wheel). When a MOSFET's input receives a low voltage, the MOSFET makes the motor shut off (so the wheel stops).
Can you see how these two things could be set up to control a motor, and spin a wheel, based on whether or not the sensor detects motion? You need to connect the output of the sensor to the input of the MOSFET. Figure 3 shows a simplified diagram of this process (remember to refer to the Help section for the full explanation).
When a passive infrared sensor does not detect any motion only low voltage power is sent to the MOSFET. If the MOSFET doesn't receive enough power no current flows to the motor and the motor stops. When a PIR sensor does detect motion it sends high voltage to the MOSFET. The MOSFET is able to pass a current to the motor and the motor will turn the wheels of the robot.
Figure 3. A diagram explaining the robot's operation.
Terms and Concepts
- Infrared (IR) light
- Electromagnetic radiation
- Electromagnetic spectrum
- Passive infrared (PIR) sensor
- Field of view
- Battery pack
- Jumper wires
- DC motor
- Male-female jumper wire
Advanced terms (see Help section):
- Threshold voltage
- N-channel MOSFET
- P-channel MOSFET
- What is infrared light? How is it different from visible light?
- How does a passive infrared (PIR) sensor work?
- What are some everyday uses of PIR sensors?
- How can a PIR sensor be used to control a robot?
- How could adjusting a PIR sensor's field of view change when the robot is activated?
These beginner references will be useful if you are just starting out with electronics and robotics:
- Finio, B. (2015, September 5). How to Use a Breadboard. Retrieved September 5, 2015.
- Science Buddies staff (n.d.). Electronics Primer: Introduction. Retrieved September 8, 2015.
These references will be useful for students who want to learn more about how the circuit works, and about electronics in general:
- Lindblom, J. (n.d.). How to Read a Schematic. SparkFun Electronics. Retrieved June 2, 2014.
- Taylor, C. (n.d.). Voltage, Current, Resistance, and Ohm's Law. SparkFun Electronics. Retrieved June 2, 2014.
These references contain specific information about some of the circuit components used in this project:
Recommended Project Supplies
- BlueBot: 4-in-1 Robotics Kit, available from our partner
Home Science Tools.
You will need the following components from the kit (the kit also contains additional parts for three other projects). See the Background section for pictures if you are not sure what a part looks like.
- Blue plastic robot chassis (includes wheels, motors, and 4xAA battery holder)
- AA batteries (4)
- Jumper wire kit
- Power switch
- Diodes (2)
- MOSFETs (2)
- PIR sensor
- Male-female jumper wires (3)
- You will also need the following materials, not included in the kit:
- Double-sided foam tape
- Small Phillips head screwdriver (for assembling the chassis)
- Paper towel tube
- Optional: Wire cutters (can be used to shorten the metal leads on some parts of your circuit, making the circuit "neater")
- Optional: Needle-nose pliers or tweezers (make it easier to handle small circuit components)
- Lab notebook
Disclaimer: Science Buddies participates in affiliate programs with Home Science Tools, Amazon.com, Carolina Biological, and Jameco Electronics. Proceeds from the affiliate programs help support Science Buddies, a 501(c)(3) public charity, and keep our resources free for everyone. Our top priority is student learning. If you have any comments (positive or negative) related to purchases you've made for science projects from recommendations on our site, please let us know. Write to us at email@example.com.
Assembling Your BlueBot Chassis
- Follow the instructions in the video to assemble your robot chassis.
- Note that your kit does come with printed directions for assembling the chassis, but we recommend watching the video so you fully understand how all the parts fit together.
- Note that we recommend using double-sided foam tape to attach the battery holder to the top of the chassis, as shown in Figure 4. The printed directions recommend putting the battery holder in-between the two chassis plates, but this makes it harder to change the batteries.
Figure 4. A completed BlueBot chassis with breadboard and battery pack on top.
Assembling Your Circuit
- To build your circuit, you will need to know how to use a breadboard. Watch the video and see the Science Buddies reference How to Use a Breadboard for Electronics and Circuits.
- Now that you know how to use a breadboard, you are ready to assemble your BlueBot circuit. Table 2 shows a list of all the components in the circuit and where they go on the breadboard.
You can download and print a PDF of this table—complete with checkboxes to track each step—to use while you are building your robot.
You can also view a slideshow that shows breadboard diagrams of the circuit. Follow along in the table and/or slideshow to build your circuit one component at a time. Your finished circuit should look like the one in
Figure 5. Pay attention to these notes:
- Remember to push all components firmly into the breadboard.
- All references to orientation (up, down, left, and right) assume you have the breadboard "right-side up," so the writing is facing you.
- Your jumper wire kit comes with an assortment of colors, and the colors may vary. It does not matter what color jumper wires you use. Your colors do not need to match the colors in the diagrams. In general, you should use the shortest wires possible, to help keep your circuit neat.
- You will use male-female jumper wires to connect the PIR sensor to the breadboard. These wires act like "extension cords" that allow you to attach the sensor to the front of your robot. You do need to keep track of the wire colors when connecting the PIR sensor, since you need to connect the three pins in the right order.
- Insert the batteries last. If you see or smell smoke when you insert the batteries, you have a short circuit somewhere. Immediately remove the batteries and re-check your wiring.
||F1, F2, F3||Direction it is facing does not matter, but make sure to slide switch down (toward row 30, away from row 1), this is the "off" position.|
||J2 to (+) bus||Color does not matter.|
||Left side (+) bus to right side (+) bus||Color does not matter.|
|Jumper wire||Left side (-) bus to right side (-) bus||Color does not matter.|
|MOSFET||C11, C12, C13||Writing should face to the left, large silver tab should face to the right.
Note: the writing on your MOSFET may not match the picture exactly. This is OK.
|MOSFET||C18, C19, C20||Writing should face to the left, large silver tab should face to the right.
Note: the writing on your MOSFET may not match the picture exactly. This is OK.
|Jumper wire||A13 to (-) bus||Color does not matter.|
|Jumper wire||A20 to (-) bus||Color does not matter.|
|Diode||A12 to (+) bus||Gray band must face to the left.
Optional: Shorten the leads (see Figure 5).
|Diode||A19 to (+) bus||Gray band must face to the left.
Optional: Shorten the leads (see Figure 5).
|PIR sensor||GND pin to (-) bus
OUT pin to J15
VCC pin to (+) bus
|Color-code wires to make connections easier. Connect black wire to GND, blue wire to OUT, and red wire to VCC. See slides 13 and 14 in slideshow.|
|Jumper wire||E11 to G15||Color does not matter.|
|Jumper wire||E18 to F15||Color does not matter.|
|Top motor||Red lead to (+) bus
Black lead to E12
|When the robot is driving forward, this is the "right" motor|
|Bottom motor||Red lead to (+) bus
Black lead to E19
|When the robot is driving forward, this is the "left" motor.|
|Battery holder||Red lead to J1
Black lead to (-) bus
|Do not insert batteries until circuit is complete.|
|AA battery||N/A||Insert into battery holder. Make sure (+) signs on batteries line up with (+) signs in battery holder.|
1. Blank breadboard.
2. Insert power switch into holes F1, F2, F3. Direction of switch does not matter.
3. Connect jumper wire from hole J2 to (+) bus.
4. Connect jumper wire from left (+) bus to right (+) bus.
5. Connect jumper wire from left (-) bus to right (-) bus.
6. Insert MOSFET into holes C11, C12, C13. Writing must face to the left.
7. Insert MOSFET into holes C18, C19, C20. Writing must face to the left.
8. Connect jumper wire from hole A13 to (-) bus.
9. Connect jumper wire from hole A20 to (-) bus.
10. Bend the diode's leads down by 90 degrees and trim them so they fit into the breadboard.
11. Insert diode into hole A12 and (+) bus. Gray stripe must face to the left.
12. Insert diode into hole A19 and (+) bus. Gray stripe must face to the left.
13. Connect a red male-female jumper wire to the VCC pin of the PIR sensor, a blue wire to the OUT pin, and a black wire to the GND pin.
14. Connect PIR sensor: GND pin to (-) bus, OUT pin to J15, VCC pin to (+) bus.
15. Connect jumper wire from hole E11 to G15.
16. Connect jumper wire from hole E18 to F15.
17. Connect top motor's red wire to (+) bus, black wire to hole E19.
18. Connect bottom motor's red wire to (+) bus, black wire to hole E12.
19. Connect battery holder's red wire to hole J1, black wire to (-) bus.
End of Slideshow Images
Figure 5. Your completed circuit should look like this.
- After you have completed your circuit, mount the PIR sensor to the front of your robot chassis using double-sided foam tape, as shown in Figure 6.
Figure 6. Mount the PIR sensor to the front of your robot using double-sided foam tape.
Testing Your Robot
You are finally ready to start testing your robot! Remember that now you will need to follow the engineering design process to get your robot working. Follow these steps to learn how to use your robot.
- Double-check your circuit against the breadboard diagrams in the previous section. Remember that just one misplaced wire can prevent the circuit from working properly.
- Your PIR sensor has two small orange knobs on it, labeled Sx and Tx (Figure 7). These knobs can be adjusted using a small Phillips-head screwdriver. Tx adjusts the "delay on time," or how long the sensor will remain on after detection motion. This value can range from 3 to 200 seconds. To start, we recommend turning this knob all the way counter-clockwise to set the delay to 3 seconds (otherwise, your robot will drive forward too far when it detects motion). You can increase the delay later if you want. Sx adjusts the sensor's sensitivity to motion.
Figure 7. Adjustment knobs on the PIR sensor. Sx adjusts sensitivity and Tx adjusts delay time.
- Hold the robot's chassis in one hand, so the wheels are off the ground, and the PIR sensor is facing away from you and any other sources of infrared light, like other people, animals, or an open window (sunlight contains some infrared light).
- Turn the robot's power switch "on" by sliding it up, toward row 1 on the breadboard.
- Your robot's wheels should spin briefly as the PIR sensor "boots up," then come to a stop. Check Table 3 to see what you should do next.
|Observation||What to Do|
|I see or smell smoke.||Immediately turn your robot off. You have a short circuit somewhere. Recheck your wiring against the breadboard diagrams in the previous section.|
|Each wheel spins forward when I turn the robot on.||Your robot works! Move on to the next step.|
|One or both wheels spin backwards when I turn the robot on.||Reverse the red and black wires of the motor if the wheel is spinning backwards. See the Help section for details.|
|The wheels did not spin at all when I turned the robot on.||See the Help section for troubleshooting steps.|
- Now, try waving your hand in front of the PIR sensor. This should make your robot's wheels spin. If your robot is not working, see the Help section.
- Try to discover other ways that you can activate the robot. What happens if you put the robot on the floor and then walk in front of it? What happens if you wave an inanimate object, like a ruler, in front of the sensor, or throw a crumpled piece of paper in front of the robot?
- You might discover that it is actually too easy to activate the robot, because the PIR sensor has such a wide field of view. For example, if you try to hide the robot under a desk or table, it might jump out too early when someone walks by. This is where the engineering design process really comes into play. Can you figure out how to modify the sensor's field of view? For example, you could partially cover the sensor with a shortened paper towel tube, like in Figure 8. You can also adjust which way the PIR sensor is facing (forward, down, up, or to the side).
Figure 8. Partially covering the sensor with a shortened paper towel tube will help narrow its field of view.
- Continue making adjustments to your PIR sensor, as needed. You do not want the robot to activate too early or too late. What works best for the situation in which you want to use the robot? For example, do you want the robot to wait in a room and drive toward whoever walks in? Do you want to hide it around a corner or under a table? Once you have your robot working just the way you like it, leave it set up to "guard" something, and scare away the next person who comes by!
Looking for more robot fun? Explore the World of Robotics with This Suite of Projects!
For troubleshooting tips, please read our FAQ: Build a Motion-Activated Guard Robot (BlueBot Project #1).
Ask an Expert
This project explores topics key to Industry, Innovation and Infrastructure: Build resilient infrastructure, promote sustainable industrialization and foster innovation.
- There are three other projects you can do with your BlueBot kit. Since you have already assembled your chassis, all you need to do is build a new circuit.
- The sensor's circuit board has a jumper that you can use to toggle the detection range between 15 or 30 feet. You can read more about how to do this on the sensor's datasheet. How does adjusting the jumper affect the performance of your robot?
- The other robots in your BlueBot use something called differential steering. They use two different sensors to help the robot steer left and right. In this project, you only used one sensor to make the robot drive forward. Can you use two PIR sensors to make a motion-tracking robot that will actually follow a person around? This might be more difficult than it sounds, so be ready for a challenge!
- The Arduino is a very popular type of microcontroller used in robotics. It lets you write a computer program that can read inputs from sensors and use them to control motors. This gives you more precise "control" over your robot's behavior. Can you build a programmable motion-activated guard robot by adding an Arduino to your chassis? For example, using the other parts in your BlueBot kit (the H-bridge "motor driver" found in the Obstacle-Avoiding project), you can make a robot that drives forward when it detects motion, then goes in reverse to "hide" again. You could also make the robot wait a certain amount of time after detecting motion before it drives forward. See our How to Use an Arduino page to learn more.
- You can also use a PIR sensor to make a homemade alarm system, using a tiny programmable computer called a Raspberry Pi. See the Science Buddies Raspberry Pi Projects Kit—specifically the Make a Motion Sensor Alarm with a Raspberry Pi project—to learn more.
Looking for more robot fun? Explore the World of Robotics with This Suite of Projects!
Frequently Asked Questions (FAQ)
- My robot's wheels do not spin at all when I turn it on, or when I wave my hand in front of the PIR sensor. What should I do?
- Only one of my robot's wheels is spinning. What is wrong?
- My robot is going backwards! What should I do?
- My robot keeps moving on its own, even when no one walks in front of the sensor! What is happening?
- I have double-checked everything and my robot still does not work. How can I check if something is broken?
- How does the PIR sensor work?
- How does a MOSFET work?
- How does the circuit work? What is the circuit diagram?
- What are the circuit diagram symbols for the components in this project?
- How did you make the breadboard diagrams for this project?
- Double-check all of your breadboard connections. Make sure every lead and jumper wire is firmly pressed into the breadboard. Make sure all of your connections match the breadboard diagrams from the Procedure. You can read about other common breadboard mistakes in the the Common Mistakes section of our breadboard tutorial.
- Make sure all your batteries are properly inserted into the battery holder, with the "+" symbols on the batteries lined up with the "+" symbols inside the holder.
- If you have been using your robot for a long time, or did some of the other BlueBot projects first, your batteries may be dead. Try putting fresh batteries in your robot if none of the other steps work.
Figure 9. In the top image, the motors' red leads are connected to the power bus, and the black leads are connected to the MOSFETs' drain pins (holes E4 and E27). If this configuration causes your robot to go backwards, just switch the red and black wires for each motor, as shown in the bottom image. Connect the black wires to the power bus, and the red wires to holes E4 and E27. Do not worry about violating the color-coding convention for positive and negative; all this does is reverse the direction in which the motors spin. If only one motor is spinning backwards, only switch the wires for that motor.
- Try plugging your motor's leads directly into the buses on your breadboard (for each motor, one lead to the power bus, one lead to the ground bus). If the motors turn on, then you know that they are working, and the problem is elsewhere in your circuit. If the motors do not turn on, that does not necessarily mean they are broken. There might be a problem with your power supply (see next point).
- Check your breadboard's power supply.
- Set your multimeter to measure DC volts. Four fresh AA batteries should provide just over 6 V.
- Turn your power switch on and measure the voltage between the breadboard's buses. If you do not read a voltage, there may a problem with your power switch (see the first question in this FAQ), but you should also double check that your power switch and the red jumper wire from hole J2 to the power bus are in the right place.
- Unplug the red and black battery pack leads and measure the voltage of the battery pack directly. If you get a reading, then you know your battery pack is working, and the problem is with your breadboard connections or the power switch. If you do not get a reading, make sure all the batteries are in the correct orientation in your battery pack, and that none of the metal clips and springs that hold the batteries in place are loose.
- Measure the voltage of your PIR sensor's output pin (labeled OUT on the sensor, connected to row 15 on the right side of the breadboard). It should read 0 V when the sensor is not triggered, and between 5–6 V when the sensor detects motion.
- If the motors work when you plug their leads directly into the buses, and the output voltage of the PIR sensor increases when you wave your hand in front of it, but the robot still does not work, then the problem is elsewhere in your circuit. You know the individual components are functioning so nothing is "broken." Double and triple-check all your breadboard connections. Remember that just one misplaced wire can prevent the whole circuit from working.
Figure 10 shows a simplified explanation of how a MOSFET works. A voltage is applied to the gate pin in order to control the flow of current between the drain and source pins. When the voltage between the gate and source pins (VGS) is below a certain limit, called the threshold voltage (Vth), no current flows. When VGS exceeds Vth, the MOSFET begins to conduct, allowing current to pass through. This is what allows you to use the gate voltage of a MOSFET to turn a DC motor on and off. For this robot, the MOSFET's gate voltage is controlled by the PIR sensor's output.
Figure 10. Simplified explanation of a MOSFET's operation.
The exact description of how a MOSFET works is more complicated than this. As VGS increases past Vth, the current through the MOSFET will continue to increase. Eventually the MOSFET will reach saturation, where no additional current can flow, even if VGS continues to increase. The MOSFET's behavior will also depend on the type of load to which it is attached. The MOSFET used in this project is an N-channel MOSFET, which requires a positive gate voltage to turn on. A P-channel MOSFET requires a negative gate voltage to turn on. Advanced users can refer to the Bibliography for more information on MOSFETs.
- The batteries supply a voltage, Vbatt to the circuit. When the switch is closed, V1 = Vbatt. When the switch is open, V1 is "floating", so the circuit does not receive any power.
- The PIR sensor receives power from its VCC pin and is connected to the circuit's ground through its GND pin. The sensor is digital—it outputs a logical "low" or "high" from its OUT pin depending on whether or not it detects motion. A "low" signal is 0 V, and a "high" signal is approximately 5 V.
- 5 V is above the MOSFET's threshold voltage. So, when the sensor goes "high," this turns on both MOSFETs (notice how the OUT pin of the sensor is connected to the gate pin of both MOSFETs). This allows current to flow through the motors, and the robot drives forward.
- Finally, each motor has a diode connected across its terminals. Motors can create large voltage spikes when they abruptly come to a stop (this has to do with the relationship between electrical current and magnetic fields, if you want to do more research on the explanation). The diodes help prevent damage to the MOSFET by safely discharging the current generated by the voltage spike.
Figure 11. A complete circuit diagram for the motion-activated robot.
|Item name||Picture||Breadboard Diagram Symbol||Circuit Diagram Symbol|
If you like this project, you might enjoy exploring these related careers:
Contact UsIf you have purchased a kit for this project from Science Buddies, we are pleased to answer any question not addressed by the FAQ above.
In your email, please follow these instructions:
- What is your Science Buddies kit order number?
- Please describe how you need help as thoroughly as possible:
Good Question I'm trying to do Experimental Procedure step #5, "Scrape the insulation from the wire. . ." How do I know when I've scraped enough?
Good Question I'm at Experimental Procedure step #7, "Move the magnet back and forth . . ." and the LED is not lighting up.
Bad Question I don't understand the instructions. Help!
Good Question I am purchasing my materials. Can I substitute a 1N34 diode for the 1N25 diode called for in the material list?
Bad Question Can I use a different part?