This dubious invention is sure to drive its victims absolutely bonkers, 100% guaranteed. When assembled and coded, this will let off random beeps at random times that go for a random length.
Parts list
What you’ll need
Step 1
Let’s build this
This is the positive leg of the buzzer. It will have a ‘+’ over top and will also be longer than the other leg.
Don’t forget to plug the board into your computer with the supplied USB cable.
Connections
Buzzer
The +LEG is the longer leg.
Step 2
Code some chaos
Don’t forget to select your port, like usual
Copy and paste the sample code
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));
}
Upload the code and test it out
Step 3
Modify the madness
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. While 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!