viliamk
Published © GPL3+

Play a melody by notes sent from a phone

Plays a text of notes sent from a phone to arduino through bluetooth

BeginnerProtip799
Play a melody by notes sent from a phone

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Speaker: 3W, 4 ohms
Speaker: 3W, 4 ohms
×1
Rotary Potentiometer, 10 kohm
Rotary Potentiometer, 10 kohm
×1
Toggle Switch, Toggle
Toggle Switch, Toggle
×1

Software apps and online services

MIT App Inventor 2
MIT App Inventor 2

Story

Read more

Schematics

Circuit diagram

Code

Playing a melody sent from a phone

Arduino
int note[110]; 
int micpin = 11;  //speaker
char BTData; //data from my phone
int oct = 1; //octave
int race = 200;  //speed of playing

void setup() {
    Serial.begin(9600);
    pinMode(micpin, OUTPUT);
    note['c'] = 247;    //ces = H
    note['C'] = 262;    //C
    note['d'] = 277;    //des = cis
    note['D'] = 294;    //D
    note['e'] = 311;    //es = dis
    note['E'] = 330;    //E
    note['f'] = 330;    //fes = E
    note['F'] = 349;    //F
    note['g'] = 370;    //ges = fis
    note['G'] = 392;    //G
    note['a'] = 415;    //as = gis
    note['A'] = 440;    //A
    note['h'] = 466;    //b = ais
    note['H'] = 494;    //H
}

void loop() {
  delay(5);
  
  if (Serial.available()){
      BTDataCases();
   }
}

void BTDataCases() {
      BTData = Serial.read();
      Serial.println(BTData);

      switch(BTData) {
        case '2':
          oct = 1;
          break;
        case '3':
          oct = 2;
          break;
        case '4':
          oct = 4;
          break;
        case '5':
          oct = 8;
          break;
        case '9':
          race += 20;
          break;          
        case '8':
          race -= 20;
          if (race < 20) race = 20;
          break;
        default:
          tone(micpin, note[BTData] * oct, race);
          delay(race + 100);
        }
     }

Credits

viliamk
14 projects • 5 followers

Comments