HELP.How to wire Momentary footswitch to Arduino Mega 2560 as Hi Hat controller?

Hello Everyone, Having a hard time , stressed , really frustrated and about to quit the project. Don’t have enough money to buy such expensive electronic drums, So I’ve heard this arduino for your DIY projects specially drums in a low budget… I’m done with the rest of the pads but except with this Hi hat controller. Pls. help me how to wire a momentary footswitch to an arduino mega 2560 based on the attached code… I am just new to this code and arduino projects… and I do really have a hard time analyzing how was the creator of this code wired his momentary footswitch to the Arduino mega 2560… Hopefully anybody can help me showing a diagram with a breadboard photo showing the wirings from the push button to the ardiuno for better understanding cause I really don’t know how to read electronic schematic diagrams…By the way… I get this code from: https://deadastronaut.wixsite.com/effects/copy-of-nano-8-midi-drums… Thanks :slight_smile:

16_pad_kit.ino (7.83 KB)

16_pad_kit.ino (7.83 KB)

images.jpg

well in the link you mention they describe where things go

You have a socket connected to the SW1 pins on their board. They mention

you insert the momentary switch within the jack cable (with a long enough cable so that in becomes indeed a foot switch) as in the picture. The tip of the Jack has to be the positive and the sleeve the GND.

in the code then they mention

hihat_switch = (((hihat_switch << 1) | digitalRead(3)) & 3);

so I would assume the switch is connected to digital pin 3 of your Arduino Mega (not the Analog 3).

Hi Sir J-M-L,

Good Day!

thank you for your quick reply sir,I really appreciate it… I will try this out… :slight_smile:

is there any resistors would be needed to connect either on the sleeve and ground wires?
is it possible also to replace my momentary footswitch with a TCRT5000? how would this TCRT5000 be connected to an arduino to make it function?.. I guess this TCRT5000 needs a power to make it function.

Well the author did not even take the time to set the pin mode as input (it’s the default though) but did not use input pull-up…

The code

 unsigned long currentTime = millis();
 
 if(currentTime > (switch_pressed + 2))
 {
 hihat_switch = (((hihat_switch << 1) | digitalRead(3)) & 3);
 if(hihat_switch == 2){
   noteFire(22, 127);  
  switch_pressed = currentTime; 
   }
 if(hihat_switch == 1){
   noteFire(17, 127);  
  switch_pressed = currentTime; 
   }
   
 }

is not the best ever and I’m not totally sure how this works regarding the 2ms threshold and the bit shifting that will still propagate but probably the loop is fast enough to wipe the 8 bits quickly to capture button press

The timing test would be better written as

 if(currentTime - switch_pressed >  2)

Looking at this code, it seems he expects a HIGH when pressed so a pull down resistor would seem appropriate indeed so that signal properly reads as GND when not pressed and the long wire does not become an antenna

TCRT5000 is an IR very close distance / contrast detector usually used for line following

i suppose you would prefer a non contact switch, just hover over it to trigger? Distance is short, like less than 1 inch and this will be sensitive to other IR possibly floating around

That’s entirely possible, you have GND and 5v on SW1 so that could power your module but you would need a third wire for the digital signal to reach pin D3, so that changes a bit the design.

Thank you for your reply sir... I followed the author's video in this link FULL 16 PIEZO MIDI TRIGGER DRUM KIT. (test) - YouTube ... it seems that when he release the pedal after stepping, there is a un-natural sound of the hi hats...the sound or velocity during releasing the pedal is just the same as the velocity during hitting the Open hi hat Pad....

I’ve no clue what he is doing :slight_smile: