Arduino Jazz Improviser

573

12

2

Published

Introduction: Arduino Jazz Improviser

About: I go by millerman4487, and I am here to share what I make. Hopefully, you can learn from watching what I have done and even improve upon it. So here you go! If you have any ideas for future projects, send...

This design does not play a "song." Instead, it uses a blues scale to create its own music while it plays - similar to a real jazz musician. Every time you turn it on it will play something different; but you can still control the tempo, pitch, and volume with the dials. Hear an example of it playing below:

Step 1: What Is Jazz?

If you want the official definition, you can look at these links, but I think the best way to describe it is just to show you what it sounds like.

Step 2: Build the Circuit

I built a stand for my speaker out of drinking straws and tape, but that is optional. Follow the diagram to build the rest of this design.

Step 3: Upload the Code

This code follows a pseudo-random algorithm to infinitely play the notes of the Bb blues scale in a jazzy syncopated rhythm.

Use this code in the Arduino IDE:

int note = 1;
int note2 = 1;

void setup() {
  pinMode(3, OUTPUT);
}

void loop() {
  int tonecontrol = map(analogRead(A0), 0, 1023, 1, 4);
  int speedcontrol = map(analogRead(A1), 0, 1023, 1, 20);
  int tonecontrol2 = map(analogRead(A2), 0, 1023, 1, 4);

  int playnote;
  int switchval = random(1, 5);

  switch (switchval) {
    case 1:
      note = note;
      break;
    case 2:
      note = note + 1;
      break;
    case 3:
      note = note - 1;
      break;
    case 4:
      note = note + 2;
      break;
    case 5:
      note = note - 2;
      break;
  }

  switch (note) {
    case 1:
      playnote = 262;
      break;
    case 2:
      playnote = 294;
      break;
    case 3:
      playnote = 311;
      break;
    case 4:
      playnote = 349;
      break;
    case 5:
      playnote = 392;
      break;
    case 6:
      playnote = 440;
      break;
    case 7:
      playnote = 466;
      break;
    case 8:
      playnote = 523;
      break;
    default:
      note = 1;
      break;
  }

  playnote = playnote * tonecontrol;

  int playnote2;
  int switchval2 = random(1, 5);

  switch (switchval2) {
    case 1:
      note2 = note2;
      break;
    case 2:
      note2 = note2 + 1;
      break;
    case 3:
      note2 = note2 - 1;
      break;
    case 4:
      note2 = note2 + 2;
      break;
    case 5:
      note2 = note2 - 2;
      break;
  }

  switch (note2) {
    case 1:
      playnote2 = 262;
      break;
    case 2:
      playnote2 = 294;
      break;
    case 3:
      playnote2 = 311;
      break;
    case 4:
      playnote2 = 349;
      break;
    case 5:
      playnote2 = 392;
      break;
    case 6:
      playnote2 = 440;
      break;
    case 7:
      playnote2 = 466;
      break;
    case 8:
      playnote2 = 523;
      break;
    default:
      note2 = 1;
      break;
  }

  playnote2 = playnote2 * tonecontrol2;

  tone(3, playnote, 30 * speedcontrol);
  delay(31 * speedcontrol);
  if (random(1, 4) == 3) {
    delay(21 * speedcontrol);
  }
  else {
    tone(3, playnote2, 20 * speedcontrol);
    delay(21 * speedcontrol);
  }
}

Step 4: How to Control It

From left to right, each dial does as follows:

  • Volume
  • 1st tone's pitch
  • Tempo
  • 2nd tone's pitch

Mess around with them until you get a sound you like.

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Clocks Contest

      Clocks Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    2 Discussions

    Very cool. Would love to see a video, or did I miss it somewhere?

    1 reply

    There is no video but I added an audio recording to the introduction.