51 and 32 microcontrollers read the pressure changes of the FSR film pressure sensor

Introduction

Insert image description here

The FSR film pressure sensor is a sensor that can convert pressure changes into resistance changes. The microcontroller can read it and then use it as a rough measurement of pressure (only provides pressure changes, not suitable for specific numerical calculations of absolute values), pressure detection and other applications. The larger the resistance, the smaller it is. From the appearance point of view, it can be divided into two types: comb and all-over silver. Comb as the name implies, it looks like a comb. All-over silver means that the front and back are the same and there are no lines on the surface. This article uses a comb-mounted FSR membrane pressure sensor.
Different models have different measurement ranges, and there are many options in terms of range and size. Please refer to the figure below for details. The long and short tails are only the difference in the length of the pin wires, and there is no difference in other parameters. The model used in this article is RP-C18.3-ST, with an outer diameter of 18mm and a short tail. Can measure up to 6kg.
Insert image description here

Only one pressure sensor cannot be directly read by the microcontroller, and it must be combined with a linear voltage conversion module to output analog/digital quantities.

Linear voltage conversion module

Insert image description here
The module pin definition and potentiometer description are as follows:
Insert image description here

①VCC Supply voltage positive (5V)
②GND Supply voltage negative pole
③DO High level signal output
④AO Analog voltage signal output (0-3.3V)
AO-RES Magnification adjustment potentiometer
DO-RES Comparison threshold adjustment potentiometer

Using a microcontroller to read the AO pin, you can do applications such as the presence or absence of pressure, pressure trend changes and rough measurement of pressure values. AO-RES can adjust the range gain sensitivity of the output analog voltage value. The AO pin is adjusted through this AO_RES Output accuracy.

Using the microcontroller to read the DO pin can be used to apply whether there is pressure. DO-RES can adjust the threshold of the DO output. When the pressure is greater than the adjustment threshold, the DO pin outputs a high level and the DO_LED lights up. When the pressure is less than the set threshold, the DO pin outputs low level and the DO_LED turns off.

//下面4项内容需要根据实际型号和量程修正

//最小量程 根据具体型号对应手册获取,单位是g,这里以RP-18.3-ST型号为例,最小量程是20g
#define PRESS_MIN   20
//最大量程 根据具体型号对应手册获取,单位是g,这里以RP-18.3-ST型号为例,最大量程是6kg
#define PRESS_MAX   6000

//以下2个参数根据获取方法:
//理论上:
// 1.薄膜压力传感器不是精准的压力测试传感器,只适合粗略测量压力用,不能当压力计精确测量。
// 2. AO引脚输出的电压有效范围是0.1v到3.3v,而实际根据不同传感器范围会在这个范围内,并不一定是最大值3.3v,也可能低于3.3v,要实际万用表测量,
//  例程只是给出理论值,想要精确请自行万用表测量然后修正以下2个AO引脚电压输出的最大和最小值
//调节方法:
//薄膜压力传感器的AO引脚输出的增益范围是通过板载AO_RES电位器调节实现的,
//想要稍微精准点,需要自己给定具体已知力,然后调节AO_RES电位器到串口输出重量正好是自己给定力就可以了
#define VOLTAGE_MIN 100
#define VOLTAGE_MAX 3300

The following demonstrates using a 51 microcontroller to read DO for pressure detection, and a 32 microcontroller to read AO for pressure measurement applications.

51 microcontroller reads DO

Wiring

STC89C52 FSR
5V VCC
GND GND
P1.1 DO
STC89C52 LCD1602
P2.0-P2.7 DB0-DB7
P0.5 RS
P0.6 RW
P0.7 IN

51 code

#include "main.h"
#include "LCD1602.h"



//定义变量
unsigned char KEY_NUM = 0;   
int count = 0;
int state = 0;
	

//****************************************************
//主函数
//****************************************************
void main()
{
    
    
	Init_LCD1602();
	LCD1602_write_com(0x80);
	LCD1602_write_word("welcome to use!");
	while(1)
	{
    
    
    	scanSensor();
		if(KEY_NUM == 1)
		{
    
    
			KEY_NUM = 0;
			LCD1602_write_com(0x80+0x40);
			LCD1602_write_word("count =");
			LCD1602_write_data(count%10000/1000+0x30);
			LCD1602_write_data(count%1000/100+0x30);
			LCD1602_write_data(count%100/10+0x30);
			LCD1602_write_data(count%10+0x30);

			count++;
			
			if(state == 2)
			  state = 0;
		}

	}
}

