Making Distance Sensors: trigger the Touch Board with proximity
Learn how to trigger the Touch Board over distance.
The Touch Board works great out of the box to detect… well touch! But it’s also possible to trigger the sounds from a distance, which we call proximity mode (which is really just increasing the board’s sensitivity). This tutorial will take you through an example and explain the principles.
The Touch Board can work without touch too. Try distance sensing (proximity).
Use the grapher to visualise the sensitivity and precision of the Touch Board's sensors.
Ready to put your own code on the Touch Board? Follow this tutorial to get started.
To begin you will need:
1 x Electric Paint 50ml
1 x Touch Board
1 x USB A to USB Micro B cable
1 x Computer running Mac OS, Windows or Linux
1 x Speaker or Headphones
1 x A4 sheet of paper (preferably over 260 sm)
1 x Masking tape
1 x Paint brush
Prepare your proximity pad(s)
Using masking tape, start by taping out a proximity pad approximately 10cm square onto a piece of heavy stock paper.
Leave a strip about 1cm wide running off to the side to allow easy connection to the Touch Board.
Once you have the pattern taped out, paint it with Electric Paint and leave it to dry.
This should take about 15 minutes, but you can speed it up with a hairdryer if you are in a hurry.
Be careful not to let it crack in this case – forcing the drying process makes this more likely.
Carefully remove the masking tape while the paint is slightly wet to avoid tearing off the paint.
Upload the Proximity code to the Touch Board
Plug the Touch Board into your computer via USB and plug in your headphones or speaker. Make sure that the power switch on the board is set to ON.
Open the Arduino IDE and open the Proximity demo from your Sketchbook – you’ll find it under File→Sketchbook→Touch Board Examples→Proximity_MP3. Ensure that Bare Conductive Touch Board is selected under Tools→Board and that the correct serial (CU) port is selected under Tools→Port.
With all of the correct settings selected, click File→Upload to push the code to the Touch Board.
The RX and TX LEDs will flash on the Touch Board and the Arduino IDE should say “Done uploading.”
Connect the Touch Board to the pad
Now that we have the code on the board, we can go ahead and connect the (now dry) pad to the board.
You can either do this using a crocodile clip cable, or by cold soldering with a small blob of paint to connect directly..
We like using the crocodile clip for prototyping as it is easier to remove if we want to make any changes.
It doesn’t matter which electrode you connect it to, provided that there is a file named appropriately to the electrode on the microSD card.
For example, TRACK000.mp3 if you are connecting to electrode 0 or TRACK011.mp3 if you are connecting to electrode 11.
For more details on naming the tracks and uploading your own sounds to the microSD card click here.
Trigger the track!
Make sure that your workspace is neat and that the connection between the board and the pad is short and doesn’t snake over other cables (this can cause false triggering).
Now press the reset button on your Touch Board and wait about 10 seconds – 8 seconds for the board to leave “bootloader” mode (the red L LED will pulse) and another 2 seconds for the board to adjust to the new pad.
Try triggering the track by waving your hand slowly over the pad about 5cm from the pad – you should hear your track play!
If you are having trouble with getting this to work, don’t panic! Here’s a checklist to help debug things:
– Did the code upload correctly? If not, check out the Uploading FAQ.
– Are your speakers powered, if they need to be?
– Is your wiring neatly organised, not overlapping anything else?
– Is your pad correctly painted with no gaps? You can check this with a multimeter – the pad should read a few kΩ from end to end.
Spot the difference
This code is basically the same as the Touch MP3 code that ships with the Touch Board. The only difference is that the threshold for detecting a touch has been decreased (along with the threshold for detecting a release, for balance).
If you have the Touch MP3 code to compare against, you can see that lines 75-84 in Proximity MP3 have been added in, but the rest are the same.
All we have done is decrease the touch threshold from 40 (default) to 8 and the release threshold from 20 (default) to 4.
You can view code line numbers in Arduino easily by selecting “Display line numbers” in the Arduino→Preferences menu.
Note that the release threshold must ALWAYS be less than the touch threshold.
You could decrease these further to increase sensitivity, if you like, but be careful. More sensitivity means a more noisy (and possibly erratic) signal.
Ideas for taking this further
So now you have one pad working via proximity, what next?
You could paint up a set of pads like Bibi did for the Kickstarter video and change the sounds on the microSD card to be drum noises! Or you could try and increase the sensitivity even further, to see what that does.
You could also try setting individual thresholds for each electrode.
You can call MPR121.setTouchThreshold(0, 10); to set electrode 0 to have a touch threshold of 10 or MPR121.setReleaseThreshold(2, 5); to set electrode 2 to have a release threshold of 5.
Play around and see what effects you can create. Different pad shapes and sizes will have different effects too, so you can experiment with those. Don’t forget to reset your Touch Board every time you connect a new pad though.
And do share your project! Send your videos and photos to firstname.lastname@example.org so we can post them on our site for the world to see.