Test The Build-In Sensor

Andreana Hartadi Suliman
6 min readFeb 18, 2022

Ok guys, back with me again and the ESP-32 project. Today I want to tell you about the build-in sensor that will always be available on the ESP-32. In this article, I will test out the touch, hall effect, and temperature sensor. Before that do not forget to check the setup Arduino IDE tutorial.

Touch Sensor

Prepare these things :

  1. ESP-32

2. Micro USB cable

3. Bread Board

4. Male to Male Cable

First, let’s check which ESP-32 pins have a touch sensor.

Put male-to-male cable on ESP-32 pin which has a touch sensor on it, this time I choose number 15 pin.

Open the Arduino IDE and paste this code.

Before that make sure the board and port are correct.

Verify the code, then upload it.

Check the installed sensors, by pressing Tools → Serial Monitor.

Change the number in the lower right corner to 115200 baud according to the sketch.

Then it will show like this.

After all the steps are executed properly without any errors, then this is the condition for the male-to-male jumper legs and the Serial Monitor display.

When the number is stable, the foot has not been held, if the foot is held then the number will change in value and will be stable in that pattern. However, when the legs are released again, the numbers will return to the pattern of numbers at the beginning.

Variation of Touch Sensor

I do think that the touch sensor before is very simple. So I made some modifications on the breadboard.

I add 2 LED lamps, 2 pieces of 330-ohm resistor, and a few male-to-male cables.

Here is example of a simple circuit illustration using 1 LED.

Install the 330-ohm resistor vertically with the (+) LED pin and the other pin on the empty breadboard pin. Install the male-to-male jumper cable on the (-) LED leg vertically aligned and connected to the (-) pole of the breadboard. Install the male-to-male jumper cable vertically with a 330-ohm resistor mounted on the breadboard blank pin and the other leg mounted on the ESP-32 pin. Put the male-to-male jumper cable on the GND (Ground) and the other leg on the (-) pole of the breadboard.

Open the Arduino IDE and paste this code.

// set pin numbers
const int touchPin = 15; // the number of the touchPin
const int ledPin1 = 23; // the number of first LED pin
const int ledPin2 = 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); // give me time to bring up serial monitor
// initialize the LED pin as an output:
pinMode (ledPin1, OUTPUT);
pinMode (ledPin2, OUTPUT);
}
void loop(){
// read the state of the pushbutton value:
touchValue = touchRead(touchPin);
Serial.print(touchValue);
// check if the touchValue is below the threshold
// HIGH = LED ON
// LOW = LED OFF
if(touchValue < threshold){
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
delay(50);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
delay(100);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, HIGH);
delay(50);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
delay(50);
Serial.println(" - LED on");
}
else{
digitalWrite(ledPin1, HIGH);
delay(1000);
digitalWrite(ledPin1, LOW);
delay(1000);
digitalWrite(ledPin2, HIGH);
digitalWrite(ledPin1, LOW);
delay(1000);
digitalWrite(ledPin1, HIGH);
delay(1000);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
delay(1000);
digitalWrite(ledPin2, HIGH);
delay(1000);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
Serial.println(" - LED off");
}
}

Verify and upload the sketch. After there are no errors and the program has been successfully uploaded, the LED on this project looks like this.

Hall Effect Sensor

In this sensor, the tools needed are ESP-32, bread boards, and magnets.

Open the Arduino IDE and paste this code.

Verify and upload the sketch.

Check the installed sensors, by pressing Tools → Serial Monitor as in the touch sensor. However, because it uses a serial begin 9600, change the number to 9600 baud.

Then the serial monitor will display the following information when the positive pole is closer.

If the negative pole is closer, then it will look like this.

If the magnet is brought close to the ESP-32’s iron square, the experiment will look like this.

Temperature Sensor

In this sensor, the only tools needed are an ESP-32 and a breadboard.

Open the Arduino IDE and paste this code.

Verify and upload the sketch.

Check the installed sensors, by pressing Tools → Serial Monitor in the touch sensor. The number used is 115200 baud because the serial begins using that number. Then, the serial monitor will display the following display.

Here is the video testing the temperature of the ESP-32.

isn’t it fun?!

If you have any questions or advice about this tutorial, feel free to contact me through email at andreanahs29@gmail.com.

YAY, you reached the end of this tutorial. Hope you enjoy it, good luck :)

--

--

Andreana Hartadi Suliman

If we are afraid of failure, it means we have limited our ability. — Hi, nice to see you here. Have a good day!