ESP32 is a multipurpose system on a chip. My team built a touch sensor and a magnet sensor for our Embedded System class weekly assignment.

To program our ESP32, we used Arduino IDE. So first thing first, we have to install ESP32 add-ons successfully.

How to Make A Touch Sensor

The board pinout of ESP32 has ten different touch sensors. They are the pink buttons in the following diagrams. Each of them corresponds to one GPIO. Those GPIOs can detect variations in anything that has an electrical charge, including human skin.


We used the code provided by this source.

We connected a jumper wire to GPIO 4. Then, we connected the ESP32 to our laptop using a USB cable. Next, we uploaded the code after making sure we have selected the right board and COM port.

In the Arduino window, we opened Serial Plotter. When we touched the metal part of the jumper wire, the values displayed in Serial Plotter changed. We noticed that when the wire wasn’t touched, the values displayed would be around 70, and around 10 when it was touched.

We integrated an LED light to our circuit. This is the code we used.

We determined the threshold to be 20 since we already knew the range of values from the previous tries.

With this new circuit, our LED would light up every time the wire was touched.

How to Make A Magnet Sensor

Turns out ESP32 already has a built-in hall effect sensor. It can detect a change in the magnetic field surrounding it.

Here is the code for our magnet sensor.

We connected the ESP32 to our laptop using a USB cable. Then, we uploaded the code after making sure we have selected the right board and COM port.

Through the Serial Monitor we opened in the Arduino window, we figured out that when the magnet was far away from the sensor, the values displayed was around 20. When the magnet was attached to the sensor, the values changed to around 50. We have known from the reference that attaching different magnetic poles to the sensor would result in a negative value. Sadly, our magnet was one-sided. Next time, we are going to try using another magnet with both poles exposed.

We decided to code for the integration of LED light to our circuit. We determined a certain value for the threshold. Here is our code.


After creating a proper circuit and uploading the code, we could observe the LED lit up when our magnet was close to the sensor.

That was how we made a very simple touch and magnet sensor using ESP32. There are tons of tutorials on the internet that has helped us tremendously. We are looking forward to creating more projects using ESP32 and explore the world of Embedded System.