Calculating pressure from FSR 402 and showing result over blynk cloud

i am in serious need of help as i cant understand whats wrong with this code, when im running the code without blynk its working but over blynk connection no output is showing on the widget nor the serial monitor

#define BLYNK_TEMPLATE_ID "TMPLc6UqRDpu"

#define BLYNK_TEMPLATE_NAME "FOOT PRESSURE"

#define BLYNK_AUTH_TOKEN "XXXX"

#define BLYNK_PRINT Serial

#include <WiFi.h>

#include <BlynkSimpleEsp32.h>

char auth[] = "XXXX";

char ssid[] = "XXXX";  // type your wifi name

char pass[] = "XXXX";  // type your wifi password

BlynkTimer timer;

int FSRpin = 2;

int value;

int voltage;

int pressure;

unsigned long resistance ;

unsigned long conductance ;

int R;

void setup(void) {

  Serial.begin(9600);

  pinMode(FSRpin, INPUT);

  Blynk.begin(auth, ssid, pass,"blynk.cloud", 80);

  timer.setInterval(100L, sensorData);

}

void sensorData()

{

 

  value = analogRead(FSRpin);

  Serial.print("Analog reading from FSR = ");

  Serial.println(value);

  // Map analog value to obtain Vo in mV

  voltage = map(value, 0, 4095, 0, 3300);

  if (voltage == 0) {

    Serial.println("No force applied");

    delay(1000);

    return;

  }

  Serial.print("Vo = ");

  Serial.print(voltage);

  Serial.println(" mV ");

  //Calculate resistance using voltage divider equation

  //R_fsr = [(Vin*R)/Vo] - R

  resistance = 33e6/voltage;

  resistance = resistance - 10000;

  //Calculate conductance in micro mho(1/R)

  conductance = 1000000/resistance;                       //Convert to micro mhos

  //Use the FSR resistance vs. force graphs to estimate the force

  if (conductance <= 1000) {

    R = conductance/80;

  }

  else {

    R = (conductance - 1000)/30;

  }

  Blynk.virtualWrite(V0, R);  // sending sensor value to Blynk app

}

void loop() {

  Blynk.run();

  timer.run();

}

@Snehasis Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

done, please give some suggestions on my code its not giving any value on widget

The ESP32 has two analog to digital converters (ADCs) called ADC1 and ADC2.
Pins attached to ADC 2 cannot be used at the same time as WiFi.

GPIO2 is attached to ADC2, which is why it works fine without Blynk (when WiFi is not used) but stops working when WiFi is used.

Choose an ADC1 pin from the lost below and use that instead…

Analog to Digital Converter (ADC)

The ESP32 has 18 x 12 bits ADC input channels (while the ESP8266 only has 1x 10 bits ADC). These are the GPIOs that can be used as ADC and respective channels:

  • ADC1_CH0 (GPIO 36)
  • ADC1_CH1 (GPIO 37)
  • ADC1_CH2 (GPIO 38)
  • ADC1_CH3 (GPIO 39)
  • ADC1_CH4 (GPIO 32)
  • ADC1_CH5 (GPIO 33)
  • ADC1_CH6 (GPIO 34)
  • ADC1_CH7 (GPIO 35)
  • ADC2_CH0 (GPIO 4)
  • ADC2_CH1 (GPIO 0)
  • ADC2_CH2 (GPIO 2)
  • ADC2_CH3 (GPIO 15)
  • ADC2_CH4 (GPIO 13)
  • ADC2_CH5 (GPIO 12)
  • ADC2_CH6 (GPIO 14)
  • ADC2_CH7 (GPIO 27)
  • ADC2_CH8 (GPIO 25)
  • ADC2_CH9 (GPIO 26)

More info here…

Pete.

but it is still not showing anything…

Post your revised code, and the output from your serial monitor (use triple backticks at the beginning and end of each).

Pete.

[Screenshot of serial output removed by moderator]

here, thanx it finally worked, but its keeps on getting disconnected and connected automatically, any suggestion

Posting screenshots of your serial output doesn’t help.
Copy/paste the text and use triple backticks, and post the exact code that produced the serial output.

Pete.

#define BLYNK_TEMPLATE_ID "TMPLc6UqRDpu"

#define BLYNK_TEMPLATE_NAME "FOOT PRESSURE"

#define BLYNK_AUTH_TOKEN "SZDk6-jtKOtmjIjg5v_Jsc_1QwAtdtA9"

#define BLYNK_PRINT Serial

#include <WiFi.h>

#include <BlynkSimpleEsp32.h>

char auth[] = "S9";

char ssid[] = "";  // type your wifi name

char pass[] = "";  // type your wifi password

BlynkTimer timer;

int FSRpin = 34;

int value;

int voltage;

int pressure;

unsigned long resistance = 0;

unsigned long conductance = 0 ;

int R;

void setup(void) {

  Serial.begin(9600);

  pinMode(FSRpin, INPUT);

  Blynk.begin(auth, ssid, pass,"blynk.cloud", 80);

  timer.setInterval(1000L, sensorData);

}

void sensorData()

{

 //Obtain analog reading from pin A0 (FSR)

  value = analogRead(FSRpin);

  Serial.print("Analog reading from FSR = ");

  Serial.println(value);

  // Map analog value to obtain Vo in mV

  voltage = map(value, 0, 4095, 0, 3300);

  if (voltage == 0) {

    Serial.println("No force applied");

    delay(1000);

    return;

  }

  Serial.print("Vo = ");

  Serial.print(voltage);

  Serial.println(" mV ");

  //Calculate resistance using voltage divider equation

  //R_fsr = [(Vin*R)/Vo] - R

  resistance = 33e6/voltage;

  resistance = resistance - 10000;

  //Calculate conductance in micro mho(1/R)

  conductance = 1000000/resistance;                       //Convert to micro mhos

  //Use the FSR resistance vs. force graphs to estimate the force

  if (conductance <= 1000) {

    R = conductance/80;

  }

  else {

    R = (conductance - 1000)/30;

  }

  Serial.print("Force =  ");

  Serial.print(R);

  Serial.println(" N ");

  Serial.print("Pressure = ");

  Serial.print(R*5.5);

  Serial.println("KPa");

  Blynk.virtualWrite(V0, R);  // sending sensor value to Blynk app

}

void loop() {

  Blynk.run();

  timer.run();

}

here, this is the code

So are you planning to post your serial output as text, with triple backticks, as opposed to a screenshot?

Pete.