Components and supplies
Arduino UNO
Speaker: 0.25W, 8 ohms
Rotary potentiometer (generic)
Jumper wires (generic)
Apps and platforms
Arduino IDE
Project description
Code
the code:
arduino
1#include "pitches.h" 2 3 4// notes to play, corresponding to the 5 3 sensors: 6int speakerPin = 8; 7int notes[] = { 8 0, NOTE_AS1,NOTE_A2,NOTE_GS3,NOTE_G4,NOTE_FS5,NOTE_F6,NOTE_E7,NOTE_DS8 9}; 10 11void 12 setup() { 13pinMode(A0,INPUT); 14pinMode(speakerPin,OUTPUT); 15 16} 17 18void 19 loop() { 20 int sensor = analogRead(A0); 21 int S = map(sensor,0,1023,0,9); 22 23 int P = notes[S]; 24 tone(speakerPin,P,100); 25}
pitches
h
put this file in the same folder of the project
1/************************************************* 2 * Public Constants 3 4 *************************************************/ 5 6#define NOTE_B0 31 7#define 8 NOTE_C1 33 9#define NOTE_CS1 35 10#define NOTE_D1 37 11#define NOTE_DS1 39 12#define 13 NOTE_E1 41 14#define NOTE_F1 44 15#define NOTE_FS1 46 16#define NOTE_G1 49 17#define 18 NOTE_GS1 52 19#define NOTE_A1 55 20#define NOTE_AS1 58 21#define NOTE_B1 62 22#define 23 NOTE_C2 65 24#define NOTE_CS2 69 25#define NOTE_D2 73 26#define NOTE_DS2 78 27#define 28 NOTE_E2 82 29#define NOTE_F2 87 30#define NOTE_FS2 93 31#define NOTE_G2 98 32#define 33 NOTE_GS2 104 34#define NOTE_A2 110 35#define NOTE_AS2 117 36#define NOTE_B2 37 123 38#define NOTE_C3 131 39#define NOTE_CS3 139 40#define NOTE_D3 147 41#define 42 NOTE_DS3 156 43#define NOTE_E3 165 44#define NOTE_F3 175 45#define NOTE_FS3 46 185 47#define NOTE_G3 196 48#define NOTE_GS3 208 49#define NOTE_A3 220 50#define 51 NOTE_AS3 233 52#define NOTE_B3 247 53#define NOTE_C4 262 54#define NOTE_CS4 55 277 56#define NOTE_D4 294 57#define NOTE_DS4 311 58#define NOTE_E4 330 59#define 60 NOTE_F4 349 61#define NOTE_FS4 370 62#define NOTE_G4 392 63#define NOTE_GS4 64 415 65#define NOTE_A4 440 66#define NOTE_AS4 466 67#define NOTE_B4 494 68#define 69 NOTE_C5 523 70#define NOTE_CS5 554 71#define NOTE_D5 587 72#define NOTE_DS5 73 622 74#define NOTE_E5 659 75#define NOTE_F5 698 76#define NOTE_FS5 740 77#define 78 NOTE_G5 784 79#define NOTE_GS5 831 80#define NOTE_A5 880 81#define NOTE_AS5 82 932 83#define NOTE_B5 988 84#define NOTE_C6 1047 85#define NOTE_CS6 1109 86#define 87 NOTE_D6 1175 88#define NOTE_DS6 1245 89#define NOTE_E6 1319 90#define NOTE_F6 91 1397 92#define NOTE_FS6 1480 93#define NOTE_G6 1568 94#define NOTE_GS6 1661 95#define 96 NOTE_A6 1760 97#define NOTE_AS6 1865 98#define NOTE_B6 1976 99#define NOTE_C7 100 2093 101#define NOTE_CS7 2217 102#define NOTE_D7 2349 103#define NOTE_DS7 2489 104#define 105 NOTE_E7 2637 106#define NOTE_F7 2794 107#define NOTE_FS7 2960 108#define NOTE_G7 109 3136 110#define NOTE_GS7 3322 111#define NOTE_A7 3520 112#define NOTE_AS7 3729 113#define 114 NOTE_B7 3951 115#define NOTE_C8 4186 116#define NOTE_CS8 4435 117#define NOTE_D8 118 4699 119#define NOTE_DS8 4978 120
pitches
h
put this file in the same folder of the project
1/************************************************* 2 * Public Constants 3 *************************************************/ 4 5#define NOTE_B0 31 6#define NOTE_C1 33 7#define NOTE_CS1 35 8#define NOTE_D1 37 9#define NOTE_DS1 39 10#define NOTE_E1 41 11#define NOTE_F1 44 12#define NOTE_FS1 46 13#define NOTE_G1 49 14#define NOTE_GS1 52 15#define NOTE_A1 55 16#define NOTE_AS1 58 17#define NOTE_B1 62 18#define NOTE_C2 65 19#define NOTE_CS2 69 20#define NOTE_D2 73 21#define NOTE_DS2 78 22#define NOTE_E2 82 23#define NOTE_F2 87 24#define NOTE_FS2 93 25#define NOTE_G2 98 26#define NOTE_GS2 104 27#define NOTE_A2 110 28#define NOTE_AS2 117 29#define NOTE_B2 123 30#define NOTE_C3 131 31#define NOTE_CS3 139 32#define NOTE_D3 147 33#define NOTE_DS3 156 34#define NOTE_E3 165 35#define NOTE_F3 175 36#define NOTE_FS3 185 37#define NOTE_G3 196 38#define NOTE_GS3 208 39#define NOTE_A3 220 40#define NOTE_AS3 233 41#define NOTE_B3 247 42#define NOTE_C4 262 43#define NOTE_CS4 277 44#define NOTE_D4 294 45#define NOTE_DS4 311 46#define NOTE_E4 330 47#define NOTE_F4 349 48#define NOTE_FS4 370 49#define NOTE_G4 392 50#define NOTE_GS4 415 51#define NOTE_A4 440 52#define NOTE_AS4 466 53#define NOTE_B4 494 54#define NOTE_C5 523 55#define NOTE_CS5 554 56#define NOTE_D5 587 57#define NOTE_DS5 622 58#define NOTE_E5 659 59#define NOTE_F5 698 60#define NOTE_FS5 740 61#define NOTE_G5 784 62#define NOTE_GS5 831 63#define NOTE_A5 880 64#define NOTE_AS5 932 65#define NOTE_B5 988 66#define NOTE_C6 1047 67#define NOTE_CS6 1109 68#define NOTE_D6 1175 69#define NOTE_DS6 1245 70#define NOTE_E6 1319 71#define NOTE_F6 1397 72#define NOTE_FS6 1480 73#define NOTE_G6 1568 74#define NOTE_GS6 1661 75#define NOTE_A6 1760 76#define NOTE_AS6 1865 77#define NOTE_B6 1976 78#define NOTE_C7 2093 79#define NOTE_CS7 2217 80#define NOTE_D7 2349 81#define NOTE_DS7 2489 82#define NOTE_E7 2637 83#define NOTE_F7 2794 84#define NOTE_FS7 2960 85#define NOTE_G7 3136 86#define NOTE_GS7 3322 87#define NOTE_A7 3520 88#define NOTE_AS7 3729 89#define NOTE_B7 3951 90#define NOTE_C8 4186 91#define NOTE_CS8 4435 92#define NOTE_D8 4699 93#define NOTE_DS8 4978 94
the code:
arduino
1#include "pitches.h" 2 3 4// notes to play, corresponding to the 3 sensors: 5int speakerPin = 8; 6int notes[] = { 7 0, NOTE_AS1,NOTE_A2,NOTE_GS3,NOTE_G4,NOTE_FS5,NOTE_F6,NOTE_E7,NOTE_DS8 8}; 9 10void setup() { 11pinMode(A0,INPUT); 12pinMode(speakerPin,OUTPUT); 13 14} 15 16void loop() { 17 int sensor = analogRead(A0); 18 int S = map(sensor,0,1023,0,9); 19 int P = notes[S]; 20 tone(speakerPin,P,100); 21}
Downloadable files
the circuit:
the circuit:
the schematic:
the schematic:
the circuit:
the circuit:
Comments
Only logged in users can leave comments