Activity: Internet of Thing (IoT)
After done with the measurement of respiration rate we proceed with IoT. This is important to transfer the data to the doctor. The module for this IoT was NodeMCU. NodeMCU act as IoT module was used to transfer the data that have recorded. Arduino Uno module did not use in this part because all the program from the Arduino has been transferred to the NodeMCU. To start using the NodeMCU, a program and a new project in a Blynk app been created. Each new project has the specific token number that must be set in the program. When the new project is creating, the Blynk app will send the specific token number to the email that makes the project can be connected to the selected specific WiFi. The token number was inserted in the program. NodeMCU has to know the WiFi credential by set the network name and password to make it function to transfer the data.
Token gets through E-mail when creating a new project.
ID number and password for the WiFi credential.
Result from the Blynk when the normal respiration rate per minutes was recorded.
Result from the Blynk when the abnormal respiration rate per minutes was recorded.
The coding used for the IoT was;
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c484633147bc43a5b8189359ddeee344";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "PykaaHishan";
char pass[] = "pykaahishan96";
unsigned long prevRespTime = 0;
unsigned long currRespTime = 0;
respState currentRespState;
int movingAvgRespRate = 0;
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
Blynk.run();
int sensorValue = analogRead(A0);
if (sensorValue > 510 && currentRespState == Exhaling)
{
currentRespState = Inhaling;
prevRespTime = currRespTime; // save time from last cycle
currRespTime = millis();
float period_respiration = currRespTime - prevRespTime;
float breathrate = 60000 / period_respiration;
Serial.print("Inhaling \tRespirations per minute: ");
Serial.println(breathrate);
if (breathrate>1 && breathrate<9)
{
digitalWrite(9,HIGH);
delay(2000);
digitalWrite(9,LOW);
delay(200);
}
if (breathrate>60 && breathrate<100)
{
digitalWrite(9,HIGH);
delay(1000);
digitalWrite(9,LOW);
delay(200);
}
else if (breathrate>101 && breathrate<500 )
{
digitalWrite(9,HIGH);
delay(500);
digitalWrite(9,LOW);
delay(200);
}
else
{
digitalWrite(9,LOW);
}
}
else if (currentRespState == Inhaling && sensorValue < 490)
{
currentRespState = Exhaling;
Serial.println("Exhaling");
}
Serial.println(sensorValue);
Blynk.virtualWrite(V5,breathrate);
}