Turning On an LED with a Single Touch and Observing Hall Effect using ESP-32

Hi! I’m back with a story of my second Embedded System project. The course has been one of the most fun as it has this ‘learning-together-as-we-go’ spirit that I really like.

The second assignment consists of two separate projects: turning on an LED using a made-up touch pad and observing Hall Effect using a magnet.

Making the Touch Pad

To create a touch pad, we utilized ESP-32s built-in touch sensors, which are connected to its GPIOs (input/output pins). The picture below shows the anatomy of the microcontroller (My friends and I used the one with 36 pins, though). The capacitive touch sensors are marked by the color pink. They work by detecting the variations of electrical charge in stuffs, including human’s fingers.

The things you need to prepare for this project are as follows:

  • ESP-32 Board (NodeMCU E-32s with 36 pins in my case)
  • a USB cable (with microUSB end)
  • an LED (light-emitting diode) of any color
  • a breadboard
  • a 330 Ohm resistor
  • some jumper cables (the kinds used here are the male-female cable and male-male cable, or hetero and homo cables as me and my friends like to call it)
  • a laptop with Arduino IDE installed
  • a piece of aluminium foil (or not. I didn’t have any so I didn’t use it)

You can start with testing the capacitive touch sensor with a simple code and a jumper cable, or you can go straight to make the configuration involving the LED.

  1. Attach the female end of a male-female (hetero) jumper cable on GPIO4 on ESP-32, where touch sensor 0 is located (refer to the anatomy of ESP-32). Attach another one to GPIO16 (the one beside it).

2. Attach the resistor, the LED, and some jumper cables on a breadboard with the arrangement as shown below. You can also attach the ESP-32 if you want. Make sure the anode and catode of the LED is attached correctly.

3. Connect your ESP-32 board to a laptop with an installed Arduino IDE.

4. Use the code below to process the touch input into LED’s on mode. Compile and upload it onto the ESP board.

5. To test out the capacitive touch sensor, go to Tools > Serial Monitor, and set the baud rate to 115200. This is important as it determines the read process’ speed of the sensor. At other rates, the value might be unrecognizable (an array of ??????? in my experience). When you touch the male end of the green jumper wire, the number recorded (indicates the electrical charge detected) on the serial monitor should drop by a significant amount.

6. Now that the arrangement on the breadboard is correct and you’ve tested out the touch sensor on the ESP, your touch pad (the male end of the green jumper wire) should be able to light up the LED when it’s touched. To make it actually look like a touch pad, you could cover it with a piece of aluminium foil. I couldn’t get one during my trial so I didn’t. Here is how the result looked like, by the way.

The Hall Effect

Other than capacitive touch sensors that detect changes in electrical charge around them, ESP-32 is also equipped with a hall effect sensor located in its square metal lid that detects change in magnetic field. This sensor is usually used to detect proximity, calculate positioning, count the number of revolutions of a wheel, detect a door closing, and much more.

This project is simpler than the one with LED as you only need these things to work:

  • an ESP-32 Board
  • a USB cable
  • a magnet
  • a laptop with Arduino IDE installed
  1. First thing first, connect your ESP-32 board to your laptop.
  2. On Arduino IDE, compile and upload this program that uses the hallRead() function to acquire value of the Hall Effect.

3. After that, go to Tools > Serial Monitor and set the baud rate to 9600.

4. Hold/put a magnet around the metal lid. The value on Serial Monitor should change significantly when a magnet is near or away.

5. Here is the video demonstration of the Hall Effect value reading.

There it is! All done!

See you on the next Embedded System projects!