FSR not working

fsrPinc is not working. I've tried a simple sketch to read and print all three FSR sensors value and all three work. but in the below sketch the one (fsrpinc) is not working.



#define BLYNK_TEMPLATE_ID "TMPL6Sk8NoCPC"
#define BLYNK_DEVICE_NAME "bag"
#define BLYNK_AUTH_TOKEN "JUdskCWySnYUfMgBvfZwLUO4sPlFz7Za"

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <MPU6050.h>
#include <Preferences.h>


float roll;
float pitch;
float yaw;


MPU6050 mpu;
Preferences preferences;

BlynkTimer timer;
WidgetLED danger(V0);


int cal_weight;
int body_weight;

const int bzr = 25;      // Buzzer pin
const int fsrPinr = 34;   // FSR analog pin
const int fsrPinl = 35; // FSR analog pin
const int fsrPinc = 27; // FSR analog pin

int fsrValuer, fsrValuel, fsrValuec;


const int buttonPin = 14;
volatile bool buttonPressed = false;

void IRAM_ATTR buttonInterrupt() {
  buttonPressed = true;
}


// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Redmi Note 12S";
char pass[] = "ablgazra";

void setup()
{
  // Debug console
  Serial.begin(115200);
  pinMode(fsrPinr, INPUT);
  pinMode(fsrPinl, INPUT);
  pinMode(fsrPinc, INPUT);
  pinMode(bzr, OUTPUT);

  Wire.begin();
  pinMode(buttonPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(buttonPin), buttonInterrupt, FALLING);

  mpu.initialize();
  mpu.setDMPEnabled(true);

  preferences.begin("mpu6050", false);

  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(400L, cd);
  timer.setInterval(400L, pres);
}

void pres()
{
  fsrValuer = analogRead(fsrPinr);
  fsrValuel = analogRead(fsrPinl);
  fsrValuec = analogRead(fsrPinc);


  Serial.print("FSR Value Right: ");
  Serial.println(fsrValuer);
  Serial.print("FSR Value Left: ");
  Serial.println(fsrValuel);
  Serial.print("FSR Value Center: ");
  Serial.println(fsrValuec);

  Blynk.virtualWrite(V1, fsrValuer );
  Blynk.virtualWrite(V2, fsrValuel);
  Blynk.virtualWrite(V3, fsrValuec);

}

void cd() {

  if (buttonPressed) {
    resetReference();
    buttonPressed = false;
  }

  int16_t ax, ay, az;
  int16_t gx, gy, gz;

  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  float referenceX = preferences.getFloat("referenceX", 0.0);
  float referenceY = preferences.getFloat("referenceY", 0.0);
  float referenceZ = preferences.getFloat("referenceZ", 0.0);

  float accX = (float)ax / 16384.0;
  float accY = (float)ay / 16384.0;
  float accZ = (float)az / 16384.0;

  float gyroX = (float)gx / 131.0;
  float gyroY = (float)gy / 131.0;
  float gyroZ = (float)gz / 131.0;

  roll = atan2(accY, accZ) * (180.0 / PI) - referenceX;
  pitch = atan(-accX / sqrt(accY * accY + accZ * accZ)) * (180.0 / PI) - referenceY;
  yaw = gyroZ - referenceZ;


  //  Blynk.virtualWrite(V1, roll);
  //  Blynk.virtualWrite(V2, pitch);
  //  Blynk.virtualWrite(V3, yaw);

  //delay(100);
}


void resetReference() {
  int16_t ax, ay, az;
  int16_t gx, gy, gz;
  float accX, accY, accZ;

  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  accX = (float)ax / 16384.0;
  accY = (float)ay / 16384.0;
  accZ = (float)az / 16384.0;

  float referenceX = atan2(accY, accZ) * (180.0 / PI);
  float referenceY = atan(-accX / sqrt(accY * accY + accZ * accZ)) * (180.0 / PI);
  float referenceZ = (float)gz / 131.0;

  preferences.putFloat("referenceX", referenceX);
  preferences.putFloat("referenceY", referenceY);
  preferences.putFloat("referenceZ", referenceZ);

  //Serial.println("Reference reset and stored.");
}



void loop() {
  Blynk.run();
  timer.run();

  // Reset the danger indicator
  //danger.off();

  // Forward tilt
  if (roll < -40) {
    digitalWrite(bzr, HIGH);
    danger.on();
  }

  // Unbalance
  else if (((fsrValuel > 2800) &&  (fsrValuer == 0)) || (fsrValuel == 0) &&  (fsrValuer > 2800)) {
    Blynk.logEvent("unbalanced");
    digitalWrite(bzr, HIGH);
    danger.on();
  }

  // Spine pain
  //  else if (fsrValuec > 500) {
  //    digitalWrite(bzr, HIGH);
  //    danger.on();
  //}

  // Overweight
  //  else if (fsrValuel > cal_weight) {
  //    digitalWrite(bzr, HIGH);
  //    danger.on();
//}

// No dangerous conditions, turn off the buzzer
else {
  digitalWrite(bzr, LOW);
  danger.off();
}
}


BLYNK_WRITE(V4) {                   //Read the changes in the weight slider
  body_weight = param.asInt();
  cal_weight = body_weight;  // Calculate the safe carrying weight
}

Welcome to the forum

Which Arduino board are you using and what exactly do you mean by "not working" ?

That can hardly be called a simple sketch.

Test one FSR with a simple resistive voltage divider, and the 10 lines or so of code required. Example tutorial

Once that is working, add other options to the project, one at a time, testing as you go.

By simple sketch, I don't mean this one.
I've used a similar code in the example code you've provided.

all three were working and yes I've used 10 K resister with each of them.

the problem is that in this sketch the one sensor is not showing any value it's zero

By not working I mean it is not flying.

it's an analog sensor and is expected to show analog value as the other two are showing but this one is not.

the one sensor is not showing any value it's zero

Check the wiring, and use your multimeter to verify voltage changes at the input.

don't have one right now. if it's working on other sketch, It must on this one too

I'm using an ESP32

Shouldn't you hide your token and ID?

What you should do is strip that sketch to the very minimum, still having the issue. So remove all code that deals with other sensors and whatnot, just leaving the code related to that one sensor.

In doing so, chances are you find the problem yourself. If not, post that minimum sketch and describe in detail what it does, and how it differs from what you expect/want it to do.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.