RSS
 

Archive for the ‘minecraft’ Category

Motion activated “Attack Creeper”!

28 Mar

That's a nice everything you have...

 

Update! I’ve been entered in the Instructables game.life challenge contest. If you like my project please vote for it. Here’s the link to my instructable: http://www.instructables.com/id/Motion-activated-Attack-Creeper/

In January I decided that I needed to upgrade my in-home security. Unfortunately for me my building does not allow dogs so a big scary animal was not an option. Then suddenly, inspiration struck or I guess you could say exploded.

The most logical option was obviously to create a near life size Arduino powered, motion activated, audio playing, remote controllable Minecraft Creeper. Obviously.

As always this started with a fairly lengthy list of relatively inexpensive supplies. Here’s the most complete list I can compile from memory.

The electronics

  • Arduino UNO (all good projects start with an Arduino)
  • Ada Fruit Wave Shield (for audio playback with the Arduino)
  • Electric Sumo CMoy Amp (I wanted to build one of these anyway so I picked it up for the project)
  • Cheap RC Car (I picked mine up for $15 at the drug store)
  • PIR Sensor
  • Speaker (mine came with my Wave Shield kit)
  • Various bits of wire
  • Batteries, lots and lots of batteries
  • Something to power the Arduino (I used a Minty Boost also from Adafruit)

 

And the crafty bits

  • Cardboard boxes
  • Paint
  • Hot glue (I used the normal stuff to hold the electronics in place and some heavy duty pull-the-skin-off-your-hands industrial stuff to hold the boxes together
  • Masking or painters tape
  • zip ties/cable ties

 

OK So first lets build a cardboard creeper. I sketched out the basic idea to help me find boxes that fit the correct proportions. I wouldn’t want a disproportionate in-home “Attack Creeper” because that would be ridiculous.

My first step was cutting holes to allow me to run cables internally from box to box and opening up some access doors on the back of each box. I also cut holes in the bottom box to allow me to thread cable ties through the bottom and around the RC car and opened holes for the PIR sensor and speaker. After this was done I connected the three cardboard boxes that make up the body using some heavy duty hot glue. This stuff will pull the laminate off your desk before it pulls off, serious stuff. Everything got a coat of “Creeper Green” paint and I masked off the eyes and mouth for a coat of “Soul-less Killing Machine Black”.

Next step electronics!

My program basically works like this

  1. Detect motion with the PIR sensor
  2. Play fuse.wav (aka Tsssssssss…) via the Wave Shield
  3. Trigger the “Forward” button on the RC car remote for 2 seconds
  4. Play explode.wave via the Wave Shield
  5. Wait 10 seconds and reset

Here’s a wiring diagram which explains how this monster is hooked up.

The PIR sensor was really easy to hook up using the instructions available on Adafruit’s website. I imagine any sensor that measures distance or detects motion could be used in place of this. I will say (for better or worse) using the example code for the PIR sensor made it very sensitive, maybe too sensitive.

The RC car came with a simple remote that contained four momentary micro push buttons. I just wired into one side of the “forward” button and used the Arduino to turn the button. I also removed most of the body of the RC car leaving just the wheels, motors and frame.

I copied the in game sound effects from Minecraft to the SD card in the wave shield for playback. The output volume of the Wave Shield on it’s own is pretty quiet so I ran it through the CMoy Amp to boost it’s volume to a appropriately scary level.

After I was sure I had everything working I used some standard craft hot glue to glue the speaker and PIR sensor inside of the Creeper body. I also glued the back of the body closed because as I learned it’s nearly impossible to get tape to stick to acrylic paint.

Here’s a montage of the little guy working. He’s just so adorable I could explode.

Now if you make your own motion activated “Attack Creeper” you’ll find the real fun is hiding in places around the house your roommates and/or significant other would not expect it.

And since someone might be interested in my terribly mashed up code here’s the code I used to run the thing. I used the example code for the PIR sensor and Wave Shield both available on adafruit.com to create this mostly functional code. Use at your own risk!

/*
  Motion activated "Attack Creeper"
 
Detects motion using a PIR sensor. When motion is detected plays two wave files and activates RC remote.
 
Code examples edited and reworked from http://wwww.ladyada.net
 
TheNewHobbyist 2011 
 
 */

#include 
#include 
#include 
#include "WaveUtil.h"
#include "WaveHC.h"


SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card
FatReader f;      // This holds the information for the file we're play

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

  // for PIR
  int ledPin = 13;                // choose the pin for the LED
  int inputPin = 6;               // choose the input pin (for PIR sensor)
  int pirState = LOW;             // we start, assuming no motion detected
  int val = 0;                    // variable for reading the pin status
  

#define DEBOUNCE 5  // button debouncer

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end; 
  extern int  *__brkval; 
  int free_memory; 
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end); 
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval); 
  }
  return free_memory; 
} 

void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("nrSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}

void setup() {
  byte i;
  
  // set up serial port
  Serial.begin(9600);
  putstring_nl("WaveHC with ");
  putstring_nl("buttons");
  
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam());      // if this is under 150 bytes it may spell trouble!
  
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, INPUT);
  pinMode(8, OUTPUT);
  
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!)  
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
  
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
// Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part)) 
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
  
  // Lets tell the user about what we found
  putstring("Using partition ");
  Serial.print(part, DEC);
  putstring(", type is FAT");
  Serial.println(vol.fatType(),DEC);     // FAT16 or FAT32?
  
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
  
  // Whew! We got past the tough parts.
  putstring_nl("Ready!");
  
  TCCR2A = 0;
  TCCR2B = 1<
						
 
 
 


css.php