I'm trying to read in an analog signal (a heartbeat) to pin A0 on the Arduino Uno and then convert it to digital. I'm hoping to use the digital signal to make an LED light up every time the voltage of the heartbeat signal goes over 1 volt. This is the code I have right now, but something is wrong because it isn't lighting up the LED.
unsigned int analog0; // Raw data from A0 ranging from 0 to 1023
unsigned long data_range = 2000; // Length of time to record data for
double volts; // The analog data from A0 converted to volts
int ledPin = 13;
unsigned long start_time;
unsigned long data_time;
void setup() {
Serial.begin(9600); // Initialize and set serial port baud rate
pinMode(ledPin , OUTPUT);
}
void loop() {
start_time = millis();
while ((millis() - start_time) < data_range)
{
// Record current time of analog acquisition
data_time = millis();
// Record analog data on A0
analog0 = analogRead(0);
// Convert raw data into voltage
volts = (analog0 / 1023.0) * 5;
Serial.print(volts);
Serial.println();
// Slow the rate of data acquisition
//delay(1);
if (volts > 1.5){
digitalWrite(ledPin, HIGH);
//delay(50);
}
else{
digitalWrite(ledPin, LOW);
}
}
}