Arduino UNO R4 - Force Sensor

This tutorial instructs you how to use a force sensor with Arduino UNO R4. In detail, we will learn:

Arduino UNO R4 and force sensor

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×Force Sensor
1×10 kΩ resistor
1×Breadboard
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino UNO R4
1×(Recommended) Breadboard Shield For Arduino UNO R4
1×(Recommended) Enclosure For Arduino UNO R4

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.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of Force Sensor

Force sensor pinout

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

The wiring diagram between Arduino UNO R4 Force

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

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-force-sensor */ #define FORCE_SENSOR_PIN A0 // The Arduino UNO R4 pin connected to the FSR force sensor with 10K pulldown void setup() { Serial.begin(9600); } void loop() { int analogReading = analogRead(FORCE_SENSOR_PIN); Serial.print("Force sensor reading = "); 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); }

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.
COM6
Send
Force sensor reading = 0 -> no pressure Force sensor reading = 0 -> no pressure Force sensor reading = 132 -> light touch Force sensor reading = 147 -> light touch Force sensor reading = 394 -> light squeeze Force sensor reading = 421 -> light squeeze Force sensor reading = 607 -> medium squeeze Force sensor reading = 791 -> medium squeeze Force sensor reading = 921 -> big squeeze Force sensor reading = 987 -> big squeeze Force sensor reading = 0 -> no pressure Force sensor reading = 0 -> no pressure
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Learn More

※ OUR MESSAGES

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