Arduino Jazz Improviser

by millerman4487 in Circuits > Arduino

1368 Views, 14 Favorites, 0 Comments

Arduino Jazz Improviser

IMG_20171210_151252738-01.jpeg

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:

What Is Jazz?

piano jazz improvisation

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.

Build the Circuit

Untitled Sketch_bb.png
IMG_20171210_151654133-01.jpeg
IMG_20171210_151734654-01.jpeg
IMG_20171210_151752340-01.jpeg
IMG_20171210_151635684-01.jpeg

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.

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);
  }
}

How to Control It

IMG_20171210_151635684-01.jpeg

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.