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.

Video Tutorial

you can watch this video tutorial

Hardware Required

1×ESP-WROOM-32 Dev Module
1×Micro USB Cable
1×Force Sensor
1×10 kΩ resistor
1×Breadboard
n×Jumper Wires

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.

ESP32 Button LED Wiring Diagram

Wiring Diagram

Schematic Diagram

ESP32 Button LED Wiring Diagram

Image is developed using Fritzing. Click to enlarge image

Breadboard Connections

ESP32 Button LED Wiring Diagram

Image is developed using Fritzing. Click to enlarge image

click to see ESP32 pin out

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

Copy

#define FORCE_SENSOR_PIN 36 // ESP32 pin GIOP36 (ADC0): the FSR and 10K pulldown are connected to A0

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);
}           

Quick Steps

  • power up your board
  • Open Arduino IDE
  • Select the right board
  • Select the right port
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP32
  • Arduino IDE Upload Code
  • Press and keep pressing the button several seconds
  • See the changes you made

Book Tutorial

We are considering to make the book tutorials. If you think the book tutorials are essential, you can download it. download book

References

※ NOTE THAT:

Some components works on 3.3v and others works on 5v!