Arduino Annoyatron

Hi guys,

Got my arduino today and I already absolutely love the thing!
To start it off I implemented ThinkGeeks annoyatron. Because this is my first post, I cant post the link to the annoyatron but google ThinkGeek annoyatron to see what I’m talking about.

Simply hook up a buzzer to pin 13, hide it somewhere and cause mayhem!

// Time is specified in minutes
#define MINTIME 2
#define MAXTIME 8
#define BUZZERPIN 13
#define FREQUENCY1 2000
#define FREQUENCY2 12000
void setup() {

void loop()
   int duration = random(MINTIME*60,MAXTIME*60);
   for(int i = 0; i < duration; i++)
     delay(1000); // Wait 1 second
   buzz(BUZZERPIN, randomFrequency(), 1000);

int randomFrequency()
  if(random(0,9) < 5) {
    return FREQUENCY1;
  else {
    return FREQUENCY2;
// Credit to Rob Faludi for the code below
void buzz(int targetPin, long frequency, long length) {
  long delayValue = 1000000/frequency/2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to 
  //// get the total number of cycles to produce
 for (long i=0; i < numCycles; i++){ // for the calculated length of time...
    digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait againf or the calculated delay value

Is a link to see what I'm talking about.

you can add a photoresistor for buzz him just when lights are off eheheh :D

Hehe I just made one of these for my family :P. Should be interesting... ;D!