Heart rate sensor giving constant read of 1023

I am using the KY-039 heart rate sensor and the serial monitor is giving me a constant read of 1023. Any idea why this is happening? Code below:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27 ,20,4);

int analogPin = A6;
int ECGVal = 0;

void setup() {

Serial.begin(9600);

lcd.init();
lcd.backlight();
lcd.clear();

}

void loop() {

ECGVal = analogRead(analogPin);
float ECGvoltage = ECGVal*(1);

Serial.println(ECGvoltage);

lcd.setCursor(0, 0);
lcd.print("BPM: ");

lcd.setCursor(5, 0);
lcd.print(ECGvoltage);
}

use code tags to post your code.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27 ,20,4); 

int analogPin = A6;
int ECGVal = 0;


void setup() {

  Serial.begin(9600);
  
  lcd.init();
  lcd.backlight();
  lcd.clear();


}


void loop() {

  ECGVal = analogRead(analogPin);
  float ECGvoltage = ECGVal*(1);
  
  Serial.println(ECGvoltage);
  
  
  lcd.setCursor(0, 0);
  lcd.print("BPM: ");


  lcd.setCursor(5, 0);
  lcd.print(ECGvoltage);
}[color=#222222]

1023 would represet a full votls reading or a nothing connected to the pin?

By using code tags, the thread is less likely to devolve into a lesson on how to use this site and more towards helping you out with your issue.

Carefully check your connections and include a schematic with your next post. And post a picture of your project.

What board are you using?

I'm using the MKR 1000 board. I have attached a picture of my project but don't have any software to make a schematic. From what is can tell everything is wired correctly.

The signal pin of the heart rate sensor is connected to A6 with the middle to live and the other to ground.

The LCD is working fine with SDA and SCL of the LCD going to the boards SDA and SCL pins.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27 ,20,4);

int analogPin = A6;
int ECGVal = 0;

void setup() {

  Serial.begin(9600);
 
  lcd.init();
  lcd.backlight();
  lcd.clear();

}

void loop() {

  ECGVal = analogRead(analogPin);
  float ECGvoltage = ECGVal*(1);
 
  Serial.println(ECGvoltage);
 
  lcd.setCursor(0, 0);
  lcd.print("BPM: ");

  lcd.setCursor(5, 0);
  lcd.print(ECGvoltage);

  delay(300);
}

You can draw a schematic on paper, take photo, post photo?

So when you move the wire from the heart sensor that goes to A6 and you put it to ground, does the A:D value on the monitor change to less then 1023?

I attached a schematic.

When I connect A6 to ground I get values from 6 to 10.

When I connect the signal pin of heart sensor to ground the values go from 220 to 310.

OK so when the wire connection is removed from the sensor and put to ground, so that A6 receives a ground, the value goes low. That being the case the A:D converter receives an input, responds to the input, and the code produces an output related to the change. Reads like the sensor is not doing the thing.

Also, from what I read, https://www.arduinoforbeginners.com/ky-039_arduino_heartbeat_sensor/ do not expect all that great performance out of the sensor.


Looking over the schemo and pic, even though I am not familiar with the MKR1000 (I did review a pinout diagram), it looks that there is a good connection to the sensor, and it obvious that the connection and code is good for the LCD. That you can cause a change to A6 and that change is reflected in code to the monitor, I'd say there is a sensor issue.