Arduino UNO R4 - Force Sensor
This tutorial instructs you how to use a force sensor with Arduino UNO R4. In detail, we will learn:
- How a force sensor works
- How to connect the force sensor to Arduino UNO R4
- How to program Arduino UNO R4 to read the value from the force sensor
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 sometimes called a force sensing resistor, force sensitive resistor, or simply FSR. It is a type of resistor that alters its resistance when pressure is applied to it.
- Affordable and simple to operate.
- Effective at sensing physical pressure or squeezing.
- Not effective at measuring the weight in pounds.
The force sensor is used in electronic drums, mobile phones, handheld gaming devices, and many other portable electronics.
Pinout
A force sensor has two pins. Because it works like a resistor, we do not need to differentiate between these pins. They are identical.
How It Works
The force sensor is like a resistor that changes its resistance based on how hard it is pressed. The harder you press, the lower the resistance between the two ends.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
How To Program For Force Sensor
The Arduino UNO R4 has pins labeled A0 to A5 that are used for analog input. These pins change the voltage, ranging from 0 volts to VCC, into whole numbers between 0 and 1023. This number is known as the ADC or analog value.
By connecting a pin from the force sensor to an analog input pin, we can use the analogRead() function to read the analog value from the pin. This tells us how much pressure is being applied.
Arduino UNO R4 Code
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the force sensor to the Arduino Uno R4 according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to upload the code to the Arduino UNO R4.
- Press the force sensor.
- Check the result on the Serial Monitor.