Pular para o conteúdo principal

Previsão do tempo

Feliz, RS
Utilize o menu lateral para navegar pelos projetos criados

[OUTROS] Arduino Musical


Objetivo:

Criar um projeto de Arduíno musical. Este projeto irá fazer com que o Arduíno reproduza frequências sonoras através de um buzzer, com o uso de um teclado matricial 4x3 será possível tocar notas musicais e selecionar as musicas pantera cor de rosa, ode a alegria e parabéns a você para serem reproduzidas.

Componentes necessários:
*1 teclado matricial 4x3;
*7 fios jumper macho-macho;
*1 buzzer;
*2 fios jumper macho-fêmea;
*um cabo USB;
*um computador com a IDE do Arduíno instalada;
*Arduíno MEGA 2560.

Um buzzer é componente eletrônico que emite sons geralmente em uma frequência fixa, acima do buzzer deverá ter uma indicação informando qual é a polaridade do mesmo

O teclado matricial possui 7 pinos sendo os 4 primeiros da esquerda para a direita, os pinos referentes as linhas do teclado, e os últimos 3 referentes as colunas do teclado.

Montagem do Circuito:
Conecte os componentes no Arduíno como mostra a figura abaixo. Verifique cuidadosamente os cabos de ligação antes de ligar seu Arduíno. Lembre-se que o Arduíno deve estar totalmente desconectado da força enquanto você monta o circuito.

(Buzzer: fio preto GND, vermelho digital 11)
(Teclado: vermelho digital 23, laranja digital 25, amarelo digital 27, verde digital 39, azul digital 31, roxo digital 33, preto digital 35 )

referencias:



Baixe o código do sistema: arduinomusical.ino
ou
Copie o código do sistema:


#define NOTE_B0  31
#define NOTE_C1  33
#define NOTE_CS1 35
#define NOTE_D1  37
#define NOTE_DS1 39
#define NOTE_E1  41
#define NOTE_F1  44
#define NOTE_FS1 46
#define NOTE_G1  49
#define NOTE_GS1 52
#define NOTE_A1  55
#define NOTE_AS1 58
#define NOTE_B1  62
#define NOTE_C2  65
#define NOTE_CS2 69
#define NOTE_D2  73
#define NOTE_DS2 78
#define NOTE_E2  82
#define NOTE_F2  87
#define NOTE_FS2 93
#define NOTE_G2  98
#define NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978
#define REST      0

int pinLinhas[] = {23, 25, 27, 29};
int pinColunas[] = {31, 33, 35};
//pino do buzzer
const int buzzer = 11;

