ESP32 Touch Sensor Pins - (ESP32 + Arduino IDE)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone and welcome back to my YouTube channel in this new tutorial I am going to show you how to use the touch sensors that comes with the esp32 board so this board comes with a few pens that we can use as touch sensors in this video we'll be able to control the built-in LED which is blue by touching the pen as you can see the LED turns on and when I release it it turns off so before we get started make sure to smash that subscribe button that helps me a lot and without any further Ado let's Dive Right In [Music] so the esp32 board comes with 10 capacitive touch sensors that we can use for some projects in this video we are going to check if we touch one of the pens which is a touch sensor in such case we are going to turn on the built-in LED that is connected to the gpio plane number two so if you look at the pin out diagram you see that we have some of the pens that are labeled as touch pins this one is touch zero and it is the GPA of pin number four we have touch one two three until number nine in this video I'm gonna show you how to use the touch number zero which is the PIN number four basically we have a built-in command that is called touch read we give it the pin number like four and it will return a value that changes whenever we touch the pen so let's open up the Arduino IDE here we have an empty sketch first I will read the value and print it on the serial monitor so let's go under the setup function and begin the serial monitor using serial dot begin which takes the baud rate like 115 200 and that's the best portrait for any sp-32 board then under the roof function you could use serial dot print line or println and in this parentheses we are going to print the value of the touchgrid function so let's write touch read and it takes the pin number like the pin number four which is labeled as touch zero in our case you could even use t0 instead of using the pin number by entering T then 0 and don't forget the semicolon now before we test this code we have to add a little bit of delay because the loop function is called over and over again very fast and will not be able to see the value so let's add delay which takes the number of milliseconds like 200 milliseconds now we can upload the code but make sure to plug in the USB cable of the esp32 board then we have to select it if you are using the new version of the Arduino IDE you could select the options from here like the port which is com6 then we can search for the esp32 board for me it is called node MCU 32s make sure to search for the board that you have and select the type then hit OK I highly recommend you to install the new version of the Arduino IDE because it's much much better anyways once you do that we can hit the upload button now it is compiling the sketch and if you get this message connecting you have to hold down the boot key and that will start uploading the code and once it's done we can test the project so make sure to open up the serial monitor so that we can see the values by selecting this button serial monitor or you could go to tools then serial monitor and here's the values for now it is 109 and to test the project we have to touch the pen which is the PIN number four or I will use this jumper wire and here's the pin number four now I will touch the other side and yeah the value goes below 30. and once I release it it gets back to 65 or 70. now we can check if the value is less than 50 or 40 we are going to turn the LED on otherwise we will turn it off so let's modify the code first we need to add a variable for our pen using int and let's call it led pen equals to so the built-in LED is connected to the jpio pin number two if you have another board with another number make sure to select it then under the setup function let's use pin mode which takes the LED pin and the output keyword now under the loop function we will check if the touch read function returns a value that is under 30 we are going to turn the LED on so we can add an if statement if that should read is less than 30. we turn the LED on using the digital write command this takes the LED pair which is number two and to turn it on we have to add High and that outputs a voltage from this pin to turn the LED on otherwise using else we turn it off using the same line of code so I will copy it then paste it but make sure to change this to low to turn the LED off and that's pretty much it so you see it's very easy to use the touch sensors and this is just one example but you could create as many projects as you want with this feature anyways let's upload the code using this button and hold down the boot key now it's uploading the code and once it's done uploading Let's test the project when I touch the pen you see the LED turns on and when I release it it turns off so it's working I think that's pretty much it guys for this video I hope you like it if you have any question or comment make sure to write it under the comment section down below and I will see you in the next one
Info
Channel: Enjoy Mechatronics
Views: 8,558
Rating: undefined out of 5
Keywords: enjoy mechatronics, how to, microcontroller, lessons, getting started, esp32 beginners, esp32, introduction, esp8266, beginner, learn, sketch, sensors, basic tutorial, gpio, pin, basics, touch sensor, sensor, esp32 tutorial, ESP32, esp32 introduction, esp32 arduino, arduino ide, randomnerdtutorials, random nerd tutorials, ESP32 Touch Pins with Arduino IDE, ESP32 Touch sensitive GPIOs Arduino IDE, Read ESP32 Touch Pins GPIOs, ESP32 TouchRead Arduino IDE function, TouchRead Arduino IDE ESP32
Id: waAv_fQ6wqY
Channel Id: undefined
Length: 7min 30sec (450 seconds)
Published: Mon Nov 21 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.