Instructions

KY-039 Heartbeat sensor module
ADS1015 = 0x00 # 12-bit ADC
ADS1115 = 0x01 # 16-bit
# Amplification (Gain) will be picked
gain = 4096 # +/- 4.096V
# gain = 2048 # +/- 2.048V
# gain = 1024 # +/- 1.024V
# gain = 512 # +/- 0.512V
# gain = 256 # +/- 0.256V
# Sample rate of the ADC (SampleRate) will be picked
sps = 8 # 8 Samples per second
# sps = 16 # 16 Samples per second
# sps = 32 # 32 Samples per second
# sps = 64 # 64 Samples per second
# sps = 128 # 128 Samples per second
# sps = 250 # 250 Samples per second
# sps = 475 # 475 Samples per second
# sps = 860 # 860 Samples per second
# ADC-Channel (1-4) will be picked
adc_channel = 0 # Channel 0
# adc_channel = 1 # Channel 1
# adc_channel = 2 # Channel 2
# adc_channel = 3 # Channel 3
# the ADC which is used by the KY-053 is an ADS1115 chipset adc = ADS1x15(ic=ADS1115)
# LED output pin declaration.
LED_PIN = 24
GPIO.setup(LED_PIN, GPIO.OUT, initial= GPIO.LOW)
########################################################################################
# Buzzer output pin declaration.
def heartBeatDetect(schwelle):
global maxValue
global isPeak
global result
global oldBeatTime
# Reading of the voltage at the photo transistor
# saving of the voltage value into the rawValue variable
# With "adc_channel" the channel which is connected with the ADC will be picked.
rawValue = adc.readADCSingleEnded(adc_channel, gain, sps)
# Reset of the result-variable
if result == True:
result = False
# If the difference between the current value and the last maximum value is to big
# (maybe bacause you moved the finger to strong for example)
# Here you see the reset of the maxValue to get a new basic.
if rawValue * 4 < maxValue: maxValue = rawValue * 0.8; # Detecting of the peak
if rawValue > maxValue:
maxValue = rawValue
if isPeak == False:
result = True
isPeak = True
else:
if rawValue < maxValue - schwelle:
Export: 16.06.2017 Copyright by Joy-IT - Published under CC BY-NC-SA 3.0 Page 187 of 214