Learn how to use the Touch Board's powerful proximity sensing functions
The Touch Board works great out of the box to detect touch! But it's also possible to reprogram the Touch Board to create proximity sensors that allow you to control your project just by waving your hand or approaching the sensors. We call this proximity mode. This tutorial will take you through an example and explain the principles behind this powerful feature.
We love it when you share your projects! Post your project on Instagram, YouTube, or Twitter, and make sure to tag @bareconductive or use #bareconductive. You can also send your videos and photos to firstname.lastname@example.org so we can post them on our site for the world to see.
You will need:
1 x Electric Paint 50ml
1 x Touch Board
1 x USB Micro B to USB A or USB C (depending on your computer's USB port type)
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 Paintbrush
Step 1 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. Drying 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.
Step 1 Optional - Use Printed Sensors
Instead of making your sensor, you can also use our Printed Sensors to trigger the track with proximity. You can customize the Printed Sensors, their pattern is ideal for proximity sensing, and we seal them to prevent smudging. In the steps below, make sure to connect one Printed Sensor with a crocodile clip to a single electrode on the Touch Board.
Step 2 Upload the Proximity code to the Touch Board
Once you're ready to reprogram your Touch Board, plug your board into your computer via the USB cable and plug in your headphones or speaker to the Touch Board. Set the power switch on the board 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. Select Bare Conductive Touch Board under Tools→Board. Make sure that the correct serial (CU) port is selected under Tools→Port.
With the correct board and serial port 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."
Step 3 Connect the Touch Board to the Pad
Now that we have the code on the board, we can connect the (now dry) pad of Electric Paint (or Printed Sensor) 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 one of the Touch Board's electrode's directly to the pad of Electric Paint. 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 sounds to the microSD card, take a look at the tutorial here.
Step 4 Trigger the track!
Ensure 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!
Step 5 Demonstration video
Take a look at this short video to get an idea of how proximity mode works.
Step 6 Having trouble?
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 organized, 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.
Step 7 Spot the difference
This code is mostly 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 aware that more sensitivity means a more noisy (and possibly erratic) signal.
Step 8 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 our 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.
Step 9 More ideas!
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. As a reminder, to reset your Touch Board you need to 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.