This project consists of 2 devices. the first one is wearable and monitors temperature, second one will control the temperature.
Things used in this project
Story
Introduction
This project consists of 2 devices, the first one is wearable mkr1000 with battery and temperature and humidity sensor, the mkr1000 send temperature and humidity to Artik cloud. Now doctors can observe patient’s fever and sweating of patient, and if temperature goes too high or low. Artik will send email to doctor and send action to second device! Second device is a mkr1000 that control cooler with relay!
how it works
Adding libraries to Arduino
Open Arduino ide go to sketch>>include library>>manage libraries.
Now search and install MQTTClient.h, ArduinoJson.h, WiFi101.h, dht.h.
Making cloud ready!
Go to https://developer.artik.cloud/dashboard/devicetypes and click on +new device type.
now go to https://artik.cloud/my/devices
go to https://developer.artik.cloud/dashboard/devicetypes again and create new device.
now build a new device type again.
leave device fields and go to device actions and add an action
now click on new parameter
name it and choose data type
now activate manifest.
activate manifest.
now go back to https://artik.cloud/my/devices
generate device token for your new device and then go to rules.
create new rule
(^.^)
select your device
then choose parameter
choose (is more than)
human body 37 degrees
choose device that you want to send actions to.
choose device that you want to send actions to.
add value to action. cooler controller turn on the cooler by receiving true amount.
add new action(sending email)
create email
now save the rule! when patient has fever this action will turn on cooler, and cool down the body.
now you can see your rule.add another rule that turn off the cooler by sending action switch(false) to cooler controller device.
Wearable device
The wearable device is the simple part! you just connect your DHT module to mkr1000 and power it with battery or power bank. Connect the +&- of DHT to 5V & GND and connect out pin to the A0 of mkr1000.
these data is my body’s. I put DHT in front of laptop fan to activate action!
Cooler controller
Open the cooler controller code and replace wifi name and password, device id and device token. upload it to mkr1000.
I use a voltage protector to connect relay to cooler because it is more safe!
open it
disconnect one of outlet wiresconnect the disconnected wires to the relayattach shot wire to outletnow connect outlet to relay
connect jumper wires to relay
Relay work’s with 5V, but mkr1000’s digital write is 3.3V. so we need logic level converter.
At first we connect 5V to HV and GND to GND. Then we connect 6 pin of mkr1000 to LV (because we have digital write, high to 6 pin and it’s voltage is 3.3 like our signal voltage).vNow we send signals through one of logic level converter’s channels.
RGB led show’s the status. Green means that cooler is on and red means off!
Now every thing is OK! You can sit and enjoy your fever while Artik is controlling your body temperature.
Schematics
Code
cooler controller
C/C++
/*
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);
}
}