void scanSensor()
{
    
    
//	SENSOR = 1;
	if(SENSOR == 1)
	{
    
    
		Delay_ms(10);
		if(SENSOR == 1) 
		{
    
    
		  while(SENSOR == 1);
		  KEY_NUM = 1;
		} 
	}
}


//****************************************************
//MS延时函数
//****************************************************
void Delay_ms(unsigned int n)
{
    
    
	unsigned int  i,j;
	for(i=0;i<n;i++)
		for(j=0;j<123;j++);
}


Experimental effect

Insert image description here
Each time the membrane pressure sensor is pressed, the number of presses increases by 1 and is displayed on the LCD screen.

32 microcontroller reads AO

Wiring

STM32 FSR
5V VCC
GND GND
PA1 TO THE
STM32 USB to TTL
3.3V VCC
GND GND
TXD RXD
RXD TXD

32 code

#include "stm32f10x.h"
#include "delay.h"
#include "FSR.h"
#include "usart.h"
#include "adc.h"

//下面4项内容需要根据实际型号和量程修正

//最小量程 根据具体型号对应手册获取,单位是g,这里以RP-18.3-ST型号为例,最小量程是20g
#define PRESS_MIN	20
//最大量程 根据具体型号对应手册获取,单位是g,这里以RP-18.3-ST型号为例,最大量程是6kg
#define PRESS_MAX	6000

//以下2个参数根据获取方法:
//理论上:
// 1.薄膜压力传感器不是精准的压力测试传感器,只适合粗略测量压力用,不能当压力计精确测量。
// 2. AO引脚输出的电压有效范围是0.1v到3.3v,而实际根据不同传感器范围会在这个范围内,并不一定是最大值3.3v,也可能低于3.3v,要实际万用表测量,
// 	例程只是给出理论值,想要精确请自行万用表测量然后修正以下2个AO引脚电压输出的最大和最小值
//调节方法:
//薄膜压力传感器的AO引脚输出的增益范围是通过板载AO_RES电位器调节实现的,
//想要稍微精准点,需要自己给定具体已知力,然后调节AO_RES电位器到串口输出重量正好是自己给定力就可以了
#define VOLTAGE_MIN 150
#define VOLTAGE_MAX 3300

u8 state = 0;
u16 val = 0;
u16 value_AD = 0;

long PRESS_AO = 0;
int VOLTAGE_AO = 0;

long map(long x, long in_min, long in_max, long out_min, long out_max);

int main(void)
{
    
    		
	delay_init();	
	NVIC_Configuration(); 	 //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
	uart_init(9600);	 //串口初始化为9600
	Adc_Init();

	delay_ms(1000);

	printf("Test start\r\n");
	while(1)
	{
    
    
		value_AD = Get_Adc_Average(1,10);	//10次平均值
		VOLTAGE_AO = map(value_AD, 0, 4095, 0, 3300);
		if(VOLTAGE_AO < VOLTAGE_MIN)
		{
    
    
			PRESS_AO = 0;
		}
		else if(VOLTAGE_AO > VOLTAGE_MAX)
		{
    
    
			PRESS_AO = PRESS_MAX;
		}
		else
		{
    
    
			PRESS_AO = map(VOLTAGE_AO, VOLTAGE_MIN, VOLTAGE_MAX, PRESS_MIN, PRESS_MAX);
		}
		printf("AD值 = %d,电压 = %d mv,压力 = %ld g\r\n",value_AD,VOLTAGE_AO,PRESS_AO);	
						
		delay_ms(500);
	}

}


long map(long x, long in_min, long in_max, long out_min, long out_max) {
    
    
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


Experimental effect

Insert image description here
Press the membrane pressure sensor, and the AD value, voltage value, pressure value and other parameters can be read in the serial port assistant. The model used is a short tail model with an outer diameter of 18mm, and the maximum pressure value displayed is 6000g.

Summarize

This article introduces the use of two microcontrollers, namely STC89C52 microcontroller and STM32F103 microcontroller, to read the pressure changes of the FSR film pressure sensor to measure pressure and detect pressure.

Guess you like

Origin blog.csdn.net/qq_42250136/article/details/135242070