एक मिडी नियंत्रक का उपयोग Arduino में एक विंटेज खिलौना पियानो की ओर मुड़ते

Could you turn a wooden toy piano into a MIDI controller? Could you do it in 24 hours? Liam Lacey did it at MIDI Hack 2015 in Berlin and won a prize too. Now you can make your own as Liam shares all.

मई 2015 में मैंने भाग लिया मिडी हैक

MIDI Hack 2015. Photos by Sebastian Höglund.

यदि आप एक पढ़ा, तो मेरा पिछले लेख , तुम मुझे अत्यधिक उपकरण मिडी नियंत्रकों बनाने के लिए Arduino के मंच की सलाह देते हैं कि पता होगा। मैं फिर भी यह अभी भी सरकारी सहायता और मार्गदर्शन के बहुत से अत्यंत शुरुआत के अनुकूल है, यह आप इनपुट / आउटपुट डाटा के साथ क्या करते हैं पर नियंत्रण का एक बहुत कुछ के साथ आपको प्रदान करता है के रूप में अन्य सुझाव दिया प्लेटफार्मों पर इस परियोजना के लिए Arduino चुना है। इस गाइड पूरा इलेक्ट्रॉनिक्स में शुरुआती, सॉफ्टवेयर विकास, और Arduino के हैं जो व्यक्तियों के उद्देश्य से है।

यहाँ आप इस परियोजना के लिए की आवश्यकता होगी चीजों की एक सूची है। यहां उल्लिखित सभी इलेक्ट्रॉनिक उपकरणों ऐसे SparkFun के रूप में, किसी भी अच्छे उपकरण / hobbyist के इलेक्ट्रॉनिक्स की दुकान से खरीदा जा सकता है।

What You Will Need for this Project

  • एक ध्वनिक लकड़ी के खिलौने पियानो। मैं फिर भी आप भी कभी कभी दान की दुकानों और पिस्सू बाजार में पा सकते हैं, आमतौर पर कुछ ही उपलब्ध हैं, जहां आसपास $ 15 के लिए eBay के बंद मेरी खिलौना पियानो खरीदा है। इस परियोजना की चाबियाँ एक हथौड़ा गूंजती वस्तु का किसी तरह हड़ताल करने के कारण जिससे एक तंत्र के साथ पियानो के आसपास आधारित है; एक खिलौना इलेक्ट्रॉनिक कीबोर्ड का उपयोग कर यहां काम नहीं करेगा।
  • Arduino बोर्ड। यह होगा कि microcontroller का है
  • Piezo तत्वों। Piezo तत्व सेंसर कंपन और दस्तक देता है पता लगाने के लिए प्रयोग किया जाता है, और लोकप्रिय घटक DIY और वाणिज्यिक ड्रम ट्रिगर उत्पादों में विशेष रूप से उपयोग करने के लिए कर रहे हैं। हम चाबी से प्रेस का पता लगाने के लिए इन का उपयोग करेगा, और आप प्रत्येक कुंजी के लिए इनमें से किसी एक की आवश्यकता होगी। आप पियानो के भीतर हथौड़ा सिर के आकार के आधार पर आप की आवश्यकता piezos के आकार पर विचार करने की आवश्यकता होगी
  • 1M ओम प्रतिरोधों। प्रतिरोधों बिजली के सर्किट में सबसे बुनियादी और सामान्य घटक हैं, और बिजली के प्रवाह का विरोध करने के लिए इस्तेमाल कर रहे हैं। आप प्रत्येक कुंजी / पीजो के लिए इनमें से किसी एक की आवश्यकता होगी।
  • तारों। Arduino और भी पुरुष-से-पुरुष जम्पर तारों के रूप में जाना जाता है breadboard के अनुकूल तारों, उपयोग करने के लिए आसान हो जाएगा, और हम Arduino के लिए सभी घटकों को कनेक्ट करने के लिए इन का उपयोग करेगा। आप एक्स्ट्रा कलाकार के प्रत्येक कुंजी / पीजो, साथ ही मुट्ठी भर के लिए 2 जरूरत होगी।
  • मिलाप-कम breadboards। मिलाप-कम breadboards आप सब कुछ एक साथ मिलाप की जरूरत के बिना इलेक्ट्रॉनिक सर्किट बनाने के लिए अनुमति देते हैं। आप अपने खिलौना पियानो है कि कितने चाबियाँ के आधार पर इनमें से एक जोड़ी की जरूरत हो सकती है।
  • यूएसबी केबल
  • डबल पक्षीय चिपचिपा टेप
  • Arduino के सॉफ्टवेयर। Arduino के सॉफ्टवेयर हम यह करना चाहते हैं कि क्या करना है Arduino बोर्ड प्रोग्राम करने के लिए प्रयोग किया जाता है। इस पर आसानी से उपलब्ध है Arduino के सॉफ्टवेयर पेज और ओएस एक्स, Windows, और लिनक्स पर चलाया जा सकता है। तुम भी Arduino मिडी पुस्तकालय डाउनलोड करने की आवश्यकता होगी।
  • -मिडी करने वाली सीरियल और आभासी मिडी बंदरगाह सॉफ्टवेयर। आप मिडी संदेश में Arduino से बाहर आने के संदेशों को परिवर्तित करने के लिए कुछ धारावाहिक करने वाली मिडी सॉफ्टवेयर की आवश्यकता होगी। मैं फिर भी उपलब्ध दूसरों के एक नंबर रहे हैं, सीरियल ब्रिज आवेदन करने के लिए स्वतंत्र गंजा मिडी सलाह देते हैं। आप भी अपनी काला कौवा या मिडी साधन के इनपुट के लिए गंजा के उत्पादन में कनेक्ट करने के लिए एक आभासी मिडी बंदरगाह का उपयोग करने की आवश्यकता होगी। इसके लिए मैं विंडोज पर loopMIDI की सलाह देते हैं, या ओएस एक्स पर आप इसके निर्माण में IAC चालक का उपयोग कर सकते हैं। वैकल्पिक रूप से, यह संभव है कि
  • मिडी सॉफ्टवेयर। आप

