Measuring force with Arduino and Matlab
조회 수: 14 (최근 30일)
이전 댓글 표시
I have a calibration problem with the following code. This code accesses an Arduino. The Arduino is in turn connected to a force sensor via an amplifier. The aim of the Matlab code is that when a known weight is placed on the force sensor, for example 3kg, the value is displayed in Matlab as 30 Newtons via the Arduino.
Matlab displays values between -1030 and -1020 as the zero point for the measurement. With Arduino, the values on the serial monitor for the zero point fluctuate between 267-269.
The aim is to set Matlab to zero and to display 30 newtons in Matlab when, for example, 3 kg is applied.
The following voltages were determined via Manuware when different weights were applied to the force sensor:
kg Volt
1 0,06
3 0,18
4 0,23
5 0,3
6 0,39
7 0,44
8 0,46
9 0,52
10 0,6
댓글 수: 0
답변 (1개)
Sahas
2024년 8월 26일
As per my understanding, the Arduino code gets the voltage readings from a force sensor. The MATLAB code uses the voltage readings and converts them into force measurements, in Newtons, using a conversion factor and plots the values in the end.
I went through the MATLAB and Arduino code snippets provided; I suggest doing the following changes in the codes:
In the Arduino code, separate the conversion and reading steps while reading the sensor values. Please use the following syntax for the “analogRead” function:
void loop() {
int sensorValue = analogRead(analogInPin);
int sensorValue2 = analogRead(analogInPin2);
float voltage1 = sensorValue * (5.0 / 1023.0);
float voltage2 = sensorValue2 * (5.0 / 1023.0);
Serial.print(voltage1);
Serial.print(" ");
Serial.println(voltage2);
delay(1000);
}
In the MATLAB code, the “readVoltage” is using the incorrect conversions from analog to voltage. Instead, use “readVoltage” function in the following manner:
% Read voltage from Arduino
x0_voltage = readVoltage(a, 'A1');
z0_voltage = readVoltage(a, 'A5');
From the calibration data provided, the relation between voltage and force seems to be linear and the conversion factor comes out to be 30/0.18 = 166.67.
% Define conversion factor based on calibration data
conversionFactor = 30 / 0.18;
Now multiply the voltage reading by the conversion factor to get the force in Newtons.
% Convert voltage to force in Newtons
x0_force = x0_voltage * conversionFactor;
z0_force = z0_voltage * conversionFactor;
Incorporate these changes into your code and make any necessary adjustments to the plotting if required.
I hope this is beneficial!
참고 항목
카테고리
Help Center 및 File Exchange에서 Signal Integrity Kits for Industry Standards에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!