Raspberry Pi - Force Sensor
This tutorial instructs you how to use Raspberry Pi with the force sensor. In detail, we will learn:
- How the force sensor work
- How to connect the force sensor to Raspberry Pi
- How to program Raspberry Pi to read the value from the force sensor
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
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of Force Sensor
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
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:
- Install the Adafruit_ADS1x15 library by running the following commands on your Raspberry Pi terminal:
- Create a Python script file force_sensor.py and add the following code:
- Save the file and run the Python script by executing the following command in the terminal:
- Press the force sensor.
- Check the results in the Terminal.
The script runs in an infinite loop continuously until you press Ctrl + C in the terminal.