First construct the Circuit to connect Arduino to Pulse Sensor
The heart pulse has tree terminals, in order left to right they are: analog sinal, VCC 5v and GND. Just connect directly to the ports Analog input 0, 5v and GND in your Arduino.
Preparing Watson IoT Platform
- First you log into your Bluemix account and select CATALOG and in Service select Internet of Things and create an platform of IoT.
- In the next screen will be show an wizard to create your IoT server, is importante to select the free version of this.
- Than, when you finish creation of server the painel of Watson IoT will be show, just click in active painel.
- Than, on the dashboard , just click in the icon of devices, and select add new.
- Than, into the wizard of creating a new device, you have to first create a new device type. In the device type creation just put an name and take notes the name to use in future arduino connection.
- Now you can go back to creation device wizard, select the device type you just created and in the next step junt inform the device ID. That device ID we will use to arduino connection configuration too.
- The last screen will show the most important informations that you must take notes: organization ID, device type, device id and the auth token.
Creating arduino code
The next step is create the code to arduino connect to Watson IoT Service. This code is an mixing of two examples: first this from Bradford Needham that is an special verson to work in mkr1000 and read pulse sensor signal (download original here) and this another code from Joël Gähwiler that is an simple mqtt client example (download here). Its important that the code need to be completed with the organization ID, device type, device ID, auth Token, wifi SSID e wifi Password.
When the code was upload and runing into arduino you can check if its working using the arduino console, and into the watson iot the detail of device show the packages that was received.
Processing data from Watson IoT
Now we can create an service that consumes data from our Watson Iot server, for that just create an application into Watson Iot to co generate the key.
Than you go back to IBM Bluemix Catalog and create an app type Node-RED.
Wait for wizard finish the Node-RED service and than access the configuration, we create an flow that uses de IBO Iot client to the the messages from Watson IoT and filter the value of BPM heart rate using switch, than if the BPM is between 700 and 900 per second they uses Twilio API to send SMS.
Thats the IBM IoT client configuration: