Week 9: Creating an Instrument

As a singer, one of the things I struggle with is finding nice harmonies, as I am really new at that. That’s what inspired me to create an instrument where you can pick a note, and fine the Soprano, Alto, Tenor, and Bass notes for it.

I decided to go for a range of notes that was close to my vocal range, so I went for 15 notes, from D3 to A5. I set up 4 buttons, one resembling each note, soprano being the original melody. The goal was to use the Potentiometer to pick a note, listen to it with the red button (soprano), and then find the 4 part harmony with the other buttons. In the end I should be able to press all four, and hear the harmony.

I mapped the analogue to match the notes I wanted to use, and each button just jumped a few notes from the original, to be a harmony. I only went through a few hours of debugging and creating this, but when I finished I encountered an obstacle i didn’t know how to fix. My sound was very muffled. When I would only have 1 button in use in the code, the sound would be fine. When I tried the code one button at a time, each button worked perfectly. But when I put it together, the sound sounded muffled, laggy, and muddy. The notes also didn’t come outright. At first I realised i had the resistor in the wrong place in some buttons, so when I fixed that it helped, but the issue didnt seem to go away anymore. Im not sure if this is an issue with the button being so small, or not.

#include "pitches.h"
int knob = A0;
int soprano = 11;
int alto = 10;
int tenor = 9;
int bass = 8;

int notes [15] = {NOTE_D3 , NOTE_E3 , NOTE_F3 , NOTE_G3 , NOTE_A4 , NOTE_B4 , NOTE_C4 , NOTE_D4 , NOTE_E4 , NOTE_F4 , NOTE_G4 , NOTE_A5};
//int whichNote = 0;

void setup() {
  pinMode(soprano, INPUT);
  pinMode(alto, INPUT);
  pinMode(tenor, INPUT);
  pinMode(bass, INPUT);
  // put your setup code here, to run once:

void loop() {

// put your main code here, to run repeatedly:
int knobValue = analogRead(knob);
int sopranoState = digitalRead(soprano);
int altoState = digitalRead(alto);
int tenorState = digitalRead(tenor);
int bassState = digitalRead(bass);
Serial.println (sopranoState);

//mapping the potentiometer values from 0 - 800 for easy reference
int mappedValue =  map(knobValue, 0, 1023, 0, 15);
if (sopranoState == HIGH) {
  tone(4, notes[mappedValue]);
  } else {
    tone(4, 0);
if (altoState == HIGH) {
  tone(4, notes[(mappedValue -2 )]);
  } else {
    tone(4, 0);
if (tenorState == HIGH) {
  tone(4, notes[(mappedValue- 6)]);
  } else {
    tone(4, 0);
if (bassState == HIGH) {
  tone(4, notes[(mappedValue- 8)]);
  } else {
    tone(4, 0);

Each one on its own:

All together:

One thought on “Week 9: Creating an Instrument”

  1. Great to see you’re trying to do harmony. Unfortunately, you can’t do more than one tone properly at the same time with one buzzer. That’s why it ended up sounding weird. No fault of your own!

Leave a Reply