Programming "Touch Sensor" on an ESP32 board using the Ardiono IDE
Hello, again!
So last time, I wrote about trying out the Blink LED feature on an ESP32 Development Kit using the Arduino IDE. Today I am trying out the Touch Sensor feature that is provided on the ESP32 Example Files in Arduino IDE. This project is divided into two main segments which are: Trying out the Touch Sensor by itself and Lighting an LED using the Touch Sensor.
Segment 1 - Trying out the Touch Sensor
Okay, this first segment is actually an easier and simplified version of the second one, for the purpose of testing if the Touch Sensor on the Development Board physically works or not. If you are certain to immediately move on to the second Segment you can skip this one and scroll down.
Step 1: Hardware Requirement
Everything you will need is:
- 1 Laptop/PC
- 1 ESP32 Development Board
- 1 Male-Female Jumper Wire
- 1 MicroUSB cable
Basically, every software requirement needed is just the same as in the "Blinking program" I wrote before. If you haven't checked it out, you can click here and look for Step 2: Software Requirement then come back and continue down below:
Step 3: Circuit
Now, what we do is take the jumper wire and install the female end on a desired pin. This pin has to have a Touch Sensor feature which you can check out in a Development Board's datasheet. In this example, I am using pin number 4 which has the T0 Touch Sensor.
The Male end is going to be the input receiver where a "touch" will be sensed.
Step 4: Code
Next, we move on to the code that will make the Touch Sensor actually work. In the menu bar, go to FIiles > Examples > ESP32 > Touch > TouchRead. The following code will appear in a new window. Inside the parenthesis of the touchRead function, you can write the pin number you are using.
Step 5: Compile, Upload & Observe
Now we are ready to upload the program into the Development Board. Connect your Board to your laptop/PC. Don't forget to choose the correct Board and Port under Tools.
When you're done uploading, the Touch Sensor is activated and you can view the data recordings of the touch sensing using whether the Serial Monitor or Serial Plotter which you can find under Tools. The following recordings are the data I have recorded. The small numbers stand for higher intensity of touch and the bigger ones stand for lower intensity.
Note: Make sure to synchronize the speed number in your code to the number shown in the Serial Monitor.
Now we are ready to move on to lighting the LED using the Touch Sensor! Starting from the beginning:
Step 1: Hardware Requirement
What you need for this segment is a little bit more than before:
- 1 Laptop/PC
- 1 ESP32 Development Board
- 1 Male-Male Jumper Wire
- 3 Female Jumper Wires
- 1 MicroUSB cable
- 1 LED light
- 1 Resistor (330kOhm)
Step 2: Software Requirement
Once again: Basically, every software requirement needed is just the same as in the "Blinking program" I wrote before. If you haven't checked it out, you can click here and look for Step 2: Software Requirement then come back and continue to the next steps below.
Step 3: Circuit
Using the equipment you have prepared before, build a circuit like the one in the picture below. The red Female- Male wire is plugged to the DevBoard just like in the segment before and also used as a Touch Sensor input on pin 4.
Using the equipment you have prepared before, build a circuit like the one in the picture below. The red Female- Male wire is plugged to the DevBoard just like in the segment before and also used as a Touch Sensor input on pin 4.
Down below you can see me using the brown Female-Male wire which Female end is plugged on the Development Board on pin 18 to receive output instructions and Male end is installed on the breadboard. It is followed by the resistor and then the long leg of the LED (the anode).
Then I am using the black Male-Male wire to connect the short leg of the LED (the cathode) from the inner side of the breadboard to the outer side where it then meets the white Female-Male wire which leads to Ground on the Development Board.
Step 4: Code
Now we move to writing the code! In the first part of this code I set the pin numbers I am using. For input (the Touch Sensor) I am using pin number 4 and for output (lighting the LED) I am using pin number 18.
So, every time the Touch Sensor reads input values below 30 it will send an output instruction via pin 18 to the LED circuit.
Step 5: Compile, Upload & Observe
Finally, we are ready to upload the program to the Development Board. Connect your Board to your laptop/PC. Don't forget to choose the correct Board and Port under Tools.
Finally, we are ready to upload the program to the Development Board. Connect your Board to your laptop/PC. Don't forget to choose the correct Board and Port under Tools.
When you're done uploading, the Touch Sensor and the LED circuit are activated and you can view the data recordings of the touch sensing using the Serial Monitor which you can find under Tools.
This is the data I got, showing the input and outputs in every second recorded. When Touch Value recorded is under 30, output instruction is sent to the LED circuit lighting it up and "LED on" besides the Touch Value is printed on the screen.
Note: Once again, make sure to synchronize the speed number in your code to the number shown in the Serial Monitor.
That's it for today, see you next time!
Comments
Post a Comment