How to use proximity sensors
Learn how to use proximity sensors
Both the Touch Board and the Pi Cap have the same capacitive sensors. These capacitive sensors allow you to either have touch sensors, proximity sensors or even a combination of both. With the proximity sensors, you can choose between having an “on or off switch” or using the proximity sensing to gradually fade an LED on or off. In this tutorial, we are going to show you examples of each by using the Touch Board and our Printed Sensors. You can also use the Pi Cap and other conductive materials to achieve the same results.
When you use the Touch Board for the first time, it has the code “Touch_MP3” uploaded to it. If you have a look at the code you can find the lines that include “setTouchThreshold(40);” and “setReleaseThreshold(20);”. By setting these values, 40 and 20, the capacitive sensors become touch sensors.
In the video on the right, you can see how the LED turns on when we touch the sensor. To find out more about how to use LEDs with the Touch Board, click here.
"Switch" proximity sensing
By changing the threshold values, you can turn the sensors from touch to proximity sensors. So, instead of touching the sensor to light up the LED, you can approach the sensor with your hand.
The code for the board we use in the video has the settings “setTouchThreshold(20);” and “setReleaseThreshold(10);”. The video shows how we can turn the LED on or off with just approaching the sensor. To find out more about using proximity sensing as a switch, have a look here.
Proximity sensors through materials
With the proximity sensing, you can trigger switches from afar. You can use this sensing method to hide your sensors behind materials, like wood or plastic, and then touch the material to turn something on or off. This is a great way to create safe interfaces because all the electronics, i.e. the sensors, the board, and the connections, are behind the wood or plastic.
"Gradual" proximity sensing
There’s another way to make use of the proximity sensing of the boards. As an example, have a look at the “Prox_LED” code. When you now approach the sensor, you can change the LED’s brightness gradually, depending on how close or far away you are from the sensor. So there are two methods of using the proximity sensors, either “gradual” or “switch”.
The video on the right shows how we fade the LED on and off by approaching the sensor. To find out more about the code and this method, have a look at this tutorial here.
Using Electric Paint as sensors
When you are using Electric Paint as the sensor for proximity sensing, the design of the sensor becomes quite important. The form, shape and the amount of Electric Paint used can influence the performance of the sensors. We have a tutorial about sensor design here. Additionally, if you want to visualise the performance of the sensors, you can use the Grapher tool.
Using both touch and proximity sensors
It’s also possible to set some electrodes as touch and the others as proximity. In order to do so, you can include, for example,
within the Touch Board setup code to set only electrode 11 with the respective threshold values.