Project III : ESP32 Internal Sensor

Rayhan Naufal Luthfi
5 min readFeb 20, 2022

Welcome to my third project of ESP32. This project is a form of implementation of the knowledge that i got from Embedded System course. In this next project, we’re going to learn to use Internal Sensor that ESP32 has, which is Capacitive Touch Sensor, Temperature Sensor, and Magnet (Hall Effect).

#Required Components/Hardware

First things first we need to know what components are needed for this project. These components are just the examples I used for this project, you can use different types of components that you can find easily on the internet.

  1. ESP32 Development Kit
  2. Male to Male Wire Cable
  3. Micro USB Cable
  4. Breadboard
  5. LED Lamp
  6. Resistor 330 ohm
  7. Magnet

#Capacitive Touch Sensor

The first sensor we will try is the capacitive touch sensor. This sensor can sense a different kind of things that holds an electrical charge like human skin.

But the first thing we need to know is which pin has the touch sensor. We can see the details from this image

From the image, it can be seen that one of the pins that supports the capacitive touch sensor is GPIO15. Therefore, in this experiment we will use pin 15. And this is the result when you assembly the ESP32 and the cable

Now open arduino, type this code, and dont forget to verify and upload

// ESP32 Touch Test
// Just test touch pin - Touch0 is T0 which is on GPIO 4.
void setup()
{
Serial.begin(115200);
delay(1000); // give me time to bring up serial monitor
Serial.println("ESP32 Touch Test");
}
void loop()
{
Serial.println(touchRead(15));
delay(1000);
}

To see the result, go to Tools -> Serial Monitor and change the baud value to 115200, and this is the result

#Hall Effect Sensor

In the second experiment, we’re going to try the built-in Hall Effect Sensor that detect changes in magnetic fields of its surroundings. In this experiment we only need ESP32 and breadboard. The magnetic sensor located in the metal square on the ESP32.

Now open Arduino IDE, type this code, and dont forget to verify and upload

//Simple sketch to access the internal hall effect detector on the esp32.
//values can be quite low.
//Brian Degger / @sctv
int val = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = hallRead();
// print the results to the serial monitor:
//Serial.print("sensor = ");
Serial.println(val);//to graph
delay(1000);
}

To see the result, go to Tools -> Serial Monitor and change the baud value to 9600, and this is the result

As we can see, when the positive pole brought closer, the result shows positive up to 300 and when the negative polo brought closer, the result shows negative and up to -150.

#Temperature Sensor

In the third experiment, we’re going to try the temperatue sensor. ESP32 has a built in temperature sensor to monitor its core temperature. So the only equipment we need is ESP32. We only need to upload this code and run the serial monitor with 115200 baud.

/* 
* https://circuits4you.com
* ESP32 Internal Temperature Sensor Example
*/
#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
//====================================================
// Setup
//====================================================
void setup() {
Serial.begin(115200);
}
//====================================================
// Loop
//====================================================
void loop() {
Serial.print("Temperature: ");

// Convert raw temperature in F to Celsius degrees
Serial.print((temprature_sens_read() - 32) / 1.8);
Serial.println(" C");
delay(1000);
}

And this is the result

#Variation of The Built-in Sensor

As a form of creativity, i want to combine my first project with Capacitive Touch Sensor. I’m going to make a modification on the breadboard like this

I designed the code and the circuit so when i touch the tip of the blue wire, the right LED will blink and when i don’t touch the tip, the left LED will blink. This is the code that i used,

// set pin numbers
const int touchSensor = 15; // the number of the touchPin
const int led1 = 22; // the number of first LED pin
const int led2 = 5; // the number of second LED pin
// change with your threshold value
const int threshold = 50;
// variable for storing the touch pin value
int touchValue;
void setup() {
Serial.begin(115200);
delay(1000);
// initialize the LED pin as an output:
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
}
void loop() {
touchValue = touchRead(touchSensor);
Serial.print(touchValue);
if (touchValue < threshold){
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
Serial.println(" - LEDs on");
}
else{
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
Serial.println(" - LED off");
}
delay(500);
}

And this is the result,

And so that’s my experience in working on the third project. Thank you for reading this article and I hope this article can be helpful for people who want to start trying to learn ESP32.

Rayhan Naufal Luthfi
Information System Technology ITB 2020
18220048

--

--