Introduction: Arduino Noise Machine

I found a tiny speaker while tearing down an old P.C. for recycling and thought I'd see what it sounded like using the Arduino Tone() function. I began with one 10Ω potentiometer to control the pitch and started making some noise. The Tone() function uses a simple pulse pattern. It turns the sound on and off at different frequencies in a square wave-pattern. I had two other potentiometers lying around so I added them and used them to control the tone duration. One to control the length of the tone and one to control the silent space in between the tones. It's basically using another square wave-pattern but at a much lower frequency. You can achieve a good variety of noise with this circuit. It works well with a piezo buzzer too, but lacks the bass response of a speaker.

Step 1: Parts You Will Need

Arduino Uno

Breadboard and jumper wires

1 Small speaker or Piezo buzzer

1 Pushbutton switch

3 10Ω Potentiometers

1 22Ω resistor

1 10kΩ resistor

Step 2: Build the Circuit

Connect the breadboard to your Arduino 5V pin and GND. Place the Pushbutton switch on the far right or left of the breadboard and connect it to 5V and ground using the 10kΩ resistor. Connect a wire from the switch circuit to pin 2 on your Arduino.

On the other side of the breadboard set up the speaker/piezo circuit to 5v and ground using the 220Ω resistor. This resistor controls the current thus controling the volume; you can try different resistors here for higher or lower volume.

Arrange your potentiometers in the center of the breadboard giving enough space to fiddle with the knobs. Each pot will need to be connected to 5V and ground and the center pins on each connected to analog pins A0, A1 and A2

Step 3: The Code

A potentiometer or pot is a variable resistor which when connected to an Arduino will return a value between 0 and 1023. We will use the map() function to change these values to suit our own needs. The map() function takes five arguments and in our case we need to re-map the range to between 220 and 2200 to produce a reasonable audible sound.

The function looks something like this:

map(pot, 0,1023, 220,2200); 

You can play around with the last two values for higher and lower frequency tones, just be careful you don't upset your dog.

Noise_Machine.ino

/* Noise machine using three potentiometers connected to analog inputs
and a piezo or small speaker. A pushbutton turns on the noise, the potentiometers
control the pitch using the Arduino tone() function, and two delay
values which control the length of each tone and length between
each tone. The potentiometers give analog values which are changed
using the map() function into larger or smaller ranges to suit your
musical tastes.
This code is in the public domain.
Matt Thomas 05/04/2019
*/
constint buttonPin = 2; // Pushbutton pin 2
constint speaker = 9; // Speaker or piezo in pin 9
int buttonState = 0; // Variables for the button
int potZero; // and potentiometers
int potOne;
int potTwo;
voidsetup() {
pinMode(9, OUTPUT); // Speaker/piezo output pin
}
voidloop() {
buttonState = digitalRead(buttonPin); // Read the pushbutton state
potZero = analogRead(A0); //Variables for reading the analog values
potOne = analogRead(A1);
potTwo = analogRead(A2);
int htz = map(potZero, 0,1023, 0,8800); // Map the analog readings into
int high = map(potOne, 0,1023, 0,100); // new number ranges and create
int low = map(potTwo, 0,1023, 0,100); // new variables
if (buttonState == HIGH) { // If the pushbutton is pressed...
tone(speaker, htz); // Sound on
delay(high); // Length of tone
noTone(speaker); // Sound off
delay(low); // Time until next tone
} else {
noTone(speaker); // No tone if the button is released
}
}

Step 4: The End

So that's all there is to it. Play around with the values in the code, add more pots /buttons and see what else you can control. Let me know if I've made any mistakes and I hope you enjoy the music.