Mahdi Hajebi
Published © GPL3+

Controlling Patient's Fever with Artik & Arduino

This project consists of 2 devices. the first one is wearable and monitors temperature, second one will control the temperature.

IntermediateShowcase (no instructions)Over 2 days14,716

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×2
SparkFun Logic Level Converter - Bi-Directional
SparkFun Logic Level Converter - Bi-Directional
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Relay Module
×1
Resistor 1k ohm
Resistor 1k ohm
×2

Software apps and online services

Arduino IDE
Arduino IDE
ARTIK Cloud for IoT
Samsung ARTIK Cloud for IoT

Story

Read more

Schematics

cooler controller

Code

fever monitor

C/C++
this code send data to Artik cloud from wearable device.
/*
PATIENT'S FEVER & SWEATING MONITORING!
you nead mkr1000 & DHT module(temperature and humidity sensor)!
Attach the OUT pin of a DHT to pin A0, the + pins to +5V, and - to ground fo mkr1000!
this code measure temperature and humidity on the skin of paitent and send them to artik cloud!
 */
 
//libraries 
#include <MQTTClient.h>     //  MQTT messaging protocol library!
#include <ArduinoJson.h>    // sending data with Json format library!
#include <WiFi101.h>        // conecting mkr1000 to internet library!
#include <dht.h>            // temperature and humidity sensor library!

//wifi parameters
char WIFI[]     = "^your ssid^";            // your wifi name
char PASSWORD[] = "^your password^";    // your wifi password

//cloud parameters
char CloudServer[]     = "api.artik.cloud";                                             // artik cloud server
int  MQTTPort          = 8883;                                                          // MQTT protocol port
char Did[]             = "^your device id^";                                            // your device id
char Dtoken[]          = "^your device token^";                                         // your device token
char CloudDataOut[]    = "/v1.1/messages/^your device id^";              
char ClientName[]      = "ARTIK-Arduino";                                               // your client's name

char buf[128];   // data storage in buf before going to cloud!

//building objects
WiFiSSLClient ipCloudStack;
MQTTClient mqttCloudClient;
dht DHT;


void setup() 
{

  Serial.begin(9600);  
  WiFi.begin(WIFI, PASSWORD);                                              //starting wifi
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("attempting connect to : ");
    Serial.println(WIFI);
  }
  Serial.println();
  Serial.println("WiFi connected");
  
  mqttCloudClient.begin(CloudServer, MQTTPort, ipCloudStack);             // connecting to artik cloud

  Serial.println("start ARTIK Cloud connect"); Serial.println();
  
  while (!mqttCloudClient.connect(ClientName, Did, Dtoken)) {             //connecting to device
    Serial.print("*");
    delay(500);    
  }

}


void loop() 
{

  Serial.println("sending data to cloud");
  sendToArtikCloud();                                     // sending data to cloud
  delay(60*1000);                                         // wait 60s!

}



void sendToArtikCloud() 
{
  
  loadBuffer();                                    // making data ready in Json format
  mqttCloudClient.publish(CloudDataOut, buf);      // sending data to cloud

}


void loadBuffer()                                        // this function make data redy for sending in Json format!
{

  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& dataPair = jsonBuffer.createObject();
  DHT.read11(A0);                                       // reading temperature & humidity
  dataPair["temp"] = DHT.temperature;                   // adding temperature value to Json
  dataPair["humidity"] = DHT.humidity;                  // adding humidity value to Json
  dataPair.printTo(buf, sizeof(buf));
  
}

void messageReceived(String topic, String payload, char * bytes, unsigned int length)
{
  
  }

cooler controller

C/C++
this code receive actions from Artik cloud. and control the cooler with them
/*
 controling cooler with artik actions!
 connect relay to digital 9 pin!
 */
//libraries 
#include <MQTTClient.h>     //  MQTT messaging protocol library!
#include <ArduinoJson.h>    // sending data with Json format library!
#include <WiFi101.h>        // conecting mkr1000 to internet library!

//wifi parameters
char WIFI[]     = "^your ssid^";            // your wifi name
char PASSWORD[] = "^your password^";    // your wifi password



//cloud parameters
char CloudServer[]     = "api.artik.cloud";                             // artik cloud server
int  MQTTPort          = 8883;                                          // MQTT protocol port
char Did[]             = "^your device id^";                            // your device id
char Dtoken[]          = "^your device token^";                         // your device token
char CloudDataOut[]    = "/v1.1/messages/^your device id^";              
char ClientName[]      = "ARTIK-Arduino";
char CloudActionsIn[] = "/v1.1/actions/^your device id^";               // (/v1.1/actions/"DEVICE ID") 


char buf[200]; // Json Data to Artik Cloud  

//building ubjects
WiFiSSLClient ipCloudStack; 
MQTTClient mqttCloudClient; // MQTT Protocol


int relayPIN=9;
int redled=7;
int greenled=8;

 
 
void setup() 
{
  pinMode(relayPIN,OUTPUT);
  pinMode(redled,OUTPUT);
  pinMode(greenled,OUTPUT);
  //providing low 3.3V for logic level converter
  pinMode(6,OUTPUT);
  digitalWrite(6,HIGH);
  Serial.begin(9600);  
  WiFi.begin(WIFI, PASSWORD);                                 //connecting to wifi
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print("attempting connect to : ");
    Serial.println(WIFI);
  }
  Serial.println();
  Serial.println("WiFi connected");
  
  mqttCloudClient.begin(CloudServer, MQTTPort, ipCloudStack); // Connecting to Artik cloud 
  while (!mqttCloudClient.connect(ClientName, Did, Dtoken))   // connecting to device
  { 
    Serial.print("not connected to device"); 
    delay(1000); 
  } 
mqttCloudClient.subscribe(CloudActionsIn); 

}



void loop()
{ 

  //waiting for actions
  Serial.println("listening...");
  mqttCloudClient.loop();
  delay(10000);
}


void messageReceived(String topic, String payload, char * bytes, unsigned int length) { 
  Serial.print("data from artik cloud:"); 
  Serial.println(payload);  
  parseBuffer(payload); 
 
}


void parseBuffer(String _payload)     //translating data from Json format
{
   
StaticJsonBuffer<200> jsonBuffer; 
String json = _payload; 
JsonObject& root = jsonBuffer.parseObject(json);
boolean ACS = root["actions"][0]["parameters"]["sw"];   //ACS = order from Artik

if (ACS)                         //turning on
{
  digitalWrite(relayPIN,LOW);
  digitalWrite(greenled,HIGH);
  digitalWrite(redled,LOW);  
}
else                            //turning off
{
  digitalWrite(relayPIN,HIGH);
  digitalWrite(greenled,LOW);
  digitalWrite(redled,HIGH); 
}

}  

Credits

Mahdi Hajebi

Mahdi Hajebi

3 projects • 24 followers
studying mechanical engineering at hormozgan university.

Comments