Let's Make Robots!

Arduino based PC Footswitch

Uses the ATMega32u4 of the Pro Micro to pass keyboard commands to a PC based on what footswitch is pressed.
The sacrifical banner stand1.1 MB
taking shape1.08 MB
Footsie.jpg1.73 MB

I am in the process of putting together a project for another hobby of mine; music. I am a trombone player, who dabbles with many many other instruments, playing in many types of bands. I play in a Band called Dennis, in addition to Westoe Brass Band, and also play for many others as and when duty calls or opportunity knocks.

Recently, along with a like minded friend, I have started to conjure up a nice little portable recording rig to allow us to record whenever and wherever we like, whether it be on lunch breaks at work, at home etc. Essentially freedom to record without the studio constraints is the aim of the game.


Concept - one briefcase-like case (flightcase, pellican case etc, all dependent on what i can acquire) with one IEC socket will be plugged in to provide power to the rig (one laptop and two fire wire interfaces).

Foot controller - Bearing in mind most brass instruments take two hands to wield and we may be recording on our own, I want to add some kind of foot control system to the build, to enable ease of use. Having read about the ability of the ATMega32u4 to appear and function like a HID such as a keyboard my mind set to work; why not use one to send keystrokes to the Laptop with footswitches?

Keyboard shortcuts could be configured using something like AutoHotKeys, allowing full control of the laptop and the recording software's features while being able to concentrate on the task at hand.

***Pro Micro 32u4 ORDERED - AND RECEIVED!***

I'm thinking that it will be quite a simple circuit for the box; all the switches will be wired up to 5v, and the other side of the switches will be wired to pins on my new pro mini and to ground (via 10k Resistors to avoid creating a short).

Unsure of how yet but when the Pro Mini detects a change in state a void for that button will send the keystrokes to the laptop.


***24/07/2014 UPDATE***

Managed to get my little Micro firing some "IT'S ALIVE!!!!!!!" text to an open text document. I don't have any switches purchased for the build yet, so just using a jumper to bridge 5v to my data pin/ground.  Some switches would be lovely!

Next step is to add more buttons to my rudimentary code and also increase functions it carries out.

I'm also looking to add a little 16x2 display (using the I2C converter board to save pins), and also a selector switch to allow multiple layers to be assigned to the buttons.



It has been a very long time since I've been able to do anything remotely fun with any of my projects due to work and band commitments over the last month or two. While work has not let up i am hoping to get some more of this project done!

I have purchased 5 momentary footswitches and have been given a 6-position selector switch; if I can these working I'll be able to have 30 commands at my disposal. I have my pro micro breadboarded and 4 'switches' set up, plus have decided to try and incorporate 2 16x2 lcd displays to give me more room to display button functions etc.

In order to save pins with the selector switch i am going to use a series of resistors in conjunction with the selector switch to return different values to one analog pin based on which pin is selected.

Coding work is underway too - I'm looking to use some arrays to map out what void should be triggered based on the current selector position and what button has been pressed.

I am aiming to have my code check what position the selector switch is in and what button has been pressed and then return a function name from an array of strings. Then using some if, else if and else statements fire the intended key commands.

The LCD screens will display the array information for each of the buttons based on the selector switch too.


The use of arrays,, i2c screens and buttons etc is something  completely new to me, so it's a long journey to get in functional!



***UPDATE 08/08/14***

Good news - an enclosure has been found! I found an old portable banner stand that was being thrown out, so i saved it from the skip, took out the innards and essentially cut it in half. I have cut holes for the 5 switches and potentiometer, however I'm contemplating getting a bigger screen to put in the project.


Before and after hacking :-)

The switch holes need a bit more work but i have ran out of time - that will happen Monday.


Code has took a big step forward today too - Now the code checks the values from the pressed button and also the selector switch and returns a string from the Array. It then processes the key commands associated to that string. Wahey!!!!

Now i just need to sort out the resistor series for the the selector switch, as i currently have the code just defaulting to position one for now.

Once that is done i will wire up my switches to my Pro Micro, add the USB port to the enclosure etc and then give it a go!

Then screen work shall commence...


