ESP32 - Force Sensor
The force sensor is called force sensitive resistor, the force sensing resistor, or FSR. This tutorial instructs you how to use ESP32 with the force sensor. In detail, we will learn:
- How the force sensor works.
- How to connect the force sensor to ESP32.
- How to program for ESP32 to read value from a force sensor.
Hardware Used In This Tutorial
1 | × | ESP-WROOM-32 Dev Module | |
1 | × | USB Cable Type-C | |
1 | × | Force Sensor | |
1 | × | 10 kΩ resistor | |
1 | × | Breadboard | |
1 | × | Jumper Wires | |
1 | × | (Optional) DC Power Jack | |
1 | × | (Recommended) Screw Terminal Expansion Board for ESP32 |
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Introduction to Force Sensor
A force sensor is a resistor that its resistance is in inverse proportion to how much force it is given. The more force gives to the sensor, the smaller the sensor's resistance is. The force sensor is good for application that detects physical squeeze, pressure. However, it is not good for the application that finds how many pounds of weight
Force Sensor Pinout
A force sensor has two pins. Just like a resistor, we do NOT need to differentiate these pins.
Wiring Diagram between Force Sensor and ESP32
- How to connect ESP32 and force sensor using breadboard
This image is created using Fritzing. Click to enlarge image
- How to connect ESP32 and force sensor using screw terminal block breakout board (powered via USB cable)
If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: How to Power ESP32.
How To Program Force Sensor
The resistance is in proportion to voltage. We can use the ESP32's analog input pin to measure voltage.
By connecting a pin of the force sensor to an analog input pin, we can read the analog value from the pin ⇒ voltage ⇒ resistance ⇒ force (all í in relative value)
ESP32 Code
Quick Instructions
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
- Copy the above code and paste it to Arduino IDE.
- Compile and upload code to ESP32 board by clicking Upload button on Arduino IDE
- Press the force sensor
- See the result on Serial Monitor. It looks like the below:.
※ NOTE THAT:
This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a force sensor. The ESP32 ADC is good for projects that do NOT need high accuracy. However, for projects that need precise measurements, please note:
- The ESP32 ADC is not perfectly accurate and might need calibration for correct results. Each ESP32 board can be a bit different, so you need to calibrate the ADC for each individual board.
- Calibration can be difficult, especially for beginners, and might not always give the exact results you want.
For projects that need high precision, consider using an external ADC (e.g ADS1115) with the ESP32 or using an Arduino, which has a more reliable ADC. If you still want to calibrate the ESP32 ADC, refer to ESP32 ADC Calibration Driver
Video Tutorial
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.