Project: The Arduino DJ Console
Assignment Description
For this assignment, we were tasked with designing and building a musical instrument using Arduino. The requirements were simple: the project had to include at least one digital sensor (such as a switch) and one analog sensor.
What We Built
Working with Bigo, we created a DJ-style sound console powered by an Arduino. This instrument enables users to experiment with sound by adjusting pitch and speed, providing a substantial amount of room for creativity.
Our setup included:
-
Two Potentiometers (Analog Sensors):
One knob changes the pitch of the note, and the other controls the duration (speed). -
One Button (Digital Sensor):
This serves as a mute button, instantly silencing the sound. -
Piezo Buzzer:
The component responsible for producing the tones.
Schematic
The circuit uses analog pins A0 and A5 for the two knobs and digital pin 13 for the pushbutton.
The buzzer is connected to pin 9.
Video Demonstration
Code
We wrote code to read the sensors and play notes from a C Major scale. Here is the source code for the project:
C++
// Control a buzzer with two knobs and a button
// Define hardware pins
const int piezoPin = 9;
const int pitchPotPin = A0;
const int durationPotPin = A5;
const int buttonPin = 13;
// List of frequencies for C Major scale
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};
void setup() {
// Start data connection to computer
Serial.begin(9600);
Serial.println("Instrument Ready! Note Stepping Enabled.");
// Set pin modes
pinMode(piezoPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Check if the button is pressed
int buttonState = digitalRead(buttonPin);
// Mute sound if button is held down
if (buttonState == LOW) {
noTone(piezoPin);
} else {
// Read values from both knobs
int pitchValue = analogRead(pitchPotPin);
int durationValue = analogRead(durationPotPin);
// Convert pitch knob value to a note index from 0 to 7
int noteIndex = map(pitchValue, 0, 1023, 0, 7);
// Select the frequency from the list
int frequency = notes[noteIndex];
// Convert duration knob value to time in milliseconds
int noteDuration = map(durationValue, 0, 1023, 50, 500);
// Play the sound
tone(piezoPin, frequency, noteDuration);
// Show information on the screen
Serial.print("Note Index: ");
Serial.print(noteIndex);
Serial.print(" | Frequency: ");
Serial.print(frequency);
Serial.print(" Hz | Duration: ");
Serial.print(noteDuration);
Serial.println(" ms");
// Wait for the note to finish
delay(noteDuration + 50);
}
}

