Agent KK: Defend your Room from Unauthorized Intruders!

Agent KK: Defend your Room from Unauthorized Intruders!

Build this little Guardian against intrusions!


Siblings, siblings, siblings… Especially younger siblings… They sneak into your room, and disrupt your things, when they’re not simply taking them as their own! What you need is to call on the Guardian of the Wardrobe!

Build and program this little GoPiGo to protect your wardrobe, your closet, or even your whole room! Hide GoPiGo behind a closed door and when the door is opened, it will attack your siblings, scaring them, and even taking a picture as trespassing proof! That way, even mom will have to be on your side!

What you'll need for this project:

You can choose to use any of the last three items, or all of them, or none of them. The more you use, the better the protection, but if one is not available, it’s not a deal-breaker. The Guardian will guard without it.

If this is your first project with GoPiGo, take a look at the Getting Started pages before implementing this project.

Step 1: How to assemble the Guardian of the Wardrobe

Agent KK, your mission, should you choose to accept it, is to assemble the Guardian following these steps. We will deny all knowledge of your mission (but if you have questions, feel free to contact us).

  1. Make sure your GoPiGo is up and running and connected to your home network. Check your batteries.
  2. Plug the ultrasonic sensor into port A1. It doesn’t need the servo, so don’t worry if you don’t have it. You do need to find a way of attaching the ultrasonic in a fairly stable position, pointing forward.
  3. Plug in the camera module. Installing the camera is a bit more time consuming. Please refer to these instructions, especially the video to see how to attach the camera to the Raspberry Pi. You do not need to attach it to a servo for this project, you can attach it directly to the chassis.
  4. Plug the buzzer into Port D11. D11 is underneath the red board, so you have to flip GoPiGo on its back to see it. Attach the buzzer to the GoPiGo using tie wraps, or any other method that you have available to you.
  5. Plug the speaker into the audio plug on the Raspberry Pi itself. If it’s USB powered, you can use one of the USB ports on the GoPiGo. Otherwise, make sure its batteries are good.

Step 2: Getting the Code

The code for this project is available for both Python and Scratch. Use “DI Update Software” to get the latest versions of our projects (you can find this script on your Raspbian for Robots desktop). Depending on which version you want to use, choose one of the following two methods to access the code. Just don’t execute the code right away as our Guardian is not in position yet.


Launch Scratch through the “Scratch for Robots” interface. If you need help with this step, please follow the instructions described in this tutorial

Click on File/Open (you can also use Ctrl-O for a direct access) to get the File dialog.

Click on the Desktop button, then double click the GoPiGo folder.

Getting to Agent KK Scratch project

Once inside the GoPiGo folder, double click the Projects folder, and finally double click the AgentKK folder

agentKK Scratch Project

Choose agentKK and click the OK button to load it up inside Scratch.


Open up a Terminal window.

Navigate to ~/home/pi/Desktop/GoPiGo/Projects/AgentKK

cd ~/Desktop/GoPiGo/Projects/AgentKK

if you want to see what the Python code looks like, you can:

Step 3: Testing

Let’s verify that everything is working, before sending our Guardian off to do its job.

Start by putting GoPiGo on its back so it won’t run off when it detects an intrusion. Be careful not to hurt the ultrasonic sensor or the camera when you do this.
Place an obstacle in front of the ultrasonic sensor, less than 10 cm or 4 inches away.
Launch the script.

  • Scratch: click the green flag in Scratch
  • Python: sudo python

Launch agentKK from Python

Remove the obstacle in front of the ultrasonic sensor. There should be plenty of space in front of it now, enough to trigger the attack mode.

Are you getting the appropriate reactions?

  1. Yelling can be heard through the speaker
  2. A loud noise comes out from the buzzer
  3. A photo is taken, it is saved to your Pi Desktop
  4. The two LEDs on the GoPiGo blink
  5. The wheels on the GoPiGo turn (and if the GoPiGo wasn’t on its back, it would be going forward)

Step 4: Sending the GoPiGo on its mission

The Guardian is meant to guard a closed door against unauthorized opening.

  1. Put it behind a door, either a closet, or a bedroom door.
  2. Start the code remotely via your laptop
      1. Scratch: click the green flag
      2. Python:
        cd /home/pi/Desktop/GoPiGo/Projects/AgentKK
        sudo python
  3. For an ultimate test, open the door, and watch it go!

How to get the code for this project:

The easiest way to get the code is to update your Dexter Industries software through the “DI Software Update”. When you do this, all of the code files for new projects like this will show up!

File Path

When you run the DI Software Update, this project can be found in this location:


Downloadable File:

If you are not using the Dexter Industries custom software, Raspbian for Robots, and you still want to download this project, you can download it here.

Github Project :


Need help?

Have a question or a problem?  Post it on the forums and we’ll help you out.