Hello, I'm working on a project to detect bad posture using a flex sensor positioned at the lumbar spine. However, I'm struggling with inaccurate angle readings despite thorough code and circuit checks.
Here's a snippet of my code:
const int flexPin = A0; // Flex sensor input pin
const int threshold = 100; // Threshold for detecting bad posture
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int flexValue = analogRead(flexPin); // Read flex sensor value
float angle = map(flexValue, 0, 1023, 0, 180); // Map flex sensor value to angle range (adjust as needed)
if (angle > threshold) {
// Bad posture detected
Serial.println("Bad posture detected!");
// Add code for alerting user (e.g., activating a buzzer)
}
delay(100); // Delay for stability (adjust as needed)
}
I'm uncertain if there's incorrect or missing code contributing to the issue. I'd appreciate any guidance or suggestions on improving accuracy, especially considering the lumbar spine placement. My goal is precise angle detection for effective posture monitoring.
Your assistance would be invaluable. Thank you for your time.