H2OhNo!

This Tutorial is Retired!

This tutorial covers concepts or technologies that are no longer current. It's still here for you to read and enjoy, but may not be as useful as our newest tutorials.

Pages
Contributors: Nate
Favorited Favorite 6

Blink and Annoy

Now that you've got your programmer setup and working we can load fun new code onto the H2OhNo!.

Basic Blink Firmware

Basic Blink demonstrates how to blink the LED and make some noise. It's a great starting point. Copy and paste this code into the Arduino IDE, and reprogram your ATtiny.

language:c
//Pin definitions for ATtiny
const byte buzzer1 = 0;
const byte buzzer2 = 1;
const byte statLED = 4;

void setup()
{
  pinMode(buzzer1, OUTPUT);
  pinMode(buzzer2, OUTPUT);
  pinMode(statLED, OUTPUT);
}

void loop() 
{
  digitalWrite(statLED, HIGH);
  alarmSound();
  delay(1000);

  digitalWrite(statLED, LOW);
  alarmSound();
  delay(1000);
}

//This is just a unique (annoying) sound we came up with, there is no magic to it
//Comes from the Simon Says game/kit actually: https://www.sparkfun.com/products/10547
//250us to 79us
void alarmSound(void)
{
  // Toggle the buzzer at various speeds
  for (byte x = 250 ; x > 70 ; x--)
  {
    for (byte y = 0 ; y < 3 ; y++)
    {
      digitalWrite(buzzer2, HIGH);
      digitalWrite(buzzer1, LOW);
      delayMicroseconds(x);

      digitalWrite(buzzer2, LOW);
      digitalWrite(buzzer1, HIGH);
      delayMicroseconds(x);
    }
  }
}

Original H2OhNo! Firmware

If you're reprogramming the ATtiny you may want to get back to the original code that shipped with the kit. Grab the latest code by going to the H2OhNo! github repo. Click 'raw', then copy and paste the code into Arduino.

Annoy-A-Tron Firmware

We know you will eventually come across the idea of an Annoy-a-tron. The original Annoy-A-Tron was created by Think Geek, and everyone knows how annoying a low-battery beep of a fire alarm can be. This is a very basic Annoy-A-Tron example that will beep every 5 minutes. We intentionally didn't build in low-power control so that if you happen to use this code you will only annoy your enemy for a few hours before the coin cell battery gives out.

language:c
//Pin definitions for ATtiny
const byte buzzer1 = 0;
const byte buzzer2 = 1;

void setup()
{
  pinMode(buzzer1, OUTPUT);
  pinMode(buzzer2, OUTPUT);
}

void loop() 
{
  alarmSound();

  delay((long)1000 * 60 * 5); //5 minute delay
}

//This is just a unique (annoying) sound we came up with, there is no magic to it
//Comes from the Simon Says game/kit actually: https://www.sparkfun.com/products/10547
//250us to 79us
void alarmSound(void)
{
  // Toggle the buzzer at various speeds
  for (byte x = 250 ; x > 70 ; x--) 
  {
    //for (byte y = 0 ; y < 3 ; y++)
    for (byte y = 0 ; y < 1 ; y++) //Slightly modified to be a shorter beep
    {
      digitalWrite(buzzer2, HIGH);
      digitalWrite(buzzer1, LOW);
      delayMicroseconds(x);

      digitalWrite(buzzer2, LOW);
      digitalWrite(buzzer1, HIGH);
      delayMicroseconds(x);
    }
  }
}

A very broken H2OhNo board

This is what happened to an Annoy-A-Tron after it was discovered by the victim. The board met its end in the jaws of a vice with a pipewrench and a cheater pipe extension. Please annoy responsibly.

Creating projects to prank people is a fantastic way to learn electronics! Annoying them with incessant beeping is an ok start, but consider getting a lot more creative with your pranks.