{"id":1131,"date":"2020-01-17T22:57:54","date_gmt":"2020-01-17T22:57:54","guid":{"rendered":"http:\/\/robots-argentina.com.ar\/didactica\/?p=1131"},"modified":"2020-11-02T00:57:46","modified_gmt":"2020-11-02T00:57:46","slug":"modulo-de-emisor-piezoelectrico-pasivo-ky-006-kit-de-sensores-keyes-6","status":"publish","type":"post","link":"https:\/\/robots-argentina.com.ar\/didactica\/modulo-de-emisor-piezoelectrico-pasivo-ky-006-kit-de-sensores-keyes-6\/","title":{"rendered":"M\u00f3dulo de emisor piezoel\u00e9ctrico pasivo KY-006 (Kit de sensores Keyes 6)"},"content":{"rendered":"

Este m\u00f3dulo zumbador piezoel\u00e9ctrico Keyes KY-006<\/strong> puede producir una gama de tonos de sonido dependiendo de la frecuencia de entrada.<\/p>\n

\"\"<\/a><\/p>\n

Especificaciones:<\/strong><\/p>\n

El m\u00f3dulo KY-006<\/strong> consiste en un emisor piezoel\u00e9ctrico de sonido pasivo, que puede reproducir tonos entre 1,5 a 2,5 kHz al encenderlo y apagarlo en diferentes frecuencias usando retardos o PWM.<\/p>\n

\u25a0 Voltaje de funcionamiento:<\/strong> 1,5 ~ 15V DC
\n\u25a0 Rango de generaci\u00f3n de tonos:<\/strong> 1,5 ~ 2.5kHz
\n\u25a0 Dimensiones:<\/strong> 18,5 mm x 15 mm<\/p>\n

Diagrama de conexi\u00f3n:<\/strong><\/p>\n

La entrada de se\u00f1al (S<\/strong>) se conecta al pin digital 9<\/strong> en el Arduino y masa (indicado por –<\/strong>) a GND<\/strong>. El pin medio no se utiliza.<\/p>\n

\"\"<\/a><\/p>\n

\/*\r\n * M\u00f3dulo de emisor piezoel\u00e9ctrico pasivo KY-006\r\n *\/\r\nint emisor = 2; \/\/ definir el pin digital del Arduino\r\n\r\nvoid setup() {\r\n   pinMode(emisor, OUTPUT); \/\/ definir el pin como salida \r\n}\r\n\r\nvoid loop() {\r\n for (int i = 0; i < 80; i++) { \/\/ emitir un sonido\r\n   digitalWrite(emisor, HIGH); \/\/ salida en ALTO\r\n   delay(1); \/\/ espera 1 ms\r\n   digitalWrite(emisor, LOW); \/\/ salida en BAJO\r\n   delay(1);\r\n   }\r\n  delay(50);\r\n  for (int j = 0; j < 100; j++) { \/\/ otro sonido\r\n   digitalWrite(emisor, HIGH); \/\/ salida en ALTO\r\n   delay(2); \/\/ espera 2 ms\r\n   digitalWrite(emisor, LOW); \/\/ salida en BAJO\r\n   delay(2); \/\/ espera 2 ms\r\n   }\r\n   delay(100);\r\n}<\/pre>\n

Uso del piezoel\u00e9ctrico con la funci\u00f3n tone()<\/strong><\/p>\n

Descripci\u00f3n:<\/strong><\/p>\n

La funci\u00f3n tone()<\/a><\/strong> genera una onda cuadrada de la frecuencia especificada (y un ciclo de trabajo del 50%) en un pin digital del Arduino. Se puede especificar una duraci\u00f3n; de lo contrario, la se\u00f1al contin\u00faa hasta que se realiza una llamada a la funci\u00f3n noTone()<\/a><\/strong>. El pin se puede conectar a un zumbador piezoel\u00e9ctrico u otro altavoz para reproducir tonos.<\/p>\n

Solo se puede generar un tono a la vez<\/strong>. Si ya se est\u00e1 reproduciendo un tono en un pin diferente, la llamada a tone()<\/strong> no tendr\u00e1 ning\u00fan efecto. Si el tono se reproduce en el mismo pin, la llamada establecer\u00e1 una nueva frecuencia.<\/p>\n

El uso de la funci\u00f3n tone()<\/strong> interferir\u00e1 con la salida PWM<\/strong> en los pines 3<\/strong> y 11<\/strong> (en placas que no sean Mega<\/strong>).<\/p>\n

No es posible generar tonos inferiores a 31 Hz<\/strong>. Para detalles t\u00e9cnicos, vea las notas de Brett Hagman<\/a><\/strong>.<\/p>\n

NOTA: si desea reproducir diferentes tonos en m\u00faltiples pines, debe llamar a la funci\u00f3n noTone()<\/strong> en un pin antes de llamar a tone()<\/strong> en el siguiente pin.<\/p>\n

Sintaxis:<\/strong><\/p>\n

\u25a0 tone(pin, frecuencia)<\/strong>
\n\u25a0 tone(pin, frecuencia, duraci\u00f3n)<\/strong><\/p>\n

Par\u00e1metros:<\/strong><\/p>\n

\u25a0 pin:<\/strong> el pin sobre el que generar el tono
\n\u25a0 frecuencia:<\/strong> la frecuencia del tono en hercios – unsigned int<\/em>
\n\u25a0 duraci\u00f3n:<\/strong> la duraci\u00f3n del tono en milisegundos (opcional) – unsigned long<\/em><\/p>\n

Feliz cumplea\u00f1os<\/strong><\/p>\n

\/* \r\n * Piezo Buzzer entre GND y 9 \r\n *\/\r\n\r\nint speakerPin = 9;\r\nint length = 28; \/\/ cantidad de notas\r\nchar notes[] = \"GGAGcB GGAGdc GGxecBA yyecdc\";\r\nint beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8, 8, 8, 16, 1, 2, 2, 8, 8, 8, 16 };\r\nint tempo = 220;\r\n\r\nvoid playTone(int tone, int duration) {\r\nfor (long i = 0; i < duration * 1000L; i += tone * 2) {\r\n   digitalWrite(speakerPin, HIGH);\r\n   delayMicroseconds(tone);\r\n   digitalWrite(speakerPin, LOW);\r\n   delayMicroseconds(tone);\r\n   }\r\n}\r\n\r\nvoid playNote(char note, int duration) {\r\nchar names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',           \r\n                 'c', 'd', 'e', 'f', 'g', 'a', 'b',\r\n                 'x', 'y' };\r\nint tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,\r\n                 956,  834,  765,  593,  468,  346,  224,\r\n                 622 , 715 };\r\nint SPEE = 5;\r\n\r\n\/\/ tocar el tono correspondiente\r\nfor (int i = 0; i < 17; i++) {\r\n   if (names[i] == note) {\r\n    int newduration = duration\/SPEE;\r\n     playTone(tones[i], newduration);\r\n   }\r\n }\r\n}\r\n\r\nvoid setup() {\r\npinMode(speakerPin, OUTPUT);\r\n}\r\n\r\nvoid loop() {\r\nfor (int i = 0; i < length; i++) {\r\n   if (notes[i] == ' ') {\r\n     delay(beats[i] * tempo); \/\/ rest\r\n   } else {\r\n     playNote(notes[i], beats[i] * tempo);\r\n   }\r\n   \/\/ pause between notes\r\n   delay(tempo);\r\n}\r\n}<\/pre>\n

Para Elisa<\/strong><\/p>\n

\/* \r\n * Para Elisa \r\n *\/\r\n#define parlante 9\r\n#define tempo 0.90\r\n\r\nvoid setup() {\r\n  pinMode(parlante, OUTPUT);\r\n}\r\n\r\nvoid loop() {\r\n  \/\/ play e4\r\n  delay(tempo*600);\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*350);\r\n  \/\/ play d4# \r\n  tone(parlante, 311.13, 300);\r\n  delay(tempo*350);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*350);\r\n  \/\/ play d4# \r\n  tone(parlante,311.13, 300);\r\n  delay(tempo*350);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*350);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.66,300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63,300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play d3\r\n  tone(parlante,146.83, 300);\r\n  delay(tempo*350);\r\n  \/\/play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/play a3\r\n  tone(parlante, 220, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3#\r\n  tone(parlante, 233.08, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 900);\r\n  delay(tempo*1000);\r\n  delay(tempo*300);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4#\r\n  tone(parlante, 311.13, 300);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4#\r\n  tone(parlante, 311.13, 300);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.66, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play d3\r\n  tone(parlante, 146.83, 300);\r\n  delay(tempo*400);\r\n  \/\/ play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play b3\r\n  tone(parlante,246.94, 300);\r\n  delay(tempo*400);\r\n   \/\/ play c4\r\n  tone(parlante, 261.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.66, 300);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play g3\r\n  tone(parlante, 196, 300);\r\n  delay(tempo*400);\r\n  \/\/ play f4\r\n  tone(parlante, 349.23, 300);\r\n  delay(tempo*400);\r\n  \/\/play e4\r\n  tone(parlante, 329.23, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.63, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play e3\r\n  tone(parlante,164.81, 300);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play d3\r\n  tone(parlante, 146.83, 300);\r\n  delay(tempo*400);\r\n    \/\/ play d4\r\n  tone(parlante, 293.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 900);\r\n  delay(tempo*1000);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4# \r\n  tone(parlante, 311.13, 300);\r\n  delay(tempo*350);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*350);\r\n  \/\/ play d4# \r\n  tone(parlante,311.13, 300);\r\n  delay(tempo*350);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*350);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.66,300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63,300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play d3\r\n  tone(parlante,146.83, 300);\r\n  delay(tempo*350);\r\n  \/\/play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/play a3\r\n  tone(parlante, 220, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 233.08, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 900);\r\n  delay(tempo*1000);\r\n  delay(tempo*300);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4#\r\n  tone(parlante, 311.13, 300);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4#\r\n  tone(parlante, 311.13, 300);\r\n  delay(tempo*400);\r\n  \/\/ play e4\r\n  tone(parlante, 329.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play d4\r\n  tone(parlante, 293.66, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play d3\r\n  tone(parlante, 146.83, 300);\r\n  delay(tempo*400);\r\n  \/\/ play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 900);\r\n  delay(tempo*1000);\r\n  \/\/ play f3\r\n  tone(parlante, 174.61, 300);\r\n  delay(tempo*400);\r\n  \/\/ play c4\r\n  tone(parlante, 261.63, 300);\r\n  delay(tempo*400);\r\n  \/\/ play b3\r\n  tone(parlante, 246.94, 300);\r\n  delay(tempo*400);\r\n  \/\/ play a3\r\n  tone(parlante, 220, 900);\r\n  delay(tempo*1000);\r\n  \r\n  delay(tempo*5000);\r\n}\r\n<\/pre>\n

Canci\u00f3n de Star Wars<\/strong><\/p>\n

\/\/ * Star Wars Song Selector\r\n\/\/ * Original Composition : Star Wars\r\n\/\/ * Coded By : https:\/\/code.google.com\/p\/rbots\/source\/browse\/trunk\/StarterKit\/Lesson5_PiezoPlayMelody\/Lesson5_PiezoPlayMelody.pde\r\n\/\/ * Use BSD Clause 2 License for Distribution\r\n\/\/ * Collection by GitHub User @abhishekghosh - https:\/\/github.com\/AbhishekGhosh\/Arduino-Buzzer-Tone-Codes\r\n\/\/ * Program to choose between two melodies by using a potentiometer and a piezo buzzer.\r\n\r\n\/\/ TONES \/\/\r\n\/\/ Defining the relationship between note, period & frequency. \r\n\/\/ period is in microsecond so P = 1\/f * (1E6)\r\n \r\n#define  c3    7634\r\n#define  d3    6803\r\n#define  e3    6061\r\n#define  f3    5714\r\n#define  g3    5102\r\n#define  a3    4545\r\n#define  b3    4049\r\n#define  c4    3816    \/\/ 261 Hz \r\n#define  d4    3401    \/\/ 294 Hz \r\n#define  e4    3030    \/\/ 329 Hz \r\n#define  f4    2865    \/\/ 349 Hz \r\n#define  g4    2551    \/\/ 392 Hz \r\n#define  a4    2272    \/\/ 440 Hz \r\n#define  a4s   2146\r\n#define  b4    2028    \/\/ 493 Hz \r\n#define  c5    1912    \/\/ 523 Hz\r\n#define  d5    1706\r\n#define  d5s   1608\r\n#define  e5    1517    \/\/ 659 Hz\r\n#define  f5    1433    \/\/ 698 Hz\r\n#define  g5    1276\r\n#define  a5    1136\r\n#define  a5s   1073\r\n#define  b5    1012\r\n#define  c6    955\r\n#define  R     0      \/\/ Define a special note, 'R', to represent a rest\r\n \r\n \r\n\/\/ SETUP \/\/\r\nint speakerOut = 9;    \/\/ Set up speaker on digital pin 7\r\nint potPin = A0;      \/\/ Set up potentiometer on analogue pin 0.\r\n \r\nvoid setup() { \r\n  pinMode(speakerOut, OUTPUT);\r\n    Serial.begin(9600); \/\/ Set serial out if we want debugging\r\n  } \r\n\/\/}\r\n \r\n\/\/ MELODIES and TIMING \/\/\r\n\/\/  melody[] is an array of notes, accompanied by beats[], \r\n\/\/  which sets each note's relative length (higher #, longer note) \r\n \r\n\/\/ Melody 1: Star Wars Imperial March\r\nint melody1[] = {  a4, R,  a4, R,  a4, R,  f4, R, c5, R,  a4, R,  f4, R, c5, R, a4, R,  e5, R,  e5, R,  e5, R,  f5, R, c5, R,  g5, R,  f5, R,  c5, R, a4, R};\r\nint beats1[]  = {  50, 20, 50, 20, 50, 20, 40, 5, 20, 5,  60, 10, 40, 5, 20, 5, 60, 80, 50, 20, 50, 20, 50, 20, 40, 5, 20, 5,  60, 10, 40, 5,  20, 5, 60, 40};\r\n \r\n\/\/ Melody 2: Star Wars Theme\r\nint melody2[] = {  f4,  f4, f4,  a4s,   f5,  d5s,  d5,  c5, a5s, f5, d5s,  d5,  c5, a5s, f5, d5s, d5, d5s,   c5};\r\nint beats2[]  = {  21,  21, 21,  128,  128,   21,  21,  21, 128, 64,  21,  21,  21, 128, 64,  21, 21,  21, 128 }; \r\n \r\nint MAX_COUNT = sizeof(melody1) \/ 2; \/\/ Melody length, for looping.\r\n \r\nlong tempo = 10000; \/\/ Set overall tempo\r\n \r\nint pause = 1000; \/\/ Set length of pause between notes\r\n \r\nint rest_count = 50; \/\/ Loop variable to increase Rest length (BLETCHEROUS HACK; See NOTES)\r\n \r\n\/\/ Initialize core variables\r\nint toneM = 0;\r\nint beat = 0;\r\nlong duration  = 0;\r\nint potVal = 0;\r\n \r\n\/\/ PLAY TONE  \/\/\r\n\/\/ Pulse the speaker to play a tone for a particular duration\r\nvoid playTone() {\r\n  long elapsed_time = 0;\r\n  if (toneM > 0) { \/\/ if this isn't a Rest beat, while the tone has \r\n    \/\/  played less long than 'duration', pulse speaker HIGH and LOW\r\n    while (elapsed_time < duration) {\r\n \r\n      digitalWrite(speakerOut,HIGH);\r\n      delayMicroseconds(toneM \/ 2);\r\n \r\n      \/\/ DOWN\r\n      digitalWrite(speakerOut, LOW);\r\n      delayMicroseconds(toneM \/ 2);\r\n \r\n      \/\/ Keep track of how long we pulsed\r\n      elapsed_time += (toneM);\r\n    } \r\n  }\r\n  else { \/\/ Rest beat; loop times delay\r\n    for (int j = 0; j < rest_count; j++) { \/\/ See NOTE on rest_count\r\n      delayMicroseconds(duration);  \r\n    }                                \r\n  }                                 \r\n}\r\n \r\n\/\/ LOOP \/\/\r\nvoid loop() {\r\n  analogRead(potPin); \/\/Read potentiometer value and store in potVal variable\r\n  Serial.println(potVal); \/\/ Print potVal in serial monitor\r\n  \r\n  if (potVal < 511) { \/\/ If potVal is less than 511, play Melody1...\r\n  \r\n  \/\/ Set up a counter to pull from melody1[] and beats1[]\r\n  for (int i=0; i<MAX_COUNT; i++) {\r\n    toneM = melody1[i];\r\n    beat = beats1[i];\r\n \r\n    duration = beat * tempo; \/\/ Set up timing\r\n \r\n    playTone(); \/\/ A pause between notes\r\n    delayMicroseconds(pause);\r\n    }\r\n  }\r\n  else    \/\/ ... else play Melody2\r\nfor (int i=0; i<MAX_COUNT; i++) {\r\n    toneM = melody2[i];\r\n    beat = beats2[i];\r\n \r\n    duration = beat * tempo; \/\/ Set up timing\r\n \r\n    playTone(); \/\/ A pause between notes\r\n    delayMicroseconds(pause);\r\n    }\r\n  }<\/pre>\n

Brilla, brilla, peque\u00f1a estrella<\/strong><\/p>\n

\/*\r\n * Twinkle-Twinkle Little Star\r\n *\/\r\nint speakerPin = 9;\r\nint length = 15; \/\/ the number of notes\r\n\r\n\/\/twinkle twinkle little star\r\nchar notes[] = \"ccggaag ffeeddc ggffeed ggffeed ccggaag ffeeddc \"; \/\/ a space represents a rest\r\nint beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };\r\nint tempo = 260;\r\n\r\nvoid playTone(int tone, int duration) {\r\n  for (long i = 0; i < duration * 1000L; i += tone * 2) {\r\n    digitalWrite(speakerPin, HIGH);\r\n    delayMicroseconds(tone);\r\n    digitalWrite(speakerPin, LOW);\r\n    delayMicroseconds(tone);\r\n  }\r\n}\r\n\r\nvoid playNote(char note, int duration) {\r\n  char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };\r\n  int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };\r\n  \r\n  \/\/ play the tone corresponding to the note name\r\n  for (int i = 0; i < 8; i++) {\r\n    if (names[i] == note) {\r\n      playTone(tones[i], duration);\r\n    }\r\n  }\r\n}\r\n\r\nvoid setup() {\r\n  pinMode(speakerPin, OUTPUT);\r\n}\r\n\r\nvoid loop() {\r\n  for (int i = 0; i < length; i++) {\r\n    if (notes[i] == ' ') {\r\n      delay(beats[i] * tempo); \/\/ rest\r\n    } else {\r\n      playNote(notes[i], beats[i] * tempo);\r\n    }\r\n    \r\n    \/\/ pause between notes\r\n    delay(tempo \/ 2); \r\n  }\r\n}<\/pre>\n

M\u00f3dulo de emisor piezoel\u00e9ctrico pasivo – <\/strong>KY-006: Dibujo de la pieza para el editor Fritzing<\/strong><\/a><\/strong> <\/p>\n

Art\u00edculos relacionados:<\/strong><\/p>\n

\u25a0 M\u00f3dulo sensor de temperatura KY-001 (Kit de sensores Keyes 1)<\/a><\/strong>
\n\u25a0
M\u00f3dulo detector de vibraci\u00f3n KY-002 (Kit de sensores Keyes 2)<\/a><\/strong>
\n\u25a0
M\u00f3dulo de Sensor Magn\u00e9tico por efecto Hall KY-003 (Kit de sensores Keyes 3)<\/a><\/strong>
\n\u25a0
M\u00f3dulo de llave pulsadora – KY-004 (Kit de sensores Keyes 4)<\/a><\/strong>
\n\u25a0
M\u00f3dulo sensor de temperatura KY-005 (Kit de sensores Keyes 5)<\/a><\/strong>
\n\u25a0
M\u00f3dulo de emisor piezoel\u00e9ctrico pasivo KY-006 (Kit de sensores Keyes 6)<\/a><\/strong>
\n\u25a0
M\u00f3dulo codificador rotativo KY-040 [\u00f3 KY-007] \u2013 (Kit de sensores Keyes 040\/007)<\/a><\/strong><\/p>\n


\n