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
}