I made a code for my two flexion sensors but I can't calibrate them to display the correct values on my LCD. do you think you can help me? this is the code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int flexPin1 = A0;
int flexPin2 = A1;
const int LCD_COLS = 16; // Number of LCD columns
const int LCD_ROWS = 2;
float VCC = 4.7; // Arduino este alimentat cu 5V VCC
float R2 = 10000;
// Calibration values - adjust these as needed
int value1;
int value2;
const int STRAIGHT_VALUE_1 =600 ; // Raw sensor value when straight (sensor 1)
const int STRAIGHT_VALUE_2 = 600; // Raw sensor value when straight (sensor 2)
const int BEND_VALUE_1 = 1023; // Raw sensor value at 90 degrees bend (sensor 1)
const int BEND_VALUE_2 = 1023; // Raw sensor value at 90 degrees bend (sensor 2)
// LCD display object
LiquidCrystal_I2C lcd(0x27, LCD_COLS, LCD_ROWS);
void setup()
{
// Initialize the LCD
lcd.begin(LCD_COLS, LCD_ROWS);
lcd.init();
// Print initial text on the LCD
lcd.print("Angle 1: g");
lcd.setCursor(0, 1);
lcd.print("Angle 2: g");
Serial.begin(9600);
pinMode(flexPin1, INPUT);
pinMode(flexPin2, INPUT);
}
void loop()
{
value1 = analogRead(flexPin1);
value2 = analogRead(flexPin2);
// Map the sensor values to angles
int angle_1 = map(value1, STRAIGHT_VALUE_1, BEND_VALUE_1, 90, 0);
int angle_2 = map(value2, STRAIGHT_VALUE_2, BEND_VALUE_2, 90, 0);
angle_1 = constrain(angle_1, 0, 90);
angle_2 = constrain(angle_2, 0, 90);
// Display the angles on the LCD
lcd.setCursor(9, 0);
lcd.print(angle_1);
lcd.print(" ");
lcd.setCursor(9, 1);
lcd.print(angle_2);
lcd.print(" ");
Serial.println(value1);
Serial.println(value2);
delay(1500);
}
I should be able to calibrate these sensors in such a way that when they are introduced into the collar created by me, when the subject sits with his head motionless, they display 0 degrees and when he starts to bend his head, they measure the cervical flexion angle from 0 to 90 degrees. for example, when I manage from the code to set 0 degrees as the starting point, instead of displaying 90 degrees, when the sensor is bent to 90, it displays 50
YES, the sensor is positioned vertically, but I can't make the table, because the resistors are covered by heat shrink. this is the diagram in the paper. I don't have time to change the components and the approach. I really need to make it work like this