How to DIY A Touch Harp

In the past six months, I came into contact with makeymakey in various aspects. Then, I found makeymakey was OK, but had to rely on the computer system (operating system). It cannot be played by someone separately.
I happened to find a good board in the laser cutting remainders of mushroom cloud and then bought thin steel wires from a hardware store nearby, hoping to make a touch harp. I remembered Lele once gave me a section of codes which realizes touching of sensor by conductor half a year ago, so I carried out this making project right away.
Components
DFRduino UNO R3 (similar as Arduino UNO R3) *1
Fine wire * 10
DFPlayer - A Mini MP3 Player For Arduino *1
SD card
Small speakers
Several wires
[Making Procedure]
1. Cut the steel wires to appropriate size and then glue them on the board.
2. Connect the steel wires to conductors.
3. Connect the conductors to Arduino.
4. Test it. The codes are as follows:
Code: Select allint ledPin = 13; int capval; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); Serial.println("Touch senser"); } void loop () { digitalWrite(ledPin,LOW); capval = readCapacitivePin(6); //各个引脚都尝试一下 Serial.println(capval, DEC); if (capval > 2) { // turn LED on: digitalWrite(ledPin, HIGH); // 如果该引脚有反应的话,Arduino上的13号灯会亮 delay(10); } } uint8_t readCapacitivePin(int pinToMeasure) { // Variables used to translate from Arduino to AVR pin naming volatile uint8_t* port; volatile uint8_t* ddr; volatile uint8_t* pin; // Here we translate the input pin number from // Arduino pin number to the AVR PORT, PIN, DDR, // and which bit of those registers we care about. byte bitmask; port = portOutputRegister(digitalPinToPort(pinToMeasure)); ddr = portModeRegister(digitalPinToPort(pinToMeasure)); bitmask = digitalPinToBitMask(pinToMeasure); pin = portInputRegister(digitalPinToPort(pinToMeasure)); // Discharge the pin first by setting it low and output *port &= ~(bitmask); *ddr |= bitmask; delay(1); // Make the pin an input with the internal pull-up on *ddr &= ~(bitmask); *port |= bitmask; // Now see how long the pin to get pulled up. This manual unrolling of the loop // decreases the number of hardware cycles between each read of the pin, // thus increasing sensitivity. uint8_t cycles = 17; if (*pin & bitmask) { cycles = 0;} else if (*pin & bitmask) { cycles = 1;} else if (*pin & bitmask) { cycles = 2;} else if (*pin & bitmask) { cycles = 3;} else if (*pin & bitmask) { cycles = 4;} else if (*pin & bitmask) { cycles = 5;} else if (*pin & bitmask) { cycles = 6;} else if (*pin & bitmask) { cycles = 7;} else if (*pin & bitmask) { cycles = 8;} else if (*pin & bitmask) { cycles = 9;} else if (*pin & bitmask) { cycles = 10;} else if (*pin & bitmask) { cycles = 11;} else if (*pin & bitmask) { cycles = 12;} else if (*pin & bitmask) { cycles = 13;} else if (*pin & bitmask) { cycles = 14;} else if (*pin & bitmask) { cycles = 15;} else if (*pin & bitmask) { cycles = 16;} // Discharge the pin again by setting it low and output // It's important to leave the pins low if you want to // be able to touch more than 1 sensor at a time - if // the sensor is left pulled high, when you touch // two sensors, your body will transfer the charge between // sensors. *port &= ~(bitmask); *ddr |= bitmask; return cycles; }
The test indicates, 2, 3, 4, 5, 8, 9, 10 and 11 are usable.
5. Connect to DF mini player module and small horn as shown in the figure below
6. Transmit prepared music files into SD card. Please note the format. I found wav files did not work, so MP3 files must be used.
7. Install DFPlayer_Mini MP3 library of Arduino (In case this link fails, refer to DFPlayer Mini WIKI for detailed contents of two steps above)
8. Align each steel wire touch switch to different MP3 files.
Code: Select all1. #include <SoftwareSerial.h> 2.#include <DFPlayer_Mini_Mp3.h> 3. 4.int ledPin = 13; 5.int capval[8]; 6. 7.void setup() { 8. Serial.begin(9600); 9. mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module 10. delay(1); //wait 1ms for mp3 module to set volume 11. mp3_set_volume (30); 12. 13. pinMode(ledPin, OUTPUT); 14. mp3_play (1); 15.} 16. 17.void loop () { 18. digitalWrite(ledPin,LOW); 19. capval[0] = readCapacitivePin(2); 20. capval[1] = readCapacitivePin(3); 21. capval[2] = readCapacitivePin(4); 22. capval[3] = readCapacitivePin(5); 23. capval[4] = readCapacitivePin(8); 24. capval[5] = readCapacitivePin(9); 25. capval[6] = readCapacitivePin(10); 26. capval[7] = readCapacitivePin(11); 27. Serial.println(capval[0], DEC); 28. if (capval[0] > 2) { 29. mp3_play (2); 30. delay(100); 31. } 32. if (capval[1] > 2) { 33. mp3_play (3); 34. delay(100); 35. } 36. if (capval[2] > 2) { 37. mp3_play (4); 38. delay(100); 39. } 40. if (capval[3] > 2) { 41. mp3_play (5); 42. delay(100); 43. } 44. if (capval[4] > 2) { 45. mp3_play (6); 46. delay(100); 47. } 48. if (capval[5] > 2) { 49. mp3_play (7); 50. delay(100); 51. } 52. if (capval[6] > 2) { 53. mp3_play (8); 54. delay(100); 55. } 56. if (capval[7] > 2) { 57. mp3_play (1); 58. delay(1000); 59. } 60.} 61. 62.uint8_t readCapacitivePin(int pinToMeasure) { 63. // Variables used to translate from Arduino to AVR pin naming 64. volatile uint8_t* port; 65. volatile uint8_t* ddr; 66. volatile uint8_t* pin; 67. // Here we translate the input pin number from 68. // Arduino pin number to the AVR PORT, PIN, DDR, 69. // and which bit of those registers we care about. 70. byte bitmask; 71. port = portOutputRegister(digitalPinToPort(pinToMeasure)); 72. ddr = portModeRegister(digitalPinToPort(pinToMeasure)); 73. bitmask = digitalPinToBitMask(pinToMeasure); 74. pin = portInputRegister(digitalPinToPort(pinToMeasure)); 75. // Discharge the pin first by setting it low and output 76. *port &= ~(bitmask); 77. *ddr |= bitmask; 78. delay(1); 79. // Make the pin an input with the internal pull-up on 80. *ddr &= ~(bitmask); 81. *port |= bitmask; 82. 83. // Now see how long the pin to get pulled up. This manual unrolling of the loop 84. // decreases the number of hardware cycles between each read of the pin, 85. // thus increasing sensitivity. 86. uint8_t cycles = 17; 87. if (*pin & bitmask) { cycles = 0;} 88. else if (*pin & bitmask) { cycles = 1;} 89. else if (*pin & bitmask) { cycles = 2;} 90. else if (*pin & bitmask) { cycles = 3;} 91. else if (*pin & bitmask) { cycles = 4;} 92. else if (*pin & bitmask) { cycles = 5;} 93. else if (*pin & bitmask) { cycles = 6;} 94. else if (*pin & bitmask) { cycles = 7;} 95. else if (*pin & bitmask) { cycles = 8;} 96. else if (*pin & bitmask) { cycles = 9;} 97. else if (*pin & bitmask) { cycles = 10;} 98. else if (*pin & bitmask) { cycles = 11;} 99. else if (*pin & bitmask) { cycles = 12;} 100. else if (*pin & bitmask) { cycles = 13;} 101. else if (*pin & bitmask) { cycles = 14;} 102. else if (*pin & bitmask) { cycles = 15;} 103. else if (*pin & bitmask) { cycles = 16;} 104. 105. // Discharge the pin again by setting it low and output 106. // It's important to leave the pins low if you want to 107. // be able to touch more than 1 sensor at a time - i 108. // the sensor is left pulled high, when you touch 109. // two sensors, your body will transfer the charge between 110. // sensors. 111. *port &= ~(bitmask); 112. *ddr |= bitmask; 113. 114. return cycles; 115.}