(deleted)
Put the code in loop() of the second sketch in a function in the first one to start creating a combined sketch
Copy the declarations used, such as motorPin from the second sketch to the combined sketch
Copy the single line of code from setup() in the second sketch to setup() in the combined sketch
Make sure that no pins are being used for 2 variables in the combined sketch and adjust them and their wiring if there is a clash
Now, in the combined sketch, when a heartbeat is detected call the new function in the combined sketch. Note that as written the delay() function will stop heartbeats being detected for 2 seconds but depending on your requirements this may or may not be a problem
(deleted)
Well, my suggestion was to put the code to pulse the vibration motor in its own function and to call that when needed but it is OK to put it in loop() so that it runs when you want it to, but I am not clear when you want it to run
You also seem to have forgotten to copy the pinMode() for motorPin into setup() as I suggested
Copy the single line of code from setup() in the second sketch to setup() in the combined sketch
(deleted)
This is a function that executes the code to vibrate the motor. Call it when you need it just like any other function
void vibrateMotor()
{
digitalWrite(motorPin, HIGH); //vibrate
delay(1000); // delay one second
digitalWrite(motorPin, LOW); //stop vibrating
delay(1000); //wait 50 seconds.
}
This is the new combined heartbeat sensor and vibration motor code :
Does it compile ?
(deleted)
can you show me how to call out the function of the motor? I want to make the motor vibrate when the heartbeat is between 80 - 85 BPM.
if (beatsPerMinute >= 80 && beatsPerMinute <= 85)
{
vibrateMotor();
}
(deleted)
The test of BPM and hence the call to vibrateMotor() is inside the test for irValue being greater than 7000. Are you seeing the BPM value on the screen ?
Put a print statement inside the vibrateMotor() function. Is it even being called ?
Print the value of beatsPerMinute just before you test it. Is it ever between 80 and 85 ?
(deleted)