ESP32 has some useful inbuilt sensors like TOUCH SENSOR & HALL EFFECT SENSOR.

Temperature sensor is not yet implemented & not working in ESP32.

A total of 10 Touch sensors T0 to T9 are multiplexed with GPIO pins of ESP32.

Touch sensor T1 is mapped to GPIO0 , which is pulled low while uploading code, is NOT available for the user & a physical GPIO PIN is not available with ESP32 DEV KIT V1.

Other 9 touch sensors are available for the user.

Touch T0 is available at GPIO4 & multiplexed with AD2_0 . Similarly Touch T2 is mapped to GPIO2, multiplexed with AD2_2.

Check out the PIN Configuration as shown in image below.



Image 6


Let us test T0 touch sensor at GPIO4.

Just connect a male to male jumper wire at GPIO4 , which acts as our touch sensor.

Connect ESP32 to PC & note the COM port allotted.

Under Tools of Arduino IDE select the Board as ESP32 Dev Module & choose the right COM port.

Image 10


Under FILE –> Examples –> ESP32 –> Touch

Select the example sketch  TOUCHREAD.

Image 1


Image 8

This Sketch uses the touchRead() Function to read T0 sensor & prints the value on Serial monitor.

Upload the Sketch.

Press & hold the Boot button while you see connecting.. at the bottom of IDE.


Image 11


Image 12

Once the code is uploaded , open the Serial monitor of IDE

Select the Baud Rate as 115200

Random values are printed on serial monitor.

Touch the wire connected to GPIO4 (TOUCH SENSOR T0)

The value drops below 10 , when the wire pin is touched.

Image 13

Thus TOUCH SENSOR works as expected.

Image 3

Let us connect an LED  at GPIO15 through a resistor to Ground .

The male to male jumper wire acting as Touch sensor is at GPIO4.

Image 14

Modify the sketch accordingly.

Define the LED_PIN as 15  (GPIO15)

Under loop function we set a threshold value for T0 as 20. If the value drops below 20 then the LED is made ON , Otherwise OFF.

Image 001

Upload the sketch.

When you touch the sensor at T0 , the LED goes ON .

When T0 is not touched the LED is OFF.

Image 4


The next sensor is HALL EFFECT sensor which detects Magnetic field.

The Hall Effect sensor works on the principle of the Hall Effect of magnetic fields. The sensor will generate a voltage that indicates whether the sensor is in the proximity of a magnet or not.

From examples select the HallSensor sketch.

Image 2

This sketch uses hallRead() function & assigns the value to a variable, which is then printed on Serial monitor.

Image 002

Upload the sketch & open the Serial monitor.\

Set the baud rate to 9600. You can see some random values flowing in.Note that if the baud rate is not selected as 9600 , there will be no result seen.

Bring a magnet near  the ESP module .

You can see a value printed according to the strength of the magnetic field.


Image 5

If you reverse the poles of Magnet , you can see negative values.

Image 6

If you bring near a powerful magnet , then the result value will be higher.

Image 7

Instead of Serial monitor view , you can also see graphical representation.

Close the Serial monitor & then from under Tools select the Serial Plotter to see the graphical



Image 8

Video :


ESP32 #1 Arduino core installation