ESP32 Internal Sensor
- Haje Noorjamani

- Feb 20, 2022
- 2 min read
Updated: Feb 23, 2022
In this article, I will tell you about my experience using ESP32 built-in internal sensor (touch sensor, hall effect sensor, and temperature sensor). This project is my third ESP32 project and it was given by my lecturers.
Prerequisites
I used Arduino IDE v1.8.19 in Windows 11 64-bit to write the code and upload the code to ESP32, you can download it in here. Just click on download, make sure it the right version and OS, and it will download a zip file. After the download is finished, extract the zip file and open the arduino.exe. It will open the IDE. You might use other IDE, but I recommend you to use Arduino IDE.
I also used some component that I bought at Jaya Plaza, electronic market located in Bandung. But you can get this component on online marketplace.
an ESP32 microcontroller
a Micro-USB type B to USB type A (Male-to-Male)
Male-to-Male Jumper Wires
Breadboard (optional)
Magnet
Step 1: Place ESP32 on Breadboard
This is an optional step. You can use female-to-male jumper wires if you don't have the breadboard, just make sure you can use the GPIOs.

Step 2: Connect the Jumper Wires to GPIOs
I connected the jumper wires to GPIO4 because there is touch sensor 0 in that, I used the 30 pins ESP32. You can connect to any other GPIOs as long as they have the touch sensor.


Step 3: Write and Upload the Code
I used Arduino IDE to write and upload the code. This is the code that I used:
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
int val = 0;
void setup()
{
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("ESP32 Internal Sensor Test");
}
void loop()
{
Serial.print("Touch Sensor: ");
Serial.println(touchRead(4)); // get value using T0
val = hallRead();
Serial.print("Hall Effect Sensor: ");
Serial.println(val);
Serial.print("Temperature: ");
// Convert raw temperature in F to Celsius degrees
Serial.print((temprature_sens_read() - 32) / 1.8);
Serial.println(" C");
delay(5000);
}Step 4: Serial Monitor/Plotter
After you upload the code, you can see if the sensor working or not by testing it and seeing the serial monitor. If you touch the jumper wires, the touch sensor value should changes. If you put magnet or magnetic field around the big metal lid of ESP32, the hall sensor value should changes. The temperature sensor detect the ESP32 temperature.

Step 5: Improve your project
You can use this sensor to make other project, such as turn on LED lights when touch sensor value over 100, etc. All you need to do is combine my second ESP32 project with this one and change the code works.

Comments