Raspberry Pi - Force Sensor

This tutorial instructs you how to use Raspberry Pi with the force sensor. In detail, we will learn:

As a typical application, You can put your stuff on the force sensor, and then if the Raspberry Pi detects the force changes, it means someone has take your stuff.

Hardware Preparation

1×Raspberry Pi 4 Model B
1×ADS1115 ADC Module
1×Force Sensor
1×10 kΩ resistor
1×Jumper Wires
1×(Optional) Screw Terminal Adapter for Raspberry Pi

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

Force sensor pinout

The force sensor is also referred to as a force sensing resistor, force sensitive resistor, or simply FSR. It is essentially a resistor that changes its resistive value in response to the amount of pressure applied. The force sensor has the following characteristics:

  • It is inexpensive and straightforward to use.
  • It is effective at detecting physical pressure or squeezing.
  • It is not suitable for measuring the weight of an object.

The force sensor is used in a variety of portable electronics, such as electronic drums, mobile phones, and handheld gaming devices.

The Force Sensor Pinout

A force sensor has two pins which are symmetric, and since it is a type of resistor, there is no need to differentiate between them.

How It Works

The force sensor is essentially a resistor that varies its resistance depending on the amount of pressure applied. The more pressure that is put on the sensor, the lower the resistance between the two pins will be.

Wiring Diagram

The wiring diagram between Raspberry Pi and Force Sensor

This image is created using Fritzing. Click to enlarge image

Raspberry Pi Code

Detailed Instructions

  • Make sure you have Raspbian or any other Raspberry Pi compatible operating system installed on your Pi.
  • Make sure your Raspberry Pi is connected to the same local network as your PC.
  • Make sure your Raspberry Pi is connected to the internet if you need to install some libraries.
  • If this is the first time you use Raspberry Pi, See how to set up the Raspberry Pi
  • Connect your PC to the Raspberry Pi via SSH using the built-in SSH client on Linux and macOS or PuTTY on Windows. See to how connect your PC to Raspberry Pi via SSH.
  • Make sure you have the RPi.GPIO library installed. If not, install it using the following command:
sudo apt-get update sudo apt-get install python3-rpi.gpio
  • Install the Adafruit_ADS1x15 library by running the following commands on your Raspberry Pi terminal:
sudo pip install Adafruit-ADS1x15
  • Create a Python script file force_sensor.py and add the following code:
# This Raspberry Pi code was developed by newbiely.com # This Raspberry Pi code is made available for public use without any restriction # For comprehensive instructions and wiring diagrams, please visit: # https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-force-sensor import time import Adafruit_ADS1x15 # Create an ADS1115 ADC instance ADC = Adafruit_ADS1x15.ADS1115() # Specify the ADC channel to read from (0-3) CHANNEL = 0 # Set the gain (1, 2/3, 1/2, 1/4, 1/8, 1/16) # Higher gain values amplify the input voltage range but reduce precision GAIN = 1 # Define pressure level thresholds NO_PRESSURE_THRESHOLD = 1000 LIGHT_TOUCH_THRESHOLD = 2000 LIGHT_SQUEEZE_THRESHOLD = 3000 MEDIUM_SQUEEZE_THRESHOLD = 4000 try: while True: # Read the raw value from the ADC raw_value = ADC.read_adc(CHANNEL, gain=GAIN) # Determine pressure level if raw_value < NO_PRESSURE_THRESHOLD: pressure_level = "No Pressure" elif raw_value < LIGHT_TOUCH_THRESHOLD: pressure_level = "Light Touch" elif raw_value < LIGHT_SQUEEZE_THRESHOLD: pressure_level = "Light Squeeze" elif raw_value < MEDIUM_SQUEEZE_THRESHOLD: pressure_level = "Medium Squeeze" else: pressure_level = "Big Squeeze" # Print the pressure level print(f"Force Sensor Raw Value: {raw_value}, Pressure Level: {pressure_level}") time.sleep(0.5) # Wait for a short period before reading again except KeyboardInterrupt: print("Measurement stopped by user")
  • Save the file and run the Python script by executing the following command in the terminal:
python3 force_sensor.py
  • Press the force sensor.
  • Check the results in the Terminal.
PuTTY - Raspberry Pi
Force Sensor Raw Value: 800, Pressure Level: No Pressure Force Sensor Raw Value: 1500, Pressure Level: Light Touch Force Sensor Raw Value: 2500, Pressure Level: Light Squeeze Force Sensor Raw Value: 3500, Pressure Level: Medium Squeeze Force Sensor Raw Value: 4500, Pressure Level: Big Squeeze Force Sensor Raw Value: 1800, Pressure Level: Light Touch Force Sensor Raw Value: 2800, Pressure Level: Light Squeeze

The script runs in an infinite loop continuously until you press Ctrl + C in the terminal.

Video Tutorial

Learn More


  • 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!