char teclas[4][3] = {{'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

void setup() {
  pinMode(buzzer, OUTPUT);
  for (int numeroLinhas = 0; numeroLinhas < 4; numeroLinhas++) {
    pinMode(pinLinhas[numeroLinhas], OUTPUT);
    digitalWrite(pinLinhas[numeroLinhas], HIGH);
  }
  for (int numeroColunas = 0; numeroColunas < 3; numeroColunas++) {
    pinMode(pinColunas[numeroColunas], INPUT_PULLUP);
  }
  Serial.begin(9600);

}

void loop() {

  for (int numeroLinhas = 0; numeroLinhas < 4; numeroLinhas++) {
    digitalWrite(pinLinhas[numeroLinhas], LOW);
    for (int numeroColunas = 0; numeroColunas < 3; numeroColunas++) {
      if (digitalRead(pinColunas[numeroColunas]) == LOW) {

        if (teclas[numeroLinhas][numeroColunas] == '1') {
          tone(buzzer, 783);
        }
        if (teclas[numeroLinhas][numeroColunas] == '2') {
          tone(buzzer, 880);
        }
        if (teclas[numeroLinhas][numeroColunas] == '3') {
          tone(buzzer, 987);
        }
        if (teclas[numeroLinhas][numeroColunas] == '4') {
          tone(buzzer, 1046);
        }
        if (teclas[numeroLinhas][numeroColunas] == '5') {
          tone(buzzer, 1174);
        }
        if (teclas[numeroLinhas][numeroColunas] == '6') {
          tone(buzzer, 1318);
        }
        if (teclas[numeroLinhas][numeroColunas] == '7') {
          tone(buzzer, 1396);
        }
        if (teclas[numeroLinhas][numeroColunas] == '8') {
          tone(buzzer, 1567);
        }
        if (teclas[numeroLinhas][numeroColunas] == '9') {
          tone(buzzer, 1760);
        }
        if (teclas[numeroLinhas][numeroColunas] == '*') {
          digitalWrite(pinLinhas[4], LOW);
          int tempo = 120;
          int melody[] = {
            REST, 2, REST, 4, REST, 8, NOTE_DS4, 8,
            NOTE_E4, -4, REST, 8, NOTE_FS4, 8, NOTE_G4, -4, REST, 8, NOTE_DS4, 8,
            NOTE_E4, -8, NOTE_FS4, 8,  NOTE_G4, -8, NOTE_C5, 8, NOTE_B4, -8, NOTE_E4, 8, NOTE_G4, -8, NOTE_B4, 8,
            NOTE_AS4, 2, NOTE_A4, -16, NOTE_G4, -16, NOTE_E4, -16, NOTE_D4, -16,
            NOTE_E4, 2, REST, 4, REST, 8, NOTE_DS4, 4,

            NOTE_E4, -4, REST, 8, NOTE_FS4, 8, NOTE_G4, -4, REST, 8, NOTE_DS4, 8,
            NOTE_E4, -8, NOTE_FS4, 8,  NOTE_G4, -8, NOTE_C5, 8, NOTE_B4, -8, NOTE_G4, 8, NOTE_B4, -8, NOTE_E5, 8,
            NOTE_DS5, 1,
            NOTE_D5, 2, REST, 4, REST, 8, NOTE_DS4, 8,
            NOTE_E4, -4, REST, 8, NOTE_FS4, 8, NOTE_G4, -4, REST, 8, NOTE_DS4, 8,
            NOTE_E4, -8, NOTE_FS4, 8,  NOTE_G4, -8, NOTE_C5, 8, NOTE_B4, -8, NOTE_E4, 8, NOTE_G4, -8, NOTE_B4, 8,

            NOTE_AS4, 2, NOTE_A4, -16, NOTE_G4, -16, NOTE_E4, -16, NOTE_D4, -16,
            NOTE_E4, -4, REST, 4,
            REST, 4, NOTE_E5, -8, NOTE_D5, 8, NOTE_B4, -8, NOTE_A4, 8, NOTE_G4, -8, NOTE_E4, -8,
            NOTE_AS4, 16, NOTE_A4, -8, NOTE_AS4, 16, NOTE_A4, -8, NOTE_AS4, 16, NOTE_A4, -8, NOTE_AS4, 16, NOTE_A4, -8,
            NOTE_G4, -16, NOTE_E4, -16, NOTE_D4, -16, NOTE_E4, 16, NOTE_E4, 16, NOTE_E4, 2,
          };

          int notes = sizeof(melody) / sizeof(melody[0]) / 2;
          int wholenote = (60000 * 4) / tempo;
          int divider = 0, noteDuration = 0;
          for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

            divider = melody[thisNote + 1];
            if (divider > 0) {
              noteDuration = (wholenote) / divider;
            } else if (divider < 0) {
              noteDuration = (wholenote) / abs(divider);
              noteDuration *= 1.5;
            }

            tone(buzzer, melody[thisNote], noteDuration * 0.9);
            delay(noteDuration);
            noTone(buzzer);
            if (digitalRead(pinColunas[0]) == LOW) {
              break;
            }
          }
        }

        if (teclas[numeroLinhas][numeroColunas] == '#') {
          digitalWrite(pinLinhas[4], LOW);
          int tempo = 140;
          int melody[] = {
            REST, 2,
            NOTE_C4, 4, NOTE_C4, 8,
            NOTE_D4, -4, NOTE_C4, -4, NOTE_F4, -4,
            NOTE_E4, -2, NOTE_C4, 4, NOTE_C4, 8,
            NOTE_D4, -4, NOTE_C4, -4, NOTE_G4, -4,
            NOTE_F4, -2, NOTE_C4, 4, NOTE_C4, 8,

            NOTE_C5, -4, NOTE_A4, -4, NOTE_F4, -4,
            NOTE_E4, -4, NOTE_D4, -4, NOTE_AS4, 4, NOTE_AS4, 8,
            NOTE_A4, -4, NOTE_F4, -4, NOTE_G4, -4,
            NOTE_F4, -2,

          };

          int notes = sizeof(melody) / sizeof(melody[0]) / 2;
          int wholenote = (60000 * 4) / tempo;
          int divider = 0, noteDuration = 0;

          for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
            divider = melody[thisNote + 1];
            if (divider > 0) {
              noteDuration = (wholenote) / divider;
            } else if (divider < 0) {
              noteDuration = (wholenote) / abs(divider);
              noteDuration *= 1.5;
            }

            tone(buzzer, melody[thisNote], noteDuration * 0.9);
            delay(noteDuration);
            noTone(buzzer);
            if (digitalRead(pinColunas[2]) == LOW) {
              break;
            }
          }
        }

        if (teclas[numeroLinhas][numeroColunas] == '0') {
          digitalWrite(pinLinhas[4], LOW);
          int tempo = 114;
          int melody[] = {
            REST, 2,
            NOTE_E4, 4,  NOTE_E4, 4,  NOTE_F4, 4,  NOTE_G4, 4, //1
            NOTE_G4, 4,  NOTE_F4, 4,  NOTE_E4, 4,  NOTE_D4, 4,
            NOTE_C4, 4,  NOTE_C4, 4,  NOTE_D4, 4,  NOTE_E4, 4,
            NOTE_E4, -4, NOTE_D4, 8,  NOTE_D4, 2,

            NOTE_E4, 4,  NOTE_E4, 4,  NOTE_F4, 4,  NOTE_G4, 4, //4
            NOTE_G4, 4,  NOTE_F4, 4,  NOTE_E4, 4,  NOTE_D4, 4,
            NOTE_C4, 4,  NOTE_C4, 4,  NOTE_D4, 4,  NOTE_E4, 4,
            NOTE_D4, -4,  NOTE_C4, 8,  NOTE_C4, 2,

            NOTE_D4, 4,  NOTE_D4, 4,  NOTE_E4, 4,  NOTE_C4, 4, //8
            NOTE_D4, 4,  NOTE_E4, 8,  NOTE_F4, 8,  NOTE_E4, 4, NOTE_C4, 4,
            NOTE_D4, 4,  NOTE_E4, 8,  NOTE_F4, 8,  NOTE_E4, 4, NOTE_D4, 4,
            NOTE_C4, 4,  NOTE_D4, 4,  NOTE_G3, 2,

            NOTE_E4, 4,  NOTE_E4, 4,  NOTE_F4, 4,  NOTE_G4, 4, //12
            NOTE_G4, 4,  NOTE_F4, 4,  NOTE_E4, 4,  NOTE_D4, 4,
            NOTE_C4, 4,  NOTE_C4, 4,  NOTE_D4, 4,  NOTE_E4, 4,
            NOTE_D4, -4,  NOTE_C4, 8,  NOTE_C4, 2
          };

          int notes = sizeof(melody) / sizeof(melody[0]) / 2;
          int wholenote = (60000 * 4) / tempo;
          int divider = 0, noteDuration = 0;
          for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {

            divider = melody[thisNote + 1];
            if (divider > 0) {
              noteDuration = (wholenote) / divider;
            } else if (divider < 0) {
              noteDuration = (wholenote) / abs(divider);
              noteDuration *= 1.5;
            }

            tone(buzzer, melody[thisNote], noteDuration * 0.9);
            delay(noteDuration);
            noTone(buzzer);
            if (digitalRead(pinColunas[1]) == LOW) {
              break;
            }
          }
        }
        while (digitalRead(pinColunas[numeroColunas]) == LOW) {
        }
        noTone(buzzer);

      }
    }
    digitalWrite(pinLinhas[numeroLinhas], HIGH);
  }
  delay(10);
}

