I didn't think I could use tone() since the pulsesensor site said using this would disable the tone command.
You didn't mention that before. The easiest solution is to use an active buzzer. You feed it 5V and it makes a noise so it can be turned on and off using digitalWrite() but a simple digitalWrite() will not work with a passive buzzer because it expects the voltage to be turned on and off at the required frequency.
The tone() command uses an interrupt routine in the Arduino chip to do its timing and I suspect that it would interfere with the interrupt used by the heartrate monitor. You could write your own version of tone() but at your level expertise I don't suggest doing it. My advice would be to get an active buzzer,
In the meantime try printing a message when the BPM goes below the threshold
I do have an active buzzer and just changed it over. I have added this code on it's own and it works in its own sketch but not in the code. Do you think it will work and if so, can you tell me where on earth it would go in my code?
if ("BPM" < 55)
{
analogWrite(buzzerPin, 255);
}
Also, the message about BPM going below the threshold, how do I do that?
If all you want to do is to turn on the active buzzer then you may as well use digitalWrite() rather than analogWrite()
if (BPM <= 55)
[
digitalWrite(buzzerPin, HIGH); //turn on the buzzer
Serial.println("Low BPM alarm");
}
else
{
digitalWrite(buzzerPin, LOW); //turn off the buzzer
}
Put the buzzer activation at the end of loop() but note the else clause to turn it off if BPM is not below the low
I teach a technology class for grades K through 8. We incorporate a lot of STEM and Design thinking lessons but this particular project was like a science fair project for them. They came up with the design but were not sure how to complete the code. I was just teaching them how to connect the arduino but the coding I am still getting better at myself. At the moment, they can use block programming and have yet to transition to text programming. Thank you again for all of your assistance!