An Arduino Project for Halloween - Scare the shit out

published on
So last halloween (2015) we (@Me@Niko) made this for our office Halloween party. We did some online research to find what can be really scary and figured out it cannot be one, but a combination of multiple thing will make this scary.
So what does this do?
  1. Detects someone coming nearby,
  2. Turns it's head towards the person coming,
  3. Eyes glow
  4. Screams!!!
Items needed for this build: Electronics Items:
  1. Arduino Uno R3 (Or raspberry pi, you can use the same concept but write your own code)
  2. Diffused Red LED 10mm - 2 - Link
  3. Adafruit Wave Shield - 1
  4. Resistors - 10k Ohm - Bundle
  5. NPN Transistors - P2N2222A - 5
  6. Breadboard, Wires, Power supply and regular stuffs.
  7. Ultrasonic Module - 1 - Link
  8. Servo Medium Size Motor - 1 - Link
  1. Halloween skull, better if made of soft plastic
  2. Some black nets to get the feel.
  3. Go crazy anything you want to add
  4. A solid base where you can put the motor on which the skull will move.
  5. A DIY cardboard base on which you can stick the skull to move.
  Steps: Step 1: First thing, the Wave Shield needs to be assembled. Its going to take around 15min. Follow the soldering instruction in the manual. This is how unassembled it came. Seriously WTF when i got the order without a clue that it has to be assembled.
And then after 15min mission accomplished.
[embed][/embed]   Step 2: Connect the ultra sound module and the motor now. Once done you should test it working. [embed][/embed]   Step 3: Load the code
 * This example plays every .WAV file it finds on the SD card in a loop
#include <WaveHC.h>
#include <WaveUtil.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 volumes root directory
WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads

const int trigPin = 7;
const int echoPin = 8;

SoftwareServo myservo; 
 * Define macro to put error messages in flash memory
#define error(msg) error_P(PSTR(msg))

// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);

//////////////////////////////////// SETUP
void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
  putstring_nl("\nWave test!");  // say we woke up!
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad

  //  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!)  
    error("Card init. failed!");  // Something went wrong, lets print out why
  // enable optimize read - some cards may timeout. Disable if you're having problems
  // 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  :(
    error("No valid FAT partition!");  // Something went wrong, lets print out why
  // 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)) {
    error("Can't open root dir!");      // Something went wrong,
  // Whew! We got past the tough parts.
  putstring_nl("Files found (* = fragmented):");

  // Print out all of the files in all the directories. | LS_FLAG_FRAGMENTED);

//////////////////////////////////// LOOP
void loop() {
	Serial.print("Looping started ********************************************");
	  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration, inches, cm;

  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  digitalWrite(trigPin, HIGH);
  digitalWrite(trigPin, LOW);
	  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  Serial.print("in, ");
  if (cm < 30 && cm != 0)

 Serial.print("Playing sound ###################################");

/////////////////////////////////// HELPERS
 * print error message and halt
void error_P(const char *str) {
  PgmPrint("Error: ");
 * print error message and halt if SD I/O error, great for debugging!
void sdErrorCheck(void) {
  if (!card.errorCode()) return;
  PgmPrint("\r\nSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  PgmPrint(", ");
  Serial.println(card.errorData(), HEX);
 * play recursively - possible stack overflow if subdirectories too nested
void play(FatReader &dir) {
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
    // Skip it if not a subdirectory and not a .WAV file
    if (!DIR_IS_SUBDIR(dirBuf)
         && strncmp_P((char *)&[8], PSTR("WAV"), 3)) {

    Serial.println();            // clear out a new line
    for (uint8_t i = 0; i < dirLevel; i++) {
       Serial.write(' ');       // this is for prettyprinting, put spaces in front
    if (!, dirBuf)) {        // open the file in the directory
      error(" failed");          // something went wrong
    if (file.isDir()) {                   // check if we opened a new directory
      putstring("Subdir: ");
      dirLevel += 2;                      // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;    
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing ");
      printEntryName(dirBuf);              // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
        Serial.println();                  // Hooray it IS a WAV proper!;                       // make some noise!
        uint8_t n = 0;
        while (wave.isplaying) {// playing occurs in interrupts, so we print dots in realtime
          if (!(++n % 32))Serial.println();
        sdErrorCheck();                    // everything OK?
        // if (wave.errors)Serial.println(wave.errors);     // wave decoding errors

long microsecondsToInches(long microseconds)
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See:
  return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
Find it on Codebender here. Step 4:  Assemble the LED and sound board together. Found some scary sound and add it to the sound board. The final assembly should look something similar.
  Step 5: With the electronics been set, you need to find out a way (DIY) to setup the skull. Insert the LEDs and make sure it has a base to rotate. We literally tried various bottles and boxes to find the right base to make it work. [embed][/embed]   And finally we succeed. Here is how the final product looks like:
IMG_0322 copy