Vídeo do sistema funcionando:
 

Postagens mais visitadas deste blog

Anemômetro

Objetivo: Criar um projeto Arduíno  para detecção da velocidade do vento horizontal. Componentes necessários: *Protoboard; *1 sensor reed switch; *Dois fios Jumper macho/macho e dois fio Jumper fêmea/macho; *Resistore de 10000 ohms; *Um cabo USB; *Um computador com a IDE do Arduino instalada; *Arduino MEGA 2560. *1 anemômetro- sensor de velocidade do vento; *Anemômetro Montagem do Circuito: Conecte os componentes no Protoboard como mostra a figura abaixo. Verifique cuidadosamente os cabos de ligação antes de ligar seu Arduino. Lembre-se que o Arduino deve estar totalmente desconectado da força enquanto você monta o circuito. A montagem física do referente projeto é extremamente simples já que trabalha com somente dois fios do anemômetro e um Arduino, o único detalhe que podemos destacar para a instalação é a utilização de um resistor em Pull Down conectado diretamente ao pino digital 2 do Arduino em um dos fios do sensor e uma fonte de energia...

Verificando e carregando códigos no Arduino

   Passo a passo de como verificar e carregar um código no arduino. Passo 1:  O Arduino usa como linguagem de programação C++, então você pode criar um código do zero utilizando C++ ou utilizar algum código pronto para a função designada. Então para saber se o Arduino entendeu o código colocado ele tem a opção “verificar” que verifica se o código está funcionando, para isso coloque o código na IDE do Arduino e clique no botão de verificar como na imagem: Obs: Estamos utilizando o código do LM35 como exemplo.     Passo 2 : Olhar a mensagem que o Arduino deu sobre a verificação do código, se tudo der certo ele irá mostrar uma mensagem assim:   Done Compiling( Compilação concluída). Se algo der errado ele irá mostrar alguma mensagem de erro que pode variar de acordo com o problema, como na imagem a seguir:   Passo 3: Se seu código não apresentou nenhum erro ele está pronto para ser carregado pelo Arduino, para carregar um código no Arduino você t...

Pluviômetro

Objetivo: Criar um projeto Arduíno  para detecção da quantidade de chuva em um determinado intervalo de tempo ou localidade. Componentes necessários: *Protoboard; *Quatro fios Jumper macho/macho e dois fio Jumper fêmea/macho; *Resistore de 10000 ohms; *Um cabo USB; *Um computador com a IDE do Arduino instalada; *Arduino MEGA 2560. *1 Pluviômetro de Báscula Digital Arduino para Estação Meteorológica; *Pluviômetro Montagem do Circuito: A montagem física do referente projeto é extremamente simples já que trabalha com somente dois fios do Pluviômetro de Báscula e um Arduino, o único detalhe que podemos destacar para a instalação é a utilização de um resistor em Pull Down conectado diretamente ao pino D9 do Arduino em conjunto com os demais pinos de alimentação. Verifique abaixo o esquema de ligação utilizado para conectar o equipamento junto ao Arduino e logo ao lado o esquema elétrico da ligação utilizada junto aos demais componentes necessários. ...