Arduino Mega - Force Sensor
This guide shows you how to use a force sensor with an Arduino Mega. Here is what we will learn:
- What a force sensor does
- How to connect a force sensor to an Arduino Mega
- How to program Arduino Mega to read from the force sensor

Hardware Preparation
| 1 | × | Arduino Mega | |
| 1 | × | USB 2.0 cable type A/B (for USB-A PC) | |
| 1 | × | USB 2.0 cable type C/B (for USB-C PC) | |
| 1 | × | Force Sensor | |
| 1 | × | 10 kΩ Resistor | |
| 1 | × | Breadboard | |
| 1 | × | Jumper Wires |
Or you can buy the following 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

A force sensor is also called a force-sensing resistor, a force-sensitive resistor, or just FSR. It is a kind of resistor that changes its resistance when you press on it.
- Cheap and easy to use.
- Good at sensing pressure when you press or squeeze it.
- Not good at measuring weight in pounds.
A force sensor is used in electronic drums, mobile phones, handheld game devices, and many other small devices.
Pinout
A force sensor has two pins. Since it works like a resistor, we don't need to tell the pins apart. They are the same.
How It Works
A force sensor works like a resistor. Its resistance changes when you press it. The harder you press, the lower the resistance between its two ends.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
How To Program For Force Sensor
The Arduino Mega has analog input pins called A0 to A5. They read a voltage from 0 volts up to the supply voltage (VCC) and convert it into a number from 0 to 1023. This number is the ADC value, also known as the analog value.
Connect a pin from the pressure sensor to an analog input pin, then use the analogRead() function to read the value from that pin. This tells you how much pressure is on it.
Arduino Mega Code
Detailed Instructions
Do these steps one by one.
- Connect the force sensor to the Arduino Mega as shown in the diagram.
- Connect the Arduino Mega to your computer with a USB cable.
- Open the Arduino IDE on your computer.
- Choose the right Arduino Mega board and the COM port.
- Copy the code shown above and paste it into the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Mega.
- Press the force sensor to test it.
- Check the result in the Serial Monitor.