A touch-sensitive lamp

Hello and welcome to a new blog where we want to take a closer look at an interesting, built-in function of the ESP32 chip. This refers to the touch-sensitive pins of the ESP32, the so-called "touch pins". With the help of one of the possible ten "Touch" sensitive pins, we are now building a low-voltage table lamp so that we can switch it on and off by simply touching the lamp! However, since we work here with touchable, current-conducting surfaces, knitting applies when setting up or replicating this manual:

Any! Part of the presented circuit, DARF! necessarily only come into contact with protective low voltage. (5 voltS DC voltage). The lamp to be switched may have a maximum operating voltage of 24 volts DC voltage. Furthermore, the lamp must have a galvanically detaching protective small voltage transformer, which is VDE tested and bears a CE mark.

Please also familiarize yourself with the relevant VDE regulations and dangers of electric current before you start replicating the circuit.

As parts for our current project, in addition to a lamp with 12 volt LED bulbs, we only need the following components:

The circuit is wired as follows:



The Sketch code for our lamp is also quite clear thanks to the integrated touch sensitive hardware of the ESP32. We use the API function "touchRead" available exclusively at the ESP32 for reading the integer values. The read values depend on the connected sensor surface and just one touch of this surface. In order to be able to work generically with as many sensor surfaces as possible, I have deliberately refrained from inserting static values. Instead, I work with relations. Upload the following code to your ESP32:



Touch0 is T0 which is on GPIO 4.

Int touchvalue = 5;
Int touchvalue_NOT_touched = 5;
Bool Light = False;
Bool LightSwitched = False;

Void Setup()
{   pinMode(21, Output);   Delay(150);   touchvalue = touchRead(T0);   Delay(150);   touchvalue = touchRead(T0);   Delay(150);   touchvalue_NOT_touched = touchvalue;

Void Loop()
{   touchvalue = touchRead(T0);   If ((touchvalue < (touchvalue_NOT_touched - 3)) || (touchvalue > (touchvalue_NOT_touched + 3)))   {     If (!LightSwitched)     {       Light = !Light;       digitalWrite(21, Light);       Delay(250);       LightSwitched = True;     }   } else {     LightSwitched = False;   }   Calibration, if needed   If ((touchvalue >= (touchvalue_NOT_touched - 1)) && (touchvalue <= (touchvalue_NOT_touched + 1)) && (!touchvalue_NOT_touched == touchvalue) && (!LightSwitched) )   {     touchvalue_NOT_touched = touchvalue;   }


Please ensure the correct installation of the 47 K Ohm resistor when installing, and short cables between the sensor plate and the pin G4 to which the sensor is connected.

Now I wish you a lot of fun recreating and a lot of friends with your sensor lamp. Write your ideas and wishes in the comments.

Esp-32Projects for beginners

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN