Example Code for Arduino-Pressure to Serial Output

Last revision 2025/12/26

We use flex sensor together with Arduino UNO mainboard in this tutorial, and the tutorial will demonstrate how does the serial port output change under different pressure conditions.

Hardware Preparation

  • DFRduino UNO x1
  • Thin Film Pressure Sensors x1
  • Computer x1
  • Dupont Wires

Software Preparation

  • Arduino IDE

Wiring Diagram

Thin Film Pressure Sensor Connection Diagram

Other Preparation Work

  • The abscissa: force (g)
  • The ordinate: resistance (Ω)
    Thin Film Pressure Sensor Resistance vs Force

When the outside force applies to the active area, the disconnected circuit of the lower layer will be connected through the pressure sensitive layer of the upper layer, by which to convert pressure into resistance. The output resistance decreases as force increases. That is to say, the sensor output different resistances under different force conditions. The relationship of resistance and force is shown in the above figure. The abscissa represents force and the ordinate is resistance. As the picutre shows, when the the force applying to the sensing area is too strong or weak, the slope will be correspondingly too large or small. So these sensors are more suitable for qualitative measure. There would be large data errors if using the sensor in quantitative measure.

  • R@F for C18.3:SEN0294, SEN0295
  • R@F for S40:SEN0296
  • R@F for C7.6:SEN0297, SEN0298
  • R@F for RP-L:SEN0293, SEN0299

Sample Code

/*!
 * @file  piezoVibrationSensor.ino
 * @brief This example The sensors detect vibration
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  linfeng([email protected])
 * @version  V1.0
 * @date  2016-02-26
 */

#define sensorPin A0
void setup()
{
  Serial.begin(115200);
}

void loop()
{
  int x = analogRead(sensorPin);
  Serial.println(x);
  delay(50);
}

Result

Thin Film Pressure Sensor Expected Results

The serial data changes as above when we press the sensor. The serial data decreases linearly as the force increases. We recommend you use the sensor in qualitative measure.

Was this article helpful?

TOP