Earlier, we published a theoretical article named How to Build ESP32 Arduino Glass Touch Switch With LED. Here is How to Develop Your Own ESP32 Arduino Glass Touch Button in Cheap DIY Way and Calibrate it to the Best Result. Minimal resources needed for this project. In future, we will improve this thing with backlit LED. The above-linked article will give you a link to Espressif GitHub resources.
The fundamental about using metal electrode with glass top is keeping the resistance too low i.e. ESP32’s touch pin and the metal electrode should be as close as possible. Also, the metal electrode made of gold, copper, silver will work better than aluminium. For this project, we used ordinary aluminium foil.
NXP PCF8883 IC is a P-type MOSFET which will offer more advanced features than ESP32 when the coding part is not possible to deploy. Generic TTP22301 IC another similar IC. In a separate article, we will discuss how to develop a similar touch button with basic electronic components. Touch button created in this way with ESP32 will offer more ways to control than just touching, for example using Alexa with Watson IoT Platform, IR remote control and so on.
---
ESP32 Arduino Glass Touch Button : Calibration
You need just the ESP32, Arduino IDE, aluminium foil to create electrode and a piece of glass. ESP32 has onboard LED on Pin 2. ESP32 has 10 capacitive touch pins. These pins can be easily integrated into metal pads. You should cross-check this list from the illustration :
TOUCH0 = pin 4
TOUCH1 = no pin
TOUCH2 = pin 2
TOUCH3 = pin 15
TOUCH4 = pin 13
TOUCH5 = pin 12
TOUCH6 = pin 14
TOUCH7 = pin 27
TOUCH8 = pin 33
TOUCH9 = pin 32
We will later discuss how to use touch to wake up ESP32 from deep sleep. In the Arduino IDE, we can go to File > Examples > ESP32 > Touch and open the TouchRead sketch. The below code will help to calibrate :
1 2 3 4 5 6 7 8 9 10 | void setup() { Serial.begin(115200); delay(1000); Serial.println("ESP32 Touch Testing"); } void loop() { Serial.println(touchRead(4)); delay(1000); } |
The T0 pin corresponds to GPIO 4. For the above code, you’ll connect the pin 4 with the aluminium foil as the metal electrode. In the Arduino IDE, go to Tools and open the Serial Monitor at a baud rate of 115200. Touch it a few times to watch the change in value. Close the serial monitor, go to Tools > SerialPlotter. Touch it a few times again to watch the change in value.
The initial value and value while touching the naked pin varies. For my ESP32, the maximum value when not pin touched was 73. Touching the naked pin (number 4), made the value drops to near zero. Touching pin connected aluminium foil made the value down to 10. Now, place a glass over the pin connected aluminium foil. You will notice that upon touching the glass, the value drops to near 60.
In my case, 60 is the cut-off value. It is too high considering the max value is 73. For real production, we need to tweak the material, connection to bring the touching glass event lower to 50 or lesser. That value is “threshold value” for our next part.
Control LED with ESP32 Arduino Glass Touch Button
With the same setup, we can light up the onboard LED of ESP32. Adjust the “threshold value” :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | const int touchPin = 4; const int ledPin = 2; // change with your threshold value const int threshold = 65; // variable for storing the touch pin value int touchValue; void setup(){ Serial.begin(115200); delay(1000); // give me time to bring up serial monitor // initialize the LED pin as an output: pinMode (ledPin, OUTPUT); } void loop(){ // read the state of the pushbutton value: touchValue = touchRead(touchPin); Serial.print(touchValue); // check if the touchValue is below the threshold // if it is, set ledPin to HIGH if(touchValue < threshold){ // turn LED on digitalWrite(ledPin, HIGH); Serial.println(" - LED on"); } else{ // turn LED off digitalWrite(ledPin, LOW); Serial.println(" - LED off"); } delay(500); } |
This ends this guide. You can see that one ESP32, a glass panel and one 8 channel relay effectively works as a replacement of the mechanical switches extending our previous guides. There are a lot of advantages of using this kind of switch instead of mechanical including being electric shockproof and glass can be easily cleaned. Cost of ESP32 with a glass panel, one 8 channel relay and power supply to ESP32 will be around $16. That is $2 per touch switch. If we used IC, our cost would go far high up.
We will discuss later how at easy cheap cost you can create LED backlit icons which will work over the glass.
Tagged With https://thecustomizewindows com/2019/07/esp32-arduino-glass-touch-button-cheap-diy-method/ , esp 32 touch button , esp32 touch , esp32 touch button , example esp32 button , smart glasses with esp32