Heart beat sensor (KY 039) Interfacing with ESP8266
Program
const int heartbeatSensorPin = A0; // Analog pin connected to the Heartbeat Sensor module
const int ledPin = 3; // Digital pin connected to the LED (optional)
void setup() {
pinMode(heartbeatSensorPin, INPUT); // Set the Heartbeat Sensor pin as INPUT
pinMode(ledPin, OUTPUT); // Set the LED pin as OUTPUT (optional)
Serial.begin(9600); // Initialize serial communication for debugging (optional)
}
void loop() {
int heartbeatValue = analogRead(heartbeatSensorPin); // Read the analog value from the Heartbeat Sensor
int heartbeatRate = map(heartbeatValue, 0, 1023, 40, 220); // Map the sensor value to a heartbeat rate range (40 to 220 BPM)
Serial.print("Heartbeat Rate (BPM): ");
Serial.println(heartbeatRate); //
}
Comments
Post a Comment