Security Guard Bot

40-60m

Introduction

Hold up… that’s my stuff! In this activity, program your robot into a Security Bot to protect your stuff while you’re gone. Place it on top of your stuff then, when the alarm is tripped, it’ll go off and scare your robber away!

Getting setup

First, you’ll need to get started with a few programs, tools, and materials! Here’s a list of the things you’ll need:

  • Computer
  • Arduino + LRF Library
  • Printer
  • Paper
  • Scissors
  • Colouring Pencils or Markers
  • Tape

Download the Costume: security-bot-costume.pdf.

Important

This is an Arduino activity, so make sure you download the program and the library here.

Explore your code

Once you’re all setup, check out a sample snippet of your code below. It’s much longer, but here’s what you should see.

#include <LittleRobotFriends.h>

LRFPattern myAlarmPattern = {
  .colorA = LRFColor_Red,
  .colorB = LRFColor_Blue,
  .transform = LRFTransform_ZigZag,
  .duration = LRFDuration_Long
};

boolean armed = false;
boolean alarmTripped = false;

void myTapHandler(LRFEvent event) {
    if (armed == true) {
      armed = false;
      alarmTripped = false;
      lrf.speech.quiet();
    }
    else if (armed == false) {
      lrf.eyes.setColor(LRFColor_Red);
      armed = true;
    }
}

What does this program do?

The program sets your robot in armed mode when you tap its left hand sensor. You’ll know your robot is ready and armed when the eyes are red. If someone tries to move your robot from the spot it is guarding, it will set your robot in alarmTripped mode. When this event is triggered, it causes your robot to start beeping. To disarm it, tap the left hand sensor again until the eyes turn green.

What else is in the code?

There are a few other important elements in the program. Your robot is programmed to do a few things over and over again… in a loop! The loop code shown below tells your robot when its alarm is armed and when it is tripped. When your robot is tripped that means the motion sensor has been triggered.

void loop() {
  lrf.loop();
  if (armed) {
    if ((lrf.motion.readX() > 5) || (lrf.motion.readX() < -5)) {
      alarmTripped = true;
    }

    if (alarmTripped == true) {
      lrf.speech.setFrequency(1000);

      if (lrf.eyes.isBlinking() == false) {
        lrf.eyes.blinkPattern(myAlarmPattern);
      }
    }
  }
  else if (armed == false) {
    lrf.eyes.setColor(LRFColor_Green);
  }
}

Let’s take an even closer look inside the loop code. In the line of code below you’ll see the number 5. This is an arbitrary number. Essentially, the code is saying “when motion on X axis is greater than 5” or “when motion on X axis is less than 5” set off the alarm!

  if (armed) {
    if ((lrf.motion.readX() > 5) || (lrf.motion.readX() < -5)) {
      alarmTripped = true;
    }

In the line of code below, the statement is saying “if your robot’s alarm is tripped then set the sound frequency of 1000 Hz”.

    if (alarmTripped == true) {
      lrf.speech.setFrequency(1000);

There are tons of other pieces of the code you can explore, but those are some of the fundamental parts that make the trick work!

Upload this trick onto your robot

It’s time to upload the Security Bot trick onto your robot. You’ll need to connect your robot to the computer with the USB cable.

Make sure your board and port is connected, then simple click the upload button!

Upload

You’ll know when the trick is uploaded onto your robot when the Arduino Sketch says “Upload Complete”.

Upload Complete

Print your Security Bot costume

Print the costume out on regular paper, or cardstock paper if you want it to last longer. Whip out the pencil crayons, markers, and scissors. Secure the costume onto your robot with a bit of tape and you’re done!

Costume

Don’t Forget

Download your costume here!

Important

Make sure you print your costume in Actual Size, otherwise it won’t fit!

Try out the trick!

Turn your Security Guard on and set it to armed mode. Place it on your diary or Christmas gifts or something else you don’t want others to touch!

Guarded Gifts

Don’t Forget

To disarm it, tap the left hand sensor!

What’s next?

If you want to take this activity one step further, try completing a few of these challenges!

Challenge 1:

Change your robot’s eye colour when it is armed. Choose any colour!

void myTapHandler(LRFEvent event) {
    if (armed == true) {
      armed = false;
      alarmTripped = false;
      lrf.speech.quiet();
    }
    else if (armed == false) {
      lrf.eyes.setColor(LRFColor_Red);
      armed = true;
    }
}

Challenge 2:

Customize your Alarm Pattern by adjusting the eye colours, transformation, and duration. Change the section of the code below!

LRFPattern myAlarmPattern = {
  .colorA = LRFColor_Red,
  .colorB = LRFColor_Blue,
  .transform = LRFTransform_ZigZag,
  .duration = LRFDuration_Long
};

Challenge 3:

Change the Event Handler that arms your robot to a hug event. You’ll need to change the section of the code below.

void setup() {
  lrf.setup();

  lrf.disableEventExpressions();
  lrf.setBoredomTimer(0);
  lrf.setEventHandler(LRFEvent_TapLeft, myTapHandler);
}