touchmysound
Published © CC BY-NC-SA

Self-Playing Melodica 🤖🎹

Turn your melodica into a compressed-air melodica controlled by Max and Arduino. It tries to follow the melodic contour it listens to!

AdvancedFull instructions provided16 hours5,100

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×2
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
×2
60W PCIe 12V 5A Power Supply
Digilent 60W PCIe 12V 5A Power Supply
×1
Voltage regulator, step-down, 12V in, 3.6V out
×1
Bistable electrovalve (solenoid)
×1
DC Motor, 12 V
DC Motor, 12 V
×1

Software apps and online services

Arduino IDE
Arduino IDE
MAX
Cycling '74 MAX

Story

Read more

Schematics

Schematics

Robot melodica with control for a DC motor and an electrovalve for airflow.

Schematics (Fritzing file)

It's only the schematics in case you want to mess with it, nevermind the PCB and breadboard section!

Code

Final code for the Arduino

Arduino
This works with numbers sent via serial: 0, 1, 2; 100, 101, 102; 200, 201, 202. Refer to the text for more info.
const int ledPin = 13;
#define enA 9
#define in1 6
#define in2 5
#define endStopR A0
#define endStopL A1

#define air1  10
#define air2  11



int stateR = 0;
int stateL = 0;

void setup() {
  Serial.begin(9600); // open a serial connection to your computer
  pinMode(ledPin, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);

  pinMode(endStopR, INPUT);
  pinMode(endStopL, INPUT);

  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(enA, HIGH);
}

void loop() {

  stateR = digitalRead (endStopR);
  stateL = digitalRead (endStopL);

  if (stateR == HIGH) {
    Serial.print("Endstop activated:");
    Serial.print("\t");
    Serial.println("RIGHT");

    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);

    stateR = LOW;

    delay(500);

    digitalWrite(in1, LOW);
  }

  if (stateL == HIGH) {
    Serial.print("Endstop activated:");
    Serial.print("\t");
    Serial.println("LEFT");

    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);

    stateL = LOW;

    delay(500);

    digitalWrite(in2, LOW);
  }


  if (Serial.available()) {

    byte    airMov = Serial.read();  //airMov che è 1, 0 o 2 ma ha anche +100 se airflow è attivo
    Serial.print("command");
    Serial.print("\t");
    Serial.println(airMov);
    byte mov = 0;

    if (airMov > 150) {
      mov = airMov - 200;
      digitalWrite(air1, HIGH);
      digitalWrite(air2, LOW);
    }

    if (airMov > 50 && airMov < 150) {
      mov = airMov - 100;
      digitalWrite(air1, LOW);
      digitalWrite(air2, HIGH);
    }


    if (airMov < 50) {
      mov = airMov;
      digitalWrite(air1, LOW);
      digitalWrite(air2, LOW);
    }





    if (mov == 0) {
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(ledPin, LOW);
    }
    else



      if (mov == 2) {
        digitalWrite(in1, LOW);
        digitalWrite(in2, HIGH);
        digitalWrite(ledPin, HIGH);
      }

      else if (mov == 1) {
        digitalWrite(in1, LOW);
        digitalWrite(in2, LOW);
        digitalWrite(ledPin, HIGH);
      }
  }


}

Credits

touchmysound

touchmysound

6 projects • 44 followers
Alessandro Perini's artistic production ranges from audiovisual and light-based works to net-art, land-art and vibration-based works.

Comments