Directe e-mail & SMS-waarschuwingen bij abnormale hartslag
Onderdelen en benodigdheden
| Hartslagsensor-module (bijv. KY-039 of Pulse Sensor) | 1 |
| Arduino Mega 2560 | 1 |
| Bolt IoT WiFi-module | 1 |
| Draadjes (jumper wires) | 7 |
Apps en online diensten
- Bolt IoT Bolt Cloud – IoT-platform
- DigitalOcean VPS (of eigen Linux-server/VM) – draait Python-monitoringcode
- Mailgun – e-mail automatisering
- Twilio SMS API – SMS-versturen
Over dit project
24/7 hartslagmonitoring (zoals fitnessbands) is gangbaar. Maar wat als je ook een SMS of e-mail krijgt bij een abnormale hartslag? Dit project laat zien hoe je dat eenvoudig realiseert.
Stap 1: Hartslagsensor aan Arduino
- Sensor OUT → Arduino pin 2
- Sensor VCC → 5V
- Sensor GND → GND
Stap 2: Arduino-code
Meet pulsen op pin 2, berekent hartslag per minuut (bpm), stuurt waarde via Serial naar Bolt-module.
unsigned long highCounter = 0;
int pulse = 0, val = 0, lastPulse = LOW;
unsigned long oldMillis = 0;
void setup() {
pinMode(2, INPUT);
Serial.begin(9600);
}
void loop() {
pulse = digitalRead(2);
if (pulse != lastPulse) {
lastPulse = pulse;
if (pulse == HIGH) highCounter++;
}
if (millis() - oldMillis >= 10000) { // elke 10 sec
oldMillis = millis();
val = highCounter * 6; // bpm
if (highCounter > 1) Serial.println(val);
highCounter = 0;
}
}
Stap 3: Bolt WiFi-module aan Arduino
- Bolt 3V3 → Arduino 3.3V
- Bolt TX → Arduino RX
- Bolt RX → Arduino TX
Hierdoor ontvangt Bolt de seriële hartslagdata.
Stap 4: Mailgun instellen (e-mail)
- Account aanmaken, telefoon verifiëren
- Domains → Add Recipient → Invite New Recipient → je e-mailadres
- Nieuwe sandbox aanmaken → credentials kopiëren (API key, sandbox URL, sender/recipient e-mail)
Stap 5: Twilio instellen (SMS)
- Registreren op twilio.com → gratis API key
- Telefoonnummer verifiëren
- Products → Programmable SMS + Phone Numbers inschakelen
- Project Info → Account SID & Auth Token noteren
- Programmable SMS → Get Started → Get a number → kies nummer → noteren
Stap 6: DigitalOcean VPS voor monitoring-code
(Of eigen Linux-machine/VM)
- Droplet aanmaken (Ubuntu), via PuTTY inloggen
sudo apt-get -y updatesudo apt install python3-pipsudo pip3 install boltiot- Bestand
conf.pyaanmaken met alle credentials (Twilio SID/Token, nummers, Mailgun key/URL, Bolt API/Device ID) - Bestand
heart_rate.pyaanmaken (zie code-sectie) sudo python3 heart_rate.pydraaien
Bij afwijkende hartslag (<57 of >100 bpm) worden SMS én e-mail verstuurd.
Code
Arduino-code
(Zie stap 2 – identiek)
conf.py (Python-configuratie)
# Twilio
SID = 'jouw_twilio_sid'
AUTH_TOKEN = 'jouw_twilio_auth_token'
FROM_NUMBER = 'twilio_nummer'
TO_NUMBER = 'jouw_nummer_met_landcode'
# Mailgun
MAILGUN_API_KEY = 'jouw_mailgun_api_key'
SANDBOX_URL = 'jouw_sandbox_url'
SENDER_EMAIL = 'test@jouw_sandbox_url'
RECIPIENT_EMAIL = 'jouw_email'
# Bolt
API_KEY = 'jouw_bolt_api_key'
DEVICE_ID = 'jouw_bolt_device_id'
heart_rate.py (Python-monitoring)
import conf, json, time
from boltiot import Email, Bolt, Sms
minimum_limit = 57
maximum_limit = 100
mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
mailer = Email(conf.MAILGUN_API_KEY, conf.SANDBOX_URL, conf.SENDER_EMAIL, conf.RECIPIENT_EMAIL)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)
while True:
response = mybolt.serialRead(2)
data = json.loads(response)
sensor_value = data['value']
try:
if sensor_value > maximum_limit or sensor_value < minimum_limit:
mailer.send_email("Alert", "The Current Heart Rate is " + str(sensor_value))
sms.send_sms("Alert! The Current Heart Rate is " + str(sensor_value))
except Exception as e:
print(e)
time.sleep(10)
Schema
Zie schematische tekening: sensor → pin 2, Bolt ↔ Serial (RX/TX gekruist), gemeenschappelijke GND.
Productieproces
- Hoe data en storytelling te gebruiken om goedkeuring te krijgen voor uw onderhoudsprojecten
- Negen Bewezen Strategieën om Je Baam Te Beveiligen en Carrièregroei Te Versnellen
- 5 Manieren Waar Anti-Seize Smeermiddelen Tijd, Geld Besparen en Hoofdpijn Voorkomen in MRO
- Snelle Reactie: Hoe We Een Plotse Stop Op Een Komori 28" Offset Pers Oplosden
- 4 Sleutelfactoren bij het Kopen van Industriële Snijmessers
- De Juiste Automatische Boosterpomp voor Uw Huis Kiezen: Een Praktische Gids
- Schroeven en Bouten: Typen, Toepassingen en Optimale Montage
- Schroef vs. Bout: Belangrijkste Verschillen, Typen en Toepassingen
- Sales e-mails onder de knie krijgen: Aandacht grijpen & leads converteren
- Expert Gids: Uw Oplosmiddel Terugwinning Distilleerketel Onderhouden Voor Topprestaties
- Optimaliseren Van Graafmachine En Vrachtwagen Pairings Voor Maximale Efficiëntie En Winst In Mijnbouw