top of page

ESP32 Internal Sensor

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.


  1. an ESP32 microcontroller

  2. a Micro-USB type B to USB type A (Male-to-Male)

  3. Male-to-Male Jumper Wires

  4. Breadboard (optional)

  5. 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.

ree

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.


ree

ree

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.


ree

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


bottom of page