Arduino Nano ESP32 - Force Sensor

The force sensor is called force sensitive resistor, the force sensing resistor, or FSR. This tutorial provides instructions on how to use Arduino Nano ESP32 with the force sensor. In detail, we will learn:

Hardware Preparation

1×Arduino Nano ESP32
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 Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of 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.

Force sensor pinout

Wiring Diagram between Force Sensor and Arduino Nano ESP32

The wiring diagram between Arduino Nano ESP32 and Force

This image is created using Fritzing. Click to enlarge image

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)

Arduino Nano ESP32 Code

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-force-sensor */ #define FORCE_SENSOR_PIN A0 // The Arduino Nano ESP32 pin connected to the force reistor void setup() { Serial.begin(9600); } void loop() { int analogReading = analogRead(FORCE_SENSOR_PIN); Serial.print("The force sensor value = "); Serial.print(analogReading); // print the raw analog reading if (analogReading < 10) // from 0 to 9 Serial.println(" -> no pressure"); else if (analogReading < 200) // from 10 to 199 Serial.println(" -> light touch"); else if (analogReading < 500) // from 200 to 499 Serial.println(" -> light squeeze"); else if (analogReading < 800) // from 500 to 799 Serial.println(" -> medium squeeze"); else // from 800 to 1023 Serial.println(" -> big squeeze"); delay(1000); }

Detailed Instructions

  • If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE.
  • Copy the above code and paste it to Arduino IDE.
  • Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
  • Press the force sensor
  • Check out the result on the Serial Monitor. It looks like the below:.
COM6
Send
The force sensor value = 0 -> no pressure The force sensor value = 0 -> no pressure The force sensor value = 132 -> light touch The force sensor value = 147 -> light touch The force sensor value = 394 -> light squeeze The force sensor value = 421 -> light squeeze The force sensor value = 607 -> medium squeeze The force sensor value = 791 -> medium squeeze The force sensor value = 921 -> big squeeze The force sensor value = 987 -> big squeeze The force sensor value = 0 -> no pressure The force sensor value = 0 -> no pressure
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a sensor or component. The Arduino Nano ESP32's ADC is suitable for projects that do not require high accuracy. However, for projects needing precise measurements, keep the following in mind:

  • The Arduino Nano ESP32's ADC is not perfectly accurate and might require calibration for correct results. Each Arduino Nano ESP32 board can vary slightly, so calibration is necessary for each individual board.
  • Calibration can be challenging, especially for beginners, and might not always yield the exact results you want.

For projects requiring high precision, consider using an external ADC (e.g ADS1115) with the Arduino Nano ESP32 or using another Arduino, such as the Arduino Uno R4 WiFi, which has a more reliable ADC. If you still want to calibrate the Arduino Nano ESP32's ADC, refer to the ESP32 ADC Calibration Driver.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!