#define BLYNK_TEMPLATE_ID "TMPL6uDV5rQPS"
#define BLYNK_TEMPLATE_NAME "MUSCLE STRAIN DETECTOR"
#define BLYNK_AUTH_TOKEN "wlyocZLhCWg9i4qZtJrnxtICnqE9K77-"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
const char* ssid = "";
const char* password = "";
const int potPin = A0; // Pin connected to the potentiometer
const int buzzerPin = 12; // Pin connected to the buzzer
int threshold = 30 ; // Example threshold for muscle strain percentage
#define VIRTUAL_PIN_STRAIN_LEVEL V0
BlynkTimer timer;
void sendDataToBlynk() {
// Read the analog value from the potentiometer
int sensorValue = analogRead(potPin);
// Map the analog value (0-4095 on ESP32) to a meaningful strain range (e.g., 0-100%)
int strainPercent = map(sensorValue, 0, 4095, 0, 100);
Blynk.virtualWrite(VIRTUAL_PIN_STRAIN_LEVEL, strainPercent );
// Print the strain percentage
Serial.print("Muscle Strain: ");
Serial.print(strainPercent);
Serial.println("%");
// Check if strain exceeds threshold
if (strainPercent > threshold) {
tone(buzzerPin,100);
delay(500);
noTone(buzzerPin);
delay(500);
}
}
void setup() {
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
WiFi.mode(WIFI_STA);
WiFi.begin("Wokwi-GUEST", "");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Blynk.begin(BLYNK_AUTH_TOKEN, "Wokwi-GUEST", "");
// Setup timer to send data to Blynk every 2 seconds
timer.setInterval(2000L, sendDataToBlynk);
}
void loop() {
// Read the analog value from the potentiometer
int sensorValue = analogRead(potPin);
// Map the analog value (0-4095 on ESP32) to a meaningful strain range (e.g., 0-100%)
int strainPercent = map(sensorValue, 0, 4095, 0, 100);
// Print the strain percentage
Serial.print("Muscle Strain: ");
Serial.print(strainPercent);
Serial.println("%");
// Check if strain exceeds threshold
if (strainPercent > threshold) {
tone(buzzerPin,100);
delay(500);
noTone(buzzerPin);
delay(500);
}
Blynk.run();
timer.run();
delay(500); // Delay for stability
}