Home Code force-sensing resistor micropython example using a Tpyboard

force-sensing resistor micropython example using a Tpyboard

by shedboy71

In this example we connect a force-sensing resistor to a TPyboard, in this case we I used a TPyboard 202

 

Description

A force-sensing resistor is a material whose resistance changes when a force or pressure is applied.

Force-sensing resistors consist of a conductive polymer, which changes resistance in a predictable manner following application of force to its surface.They are normally supplied as a polymer sheet or ink that can be applied by screen printing.

The sensing film consists of both electrically conducting and non-conducting particles suspended in matrix. The particles are sub-micrometre sizes, and are formulated to reduce the temperature dependence, improve mechanical properties and increase surface durability.

Applying a force to the surface of the sensing film causes particles to touch the conducting electrodes, changing the resistance of the film.

As with all resistive based sensors, force-sensing resistors require a relatively simple interface and can operate satisfactorily in moderately hostile environments.

Compared to other force sensors, the advantages of FSRs are their size (thickness typically less than 0.5 mm), low cost and good shock resistance. A disadvantage is their low precision: measurement results may differ 10% and more

Here is a typical example

force-sensistive-resistor

force-sensistive-resistor

Parts Required

The module costs about $2

Name Link
Force-sensing resistor FSR402 0.5 inch Pressure Sensor
TPYBoard V202 TPYBoard V202 Pyboard Micropython Development Board
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

A simple layout to build here basically you are creating a  voltage divider with 10k resistor and the force sensor, squeezing the force sensor alters the resistance so the voltage in at pin X1 on my Tpyboard will vary depending on the force

 

Code Example

I used uPycraft for development, no libraries required.

I used uPycraft and simply modified main.py

This is a test example in the library which pretty much highlights all of the functionality, you can also use any other Micropython supported board

# main.py -- put your code here!
from pyb import Pin, ADC
import time
 
adc = ADC(Pin('X1'))
 
while True:
	print(str(adc.read()))
	time.sleep(1)

Output

Using a terminal program you should see output similar to the following, squeeze the FSR and the value will increase

MicroPython v1.8.7-478-gbfb48c1 on 2017-03-24; PYBv1.1 with STM32F405RG
Type “help()” for more information.
>>> 0
0
0
237
301
0
1085
1149
837
652
585
1673
0
432
424
2323
3025
2871

 

You may also like

Leave a Comment