Step 1—Prepare your Piano

आप अपने पियानो में इलेक्ट्रॉनिक्स डालने शुरू कर सकते हैं इससे पहले कि आप उन्हें करने के लिए piezos माउंट कर सकते हैं, इसलिए है कि आप ध्वनि छड़ निकाल सकते हैं या उन्हें संशोधित करने की आवश्यकता होगी। मेरे पियानो में छड़ के सेट टॉप के नीचे करने के लिए दबाव डाला गया, तो मैं बस उन्हें दूर करने के लिए उन्हें unscrewed, और फिर मैं पीजो सेंसर करने के लिए दृढ़ हो सकता है कि लकड़ी का एक खंड में खराब कर दिया है। एक वैकल्पिक विकल्प लेकिन आप इसे और अधिक कठिन छड़ के लिए कुछ संलग्न करने के लिए मिल सकता है, piezos करने के लिए तय किया जा सकता है कि छड़ के नीचे करने के लिए सामग्री की एक पतली फ्लैट टुकड़ा (जैसे, गत्ता, लकड़ी) तय करने के लिए हो सकता है, और आप चाहते हैं यह भी इलेक्ट्रॉनिक्स डालने का प्रयास करते समय छड़ रास्ते में मिल जाएगा मिल सकता है।

शीर्ष-बाएं दक्षिणावर्त से

आप अपने पियानो के लिए क्या करने की आवश्यकता हो सकती है एक और संशोधन piezos हड़ताल करेंगे कि हथौड़ा की सतह के लिए एक कील / बिंदु जोड़ने का है। हथौड़ा सिर वे ठीक से सेंसर ट्रिगर नहीं हो सकता piezos के इनर सर्कल से अधिक व्यापक हैं, तो मैं एक उठाया बिंदु बनाने के लिए हथौड़ों पर मिलाप की छोटी गेंदों टेप मेरे पियानो के साथ इस मुद्दे पर काबू पाने के लिए।

Step 2—Attach the Piezos

अब हम कुंजी को दबाया जाता है जब हथौड़ा तंत्र आमतौर पर ध्वनि की छड़ हड़ताल करेंगे जहां पियानो के ऊपर से नीचे करने के लिए पीजो सेंसर जगह होगी। अपने पियानो की खान की तरह हाथ का बना है, तो आप शायद हथौड़ों नहीं कर रहे हैं कि मिल जाएगा

आप एक बार

संलग्न पीजो सेंसर

Step 3—Complete the Circuitry

