Hello, I'm working on a project related to ECG (electrocardiogram) measurements, but I'm facing an issue that I can't resolve. I would like to ask for your advice since the deadline for this project is approaching. I am using the DOIT ESP-32 Development Board (ESP-WROOM-32) Wifi+Bluetooth ESP32 ESP-32S along with the AD8232. I am attaching the code I’ve written and the resulting graph. Thank you for your kindness in pointing out any mistakes.
Code
const int ecgPin = 36;
const int thresholdLow = 300;
const int thresholdHigh = 700;
// กำหนดขอบเขตค่าของกราฟ
const int graphMin = -200;
const int graphMax = 200;
void setup() {
Serial.begin(115200);
Serial.println("เริ่มต้นการวัด ECG...");
}
void loop() {
int ecgValue = analogRead(ecgPin);
int scaledValue = 0;
if (ecgValue > thresholdLow && ecgValue < thresholdHigh) {
scaledValue = map(ecgValue, thresholdLow, thresholdHigh, graphMin, graphMax);
} else {
scaledValue = 0;
}
Serial.println(scaledValue);
delay(10);
}
picture