*** UPDATE - 15/08/2014 ***

Here is a pastepin link to my current sketch so far:


As it stands It all works nicely - apart from the for loop checking the button pins.

It will detect button presses, however only sequentially - it's as if it sits and waits for each of the buttons to be pressed before moving to the next button.

My head hurts! Any suggestions would be greatly appreciated (thanks already to lumi and bdk6 for helping!)



More work to follow hopefully!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I am glad that you solved your code problem.

However, since reading your project the first time I am thinking "how the hell will Craig push those buttons with his foot/toe (considering you don't wear shoes.

Do you have some pedals which you use to attach to that buttons?

PS: I once was doing the sound and light in a rock band, so I know what a foot switch has to look like...but yours does not look like what I remember :-)

Cheers buddy - the more i fix my code the more I want to add to it, ha ha!

Once I have my debouncing coding sorted i want to add code to differentiate between a button tap and a button being held etc to increase functionality. Plus my 20x4 lcd screen arrived today, so also going to start adding the menus to it too.


As for pressing the buttons they work well with all kinds of footwear - not a fan of barefoot :-)

The buttons themselves are quite common on a lot of guitar stomp boxes; while the likes of Boss and Digitech tend to build the button into the pedal chassis a lot of other pedal companies use the style of switch I have used. One of my favourite pedals I own is the Yamaha Magicstomp, and that features three of the buttons I have used for switching patches and suchlike.

My only gripe with my current design is the buttons are a bit close together. It's not really an issue as long as I'm careful, however I am hoping to create a proper enclosure with some leds etc in. Once I have the thing working properly, that is!

Well, the code is never finish, there is always something you need/want to improve.

For the buttons, yes they look a bit small on the picture but if you say they are common used for that purpose it's ok. Yep, taking a look at my feet it might be nearly impossible for me to only press one button with shoes :-D

You are right buddy, coding is never finished. That's what I love about it!

The buttons are quite small, however very robust :-)

I think when I rebuilds menclosure I'll be aiming to put the buttons in a zig zag pattern (two at the top, three at the bottom) rather than all five in a line - that way I'll be able to make them more shoe-friendly and increase the space between them whilst not having to radically increase the size of the controller.

Once the controller is rebuild I'll be designing a case for the laptop, firewire interfaces and power supplies to live in and then signing this one as complete - then back to more robot like projects! :-D

Made the updates that bdk6 suggested to my code, and it now works!

The line that updates the PreviousState was indeed trapped inside the if statement instead of being after it in the for loop.

In my defence I was only a line away from having it in the right place :-)


Now to finetune the code and add in some debouncing to stop the button presses triggering more than once in error, and adjust the values for my selector switch.


Today is a good day!!!

My wife will get very angry! :-)

Congratulations!  Glad you got it working.

Ha ha, you are safe for the time being. If you help me out any more i can't be held responsible for my actions ha ha!

This line: 

int ButtonPins[]={4, 5, 6, 7, 8};

defines an array of 5 ints.  An int on Arduino is 16 bits, or 2 bytes.  

This line:

const int ButtonCount = sizeof(ButtonPins);

sets the constant ButtonCount to the size IN BYTES of the ButtonPins array.  5 ints is 10 bytes, so ButtonCount = 10.

This line:

for (int ThisPin = 0; ThisPin < ButtonCount; ThisPin++) {

causes the for loop to count from 0 to 9.  The body of the for loop tries to access array elements from 0 to 9.  But your array only goes from 0 to 4.  The C compiler lets you do that, and will access whatever is in memory beyond your array, which for your intended purpose is simply garbage (it probably isn't really "garbage". It is some othe part of your program. but it "seems" like garbage)

You can fix that part by using sizeof( ButtonPins) / sizeof(int);

There may be other problems. I haven't looked any further yet.

Thanks bdk6 - not just for spotting the error but explaining it too.

That explains why it is not leaving the loop after the fifth button was pressed.

Will edit and upload the sketch, see if that solves my issues!


Thanks again, bdk6!

I saw in the shoutbox that fixing that didn't fix the overall issue.  How about posting the rest of your code so we can have a look.  You'll get there!