Circuitry के पूरा करने के लिए आदेश में आप पहली बार पियानो के अंदर करने के breadboard / s और Arduino बोर्ड संलग्न करने की आवश्यकता है। अपने पियानो नीचे से खुलता है मेरा था जैसे आप शायद पियानो ऊपर से खोलता है, लेकिन अगर आप शायद सिर्फ छड़ी की जरूरत के बिना तल में बोर्डों रखकर इस परियोजना को पूरा कर सकता है, ऊपर से नीचे करने के लिए बोर्ड के लिए छड़ी करने की आवश्यकता होगी वे नीचे। दूसरी तरफ Arduino के साथ, breadboard / एस निकटतम piezos करने के लिए जगह।

इसके बाद आप breadboard / s घटकों को संलग्न करने की आवश्यकता है। सबसे breadboards करने के लिए दो मुख्य वर्गों (निम्न आरेख के भीतर दिखाया गया है) कर रहे हैं

एक Arduino बोर्ड के लिए एक एकल पीजो सेंसर कनेक्ट करने के लिए कैसे करें

पिछले चित्र में प्रदर्शित के रूप में लाल (संकेत) वायर टर्मिनल में से एक से जुड़े होने की जरूरत है, जबकि प्रत्येक पीजो / कुंजी के लिए, पीजो से काली (भूमि) के तार, जमीन बस स्ट्रिप्स में से एक से जुड़े होने की जरूरत है स्ट्रिप्स। तुम तो जमीन पट्टी करने के लिए टर्मिनल पट्टी से (किसी भी अभिविन्यास में) एक अवरोध कनेक्ट करने के लिए की जरूरत है; Arduino पर एनालॉग इनपुट पिन से एक करने के लिए टर्मिनल पट्टी से एक तार, और जमीन पिंस में से एक को जमीन पट्टी से एक और तार। निम्न आरेख में प्रदर्शन के रूप में तुम तो एक अलग टर्मिनल पट्टी और Arduino के अनुरूप निवेश पिन हर बार उपयोग करते हुए, प्रत्येक पीजो के लिए इस सर्किट को दोहराने की जरूरत है।

कैसे एक Arduino बोर्ड के लिए कई पीजो सेंसर कनेक्ट करने के लिए

इस देखने के लिए क्या यह आसान बना देता है, जैसा कि मैं प्रत्येक अनुरूप निवेश कनेक्शन के लिए अलग अलग रंग के तारों का उपयोग करना चाहिये

टॉप

Step 4—Edit and Upload the Code

हार्डवेयर और इलेक्ट्रॉनिक्स पूरा कर रहे हैं के बाद, आप तो मिडी नोट में piezos से रीडिंग बंद हो जाएगा कि Arduino बोर्ड के लिए कुछ सॉफ्टवेयर अपलोड करने की जरूरत है। आप डाउनलोड की है और Arduino के सॉफ्टवेयर और Arduino मिडी लाइब्रेरी दोनों को स्थापित करने के बाद, Arduino के आवेदन खुला और Arduino के पाठ संपादक में नीचे दिए गए कोड को कॉपी:

/*
MIDI Toy Piano Hack Code
*/

#include 
MIDI_CREATE_DEFAULT_INSTANCE();

//========================================================================================
//Values you may need to change

//Set this value to the number of keys/piezos you are using
const int NUM_OF_KEYS = 16;
//Adjust this value to change the sensitivity of the piezos
const int THRESHOLD = 5;
//Set this value to the number of microseconds you want each MIDI note to last for
const int NOTE_LENGTH = 50;
//Adjust this value to set the range of MIDI note velocity values
const int VEL_SENSE_VAL = 2;

//Change this number to set what MIDI channel the MIDI notes are set to
const int midiChan = 1;
//Change these numbers to set what MIDI note number each key/piezo will send.
//Also make sure that the total number of numbers here matches the value of NUM_OF_KEYS
const int midiNote[NUM_OF_KEYS] = {86, 84, 83, 81, 79, 77, 76, 74, 72, 71, 69, 67, 65, 64, 62, 60};

//Change these values to set which analog input pins you are using
//Also make sure that the total number of values here matches the value of NUM_OF_KEYS
const int triggerSensor[NUM_OF_KEYS] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};

//=======================================================================================

//Variables for storing certain values
int triggerVal[NUM_OF_KEYS] = {0};
bool noteIsOn[NUM_OF_KEYS] = {false};
int midiNoteTime[NUM_OF_KEYS] = {0};
int midiVelocityVal[NUM_OF_KEYS] = {0};

void setup()
{
    MIDI.begin(MIDI_CHANNEL_OMNI);
}

void loop()
{
    //repeat the below code for each anaolog input/piezo sensor
    for (int count; count < NUM_OF_KEYS; count++)
    {
        //read the piezo value
        triggerVal[count] = analogRead(triggerSensor[count]);

        //if the value is over the threshold and there isn't currently a note on for this piezo
        if (triggerVal[count] > THRESHOLD && noteIsOn[count] == false)
        {
            //get a velocity value based on the value
            midiVelocityVal[count] = triggerVal[count] * (127.0/1023.0);

            //increase sensitivity
            midiVelocityVal[count] *= VEL_SENSE_VAL;

            //make sure we don't go out of range
            if (midiVelocityVal[count] > 127)
            midiVelocityVal[count] = 127;

            //send a MIDI note-on message
            MIDI.sendNoteOn (midiNote[count], midiVelocityVal[count], midiChan);

            //flag that the note is on
            noteIsOn[count] = true;

            //start a timer for the note to be on for
            midiNoteTime[count] = NOTE_LENGTH;
        }

        //if the note is currently on
        if (noteIsOn[count] == true)
        {
            //reduce the time value by 1
            midiNoteTime[count]--;

            //if time value equals 0
            if (midiNoteTime[count] == 0)
            {
                //turn off the note
                MIDI.sendNoteOff (midiNote[count], 0, midiChan);
                noteIsOn[count] = false;
            }

        }

    }

    //pause the loop
    delay(1);
}
        

कैसे Arduino के सॉफ्टवेयर का उपयोग करने के लिए आप शिक्षण और कैसे कोड के लिए इस लेख के दायरे से परे एक सा है, तो मैं

  • NUM_OF_KEYS
  • THRESHOLD
  • NOTE_LENGTH
  • VEL_SENSE_VAL
  • midiChan
  • midiNote
  • triggerSensor

Arduino के सॉफ्टवेयर

आप एक बार

  • के लिए जाओ
  • USB के माध्यम से आपके कंप्यूटर को अपने Arduino बोर्ड कनेक्ट करें।
  • के लिए जाओ
  • के लिए जाओ
  • के लिए जाओ

कृपया ध्यान दें

Spotlight Courses

More courses released every few days.

Step 5—Connect the Software

वाम: सीरियल पुल के लिये विन्यास गंजा मिडी: ओएस एक्स के शीर्ष दाएँ पर एक आभासी मिडी बंदरगाह की स्थापना। दाहिने: Ableton जीते में आभासी मिडी पोर्ट से कनेक्ट हो।

अंत में आप शुरू करने और अपने कंप्यूटर पर सभी आवश्यक सॉफ्टवेयर कनेक्ट करने के लिए की जरूरत है:

एक आभासी मिडी बंदरगाह स्थापित:

यदि आप Windows पर हैं:

  • LoopMIDI खोलो
  • पर क्लिक करें
  • आवेदन चल छोड़

आप ओएस एक्स पर हैं:

  • लॉन्च
  • के लिए जाओ
  • पर डबल क्लिक करें
  • सुनिश्चित करें कि
  • एप्लिकेशन बंद करो

कनेक्ट गंजा मिडी करने वाली सीरियल Arduino और आभासी मिडी बंदरगाह के लिए पुल:

  • गंजा लॉन्च
  • बाएं हाथ पर पक्ष सेट
  • दाएँ हाथ पर पक्ष सेट
  • सुनिश्चित करें
  • आवेदन चल छोड़

आभासी बंदरगाह के लिए आप काला कौवा / मिडी साधन सॉफ्टवेयर कनेक्ट करें:

  • अपने काला कौवा या मिडी साधन लॉन्च
  • इसके तहत

अपने Arduino के HIDUINO से काट दिया जाता है, तो 1 और 2 के डॉन कदम - कृपया ध्यान दें

यह पूरा हो जाने के बाद आप अब खिलौना पियानो के साथ अपने मिडी उपकरणों से नोटों को गति प्रदान करने में सक्षम होना चाहिए।

कार्रवाई में ध्वनिक खिलौना पियानो मिडी नियंत्रक की एक छोटी वीडियो डेमो देखें:

Conclusion

ताकि

आप अगले मिडी हैक समारोह में भाग लेने में दिलचस्प हैं इसके अलावा, अगर, पर नजर रखने के लिए मिडी हैक वेबसाइट घोषणाओं के लिए। इस तरह के संगीत Hackday और संगीत टेक फेस्ट के रूप में दुनिया भर में सभी प्रतिवर्ष आयोजित की जाती हैं कि इसी तरह के संगीत तकनीक hackathons, साथ ही विभिन्न एकबारगी और स्थानीय घटनाओं की एक जोड़ी भी शामिल हैं।

यहाँ मिडी के बारे में अधिक जानें।

Synthesis 101
The Filter
by Bob Moog Foundation

"Liam is the Head Of Development specialising in software development at Modal Electronics, the company behind the 002, 008, CRAFT and SKULPT synthesisers, and was previously the lead software developer at nu desine, the developers of the AlphaSphere MIDI controllers. He was also an Associate Lecturer at UWE, Bristol, UK where he gradua..." Read More

Discussion

Joe
How would the code change if I wanted to use something besides a piezo. What if I just wanted to turn the Arduino into a Makey Makey and connect electrical currents from the GND to A0.
Liam Lacey
Hey Joe,
You could connect a different type of sensor or electronic source and get results without changing the code, however it will only create a note based on the first reading it gets over the threshold (due to the logic implemented for turning piezo inputs into MIDI notes). Using just electrical current to trigger a reading would be very similar to using a simple push button (where pressing the button completes the circuit and creates a reading), so I'd recommend looking at Arduino button tutorials for that.
Michel Mariano
when I put the code in my arduino notes repeatedly play without stopping and I do not touch any key how do I resolve this error I think it's the end I am not able to understand. please help me.
Liam Lacey
Hey Michel,
It sounds like your piezo sensors are not properly connected to the Arduino. Check that they are connected to the correct pins. You may also need to correct the value of NUM_OF_KEYS in the code if you are using less than 16 sensors/keys. You may also need to up the value of THRESHOLD in the code if your piezos are particularly sensitive.
Michel Mariano
Hey Liam,

thanks for answering me so fast , I'll check that the wires are connected correctly, I have another doubt about the code it in the end you said : "repeat the below code for each anaolog input/piezo sensor", and I 'm trying to do with a arduino uno with only 3 pins I changed all that you said , but the end I do not know where to get the code to be copied to each piezo I have and also do not know where it ends.

look I change this:

NUM_OF_KEYS = 3;
midiNote[NUM_OF_KEYS] = {86, 84, 83}
triggerSensor[NUM_OF_KEYS] = {A0, A1, A2}
IN THIS PART I WILL NEED TO PUT SOME NUMBER? -> (int count; count < NUM_OF_KEYS; count++)

Im sorry for all this question but im very lost with this and thank you so much for your help and sorry for my english.
Im from Brasil.
Liam Lacey
Hey Michel,

NUM_OF_KEYS, midiNote, and triggerSensor are the only values you need to change, which you have correctly done. The "repeat the below code for each anaolog input/piezo sensor" comment is actually a description of what the below 'for' loop does, rather than being an instruction. You shouldn't have to change any code in that section for it to work.
Michel Mariano
Hey Liam,

Thank you so much, this time again made ​​the piezos cables and worked, thanks for your help I buy one arduino mega
and when it comes I gonna do with the 16 piezos.

please let me ask you one more question?! can I put on this project potentiometers or one pitch bend?
Liam Lacey
Hey Michel,

Glad you got it working.

If you want to attach something like a potentiometer you'll need to change the code for reading from that particular analogue input. However the code needed here is a lot simpler - see https://www.arduino.cc/en/Tutorial/AnalogReadSerial to lean how to do this.
Florent
Hi ! Thanks for the amazing tutorial. This code line doesn't work on my Arduino when I try to install it.

_____

#include

____

He's answering me this

#include
^
exit status 1
#include expects "FILENAME" or

Do you have an idea?

Thanks,
Florent
Liam Lacey
Hey Florent,

Thanks for the kind words and for spotting this mistake.
The code above has now been updated to the correct version.

Thanks,
Liam.
Florent
Thanks! So I need this Midi.h file? Best, Florent
Liam Lacey
Yes, you need to download and install the Arduino MIDI library from http://playground.arduino.cc/Main/MIDILibrary. Best, Liam.
Florent
It's perfectly working now ! Thank you so much !
Organist
Great article thanks @Liam. I am embarking on a charity project as part of a education outreach project for our local 'large' parish church and wonder whether you would be able to give me some help with some sticking points (understand if not)...

Project = allow young people to explore (play) the out-of-reach pipe organ from a wireless-midi capable keyboard.

So far... I have an arduino, a wireless midi transmitter/receiver (Medeli WIMIDI - tested and quite surprised by performance), a breadboard (cables, female midi socket etc).

I want to connect the wireless midi transmitter to the out socket of the remote keyboard and the wireless midi receiver to the arduino (I need to solder connect to arduino via breadboard). With the arduino midi library I presume I will then be able to receive the incoming midi signal ? This is where it becomes tricky for me to ascertain next steps!... I then want to translate the midi in to individual note signals (much like what you have done in this article). Is this possible?

If this is doable, my last sticking point is how to get the individual note signals 'transferred' to the organ console. I have seen an article where someone attaches a solenoid for each note to a wooden board and then rests the board over the top of the organ keyboard. However, the organ we are planning to work on already has access to the rear of the keyboard and each note has a visible switch (2 cables to each note) on a low voltage (12v) system. Is it possible to intercept each of these switches with the arduino outputs for each note? My apologies if this is a stupid question!?
Emin
Hej Liam!

This is an awesome tutorial. It'll help me a lot with what I want to do cause the setting is similar but usage is completely different.

I wonder if the amount of the contact mics can be different? Is there any maximum we can connect?

Also, is it possible to use condenser mics instead of piezos, possibly with a little trick?? Otherwise do you have any suggestions of how I can do it?

Thanks a lot!
Liam Lacey
Hey Emin,

The number of piezo sensors you can connect depends on the number of analog inputs that your microcontroller has e.g. on an Arduino Mega you have 16 analog inputs. However it is possible to expand this number using multiplexer components - see https://playground.arduino.cc/Learning/4051. There are also Arduino IO expander shields that can do this for you.

Regarding using consider mics instead, the extra complexity depends on whether you are just trying to detect a sound level, or trying to capture actual sound data. For just detecting sound levels see http://www.learningaboutelectronics.com/Articles/Arduino-microphone-circuit.php as an example, however recording actual audio is more complex (e.g. see http://www.instructables.com/id/Arduino-Audio-Input/).
Emin
Hey Liam!

Thanks a lot for your answer.

I have an Ard.Mega and I indeed only need to use them to retrieve vibration data - not sound.

Do you think I can use your setup the same, but differ the code to make it receive only vibration level - say from 0 to 100? In that case, would you mind sharing how the code shall be?

Many thanks.
manirbangladesh
It's very specific tutorial. Great. Anyone can learn from this tutorial. I will use this guide for a midi drum. 9 piezos will be used.
I had a question. You used 18 piezo. But the Arduino mega allows only 16 input. What ambi missing?
Liam Lacey
Hey manirbangladesh. Contrary to the photos of the piano, I only actually used 16 piezos due to the 16 input limit on the Arduino Mega (originally I was going to use a multiplexer to allow for 18 piezos, however I later decided to abandon this idea for simplicity sake, but then forgot to remove the extra 2 piezos).
manirbangladesh
I used your code for my 10 piezo drum. All worked well. I will be very happy to know if i can change the treshold of each individual piezo by following line ?
""""const int THRESHOLD = {5,6,8,4,2,5,7,8,5,6};""""

What is the highest treshold value ?
Can you please tell me how i can separately change treshold, and limit the maximum & minumum velocity of each individual piezo?
If possible, write me another command line where i can adust the time amount for the gap between two stroke to avoid double triggering problem.
Thank you.

Liam Lacey
To create individual threshold values for each sensor you could create an array of const int values, e.g. const int THRESHOLD[NUM_OF_KEYS] = {5,6,8,4,2,5,7,8,5,6}; .

The highest value a piezo sensor can send using an Arduino is 1023, so threshold values could be anything up to this.

