Build this project with

The Amazing Annoyatron

Shop now
The Amazing Annoyatron is an award-winning tech kit that teaches kids how to code.

Parts & wiring

This dubious invention is sure to drive its victims absolutely bonkers, 100% guaranteed. When assembled and programmed, this will let off random beeps at random times that go for a random length. In fact, there’s not really anything about this project that isn’t random. Or annoying.

What you’ll need for this project

To build this project, you will be using the following components:

UNO R3 Board & USB Cable
UNO R3 Board & USB Cable
Buzzer
Piezo Buzzer

How to connect the parts

To wire up this project, you’ll need your UNO R3 board, USB cable, buzzer and ultrasonic sensor. To connect your buzzer, slide its pins into the Arduino board as shown – the positive leg should go in PIN 11 and the negative leg should go in GND. For the ultrasonic sensor, we will only be using 4 of its 5 pins in this project. Connect its ‘Vcc’ pin to 5V on the board, its ‘Trig’ to PIN 7, ‘Echo’ to PIN 6, and ‘GND’ to GND on the Arduino.

Hover over the PLUS signs for extra tips
This is the positive leg of the buzzer. It will have a ‘+’ sign on top of it and will also be longer than the other leg.
Don’t forget to plug the board into your computer with the included USB cable.

The final program

Here’s the code we’ll be using to program this invention.
int buzzer = 11;

void setup() {
  // put your setup code here, to run once:
  pinMode(buzzer, OUTPUT);
}

void loop() {
  for(int i = random(1, 8); i > 0; i = i - random(1,25)) {
    tone(buzzer, random(50, 1000), random(1, 1000));
    delay(random(50, 500));
    tone(buzzer, random(500, 10000), random(1, 500));
    delay(random(50, 500));
  }
  delay(random(1000, 25000));
}

I want to change. . .

The randomness of everything

Make this more awesome

Learn how to modify the code

Change the randomness of everything

While everything in this program is very random, there are still ways that we can control this randomness. Take a look at line 15 in the code, for example, where a random delay is set in-between the noise bursts.

delay(random(1000, 25000));

What does this mean? Well, normally we set a delay like this: delay(time). The time is always in milliseconds. However, here we have random(1000, 25000) inside the brackets. Whaile this may look a bit complicated, all this code is really doing is generating a random number between 1000 and 25000, and this is how long the delay goes for.

If we wanted this delay to go for any time between 5 and 10 seconds, we would need to use the following code:

delay(random(5000, 10000));

Don’t forget that all these numbers are in milliseconds, and 1000 milliseconds = 1 second. But the delay on line 15 isn’t the only place where you can change this random() thing. Take a look at the rest of the code and see what you can change. . .