If you just want to 'clip' limit the velocity value, you could change the values on lines 'if (midiVelocityVal[count] > 127) midiVelocityVal[count] = 127;' to set a lower max value, and you could do the same kind of thing for the minimum limit e.g. 'if (midiVelocityVal[count] < 10) midiVelocityVal[count] = 10;'.

To limit how often a stoke can happen you could use the Arduino Millis Library (https://www.arduino.cc/en/Reference/Millis) to store a time for every stoke and then only process a new stroke if it's time is greater than the last time by a certain amount.
manirbangladesh
Thank you... i have learned a lot from you. Thank you again
manirbangladesh
Millis library is not a safe thing to try i think. Anything else?
I saw padcycles in some sketch. I think it's about avoiding double triggering. I am not sure though. I tried Google. Didn't get enough learning about that term.
manirbangladesh
Hello Again...
I have been playing my DIY arduino midi drum for a year.
your code works flawlessly. Recently i have decided to use a foot switch instead of using 2 separate pads for closed & open hat.
I use Arduino meda...Can you please guide me how the momentary switch should be wired to my arduino ?
And what modification i have to make into my current code for activating the switch functionality ?
My current Code is given below...

/*
Midi drum ..with 10 piezo.. no pedal(2 separate pad with 2 separate piezo for closed hat and open hat), Kick,snare, open hat, closed hat, tom1, tom2, tom3, crash1, crash2, ride
*/

#include
MIDI_CREATE_DEFAULT_INSTANCE();

//========================================================================================

//Set this value to the number of keys/piezos you are using
const int NUM_OF_KEYS = 10;

//Adjust this value to change the sensitivity of the piezos
const int THRESHOLD = 10;

//Set this value to the number of microseconds you want each MIDI note to last for
const int NOTE_LENGTH = 50;

//Adjust this value to set the range of MIDI note velocity values
const int VEL_SENSE_VAL = 10;

//Change this number to set what MIDI channel the MIDI notes are set to
const int midiChan = 1;

//Change these numbers to set what MIDI note number each key/piezo will send.
//Also make sure that the total number of numbers here matches the value of NUM_OF_KEYS
const int midiNote[NUM_OF_KEYS] = {36, 38, 60, 61, 49, 52, 48, 47, 43, 84};

//Change these values to set which analog input pins you are using
//Also make sure that the total number of values here matches the value of NUM_OF_KEYS
const int triggerSensor[NUM_OF_KEYS] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9,};

//=======================================================================================

//Variables for storing certain values
int triggerVal[NUM_OF_KEYS] = {0};
bool noteIsOn[NUM_OF_KEYS] = {false};
int midiNoteTime[NUM_OF_KEYS] = {0};
int midiVelocityVal[NUM_OF_KEYS] = {0};

void setup()
{
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(115200); //REMOVE THIS LINE IF USING HIDUINO INSTEAD OF HAIRLESS
}

void loop()
{
//repeat the below code for each anaolog input/piezo sensor
for (int count; count < NUM_OF_KEYS; count++)
{
//read the piezo value
triggerVal[count] = analogRead(triggerSensor[count]);

//if the value is over the threshold and there isn't currently a note on for this piezo
if (triggerVal[count] > THRESHOLD && noteIsOn[count] == false)
{
//get a velocity value based on the value
midiVelocityVal[count] = triggerVal[count] * (127.0 / 1523.0);

//increase sensitivity
midiVelocityVal[count] *= VEL_SENSE_VAL;

//make sure we don't go out of range
if (midiVelocityVal[count] > 127)
midiVelocityVal[count] = 80;

//send a MIDI note-on message
MIDI.sendNoteOn (midiNote[count], midiVelocityVal[count], midiChan);

//flag that the note is on
noteIsOn[count] = true;

//start a timer for the note to be on for
midiNoteTime[count] = NOTE_LENGTH;
}

//if the note is currently on
if (noteIsOn[count] == true)
{
//reduce the time value by 1
midiNoteTime[count]--;

//if time value equals 0
if (midiNoteTime[count] == 0)
{
//turn off the note
MIDI.sendNoteOff (midiNote[count], 0, midiChan);
noteIsOn[count] = false;
}

}

}

//pause the loop
delay(1);
}

manirbangladesh
can you help...?
I want to add a momentary switch as a foot pedal which will triggers note between 61 & 60 ( Closed & open HiHat). Thank You

Want to join the discussion?

Create an account or login to get started!