HealthyWorker: Facemask addon

Taking care of workers' health in your work environment!

BeginnerWork in progress2.1 hours1,740
HealthyWorker: Facemask addon

Things used in this project

Hardware components

Colibri
×1
Resistor 270k
×1
Grove - I2C High Accuracy Temp&Humi Sensor (SHT35)
Seeed Studio Grove - I2C High Accuracy Temp&Humi Sensor (SHT35)
×1
Photo resistor
Photo resistor
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Things Stack
The Things Industries The Things Stack

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Plier, Cutting
Plier, Cutting

Story

Read more

Schematics

Mask module prototype wiring diagram

Mask module prototype wiring diagram for Colibri IoT

Code

HealthyWorker_mask_module.ino

C/C++
Firmware for the Colibri IoT or other Arduino compatible board
#include <Colibri.h>
#include "SHT30_Read.h"

// Set Sensor's I2C Address
#define SHT30_ADDRESS 0x45

LoRaModem modem;

// Set the Keys in the seperate tab
#include "LoRaWAN_Keys.h" 
String appEui = SECRET_APP_EUI;
String appKey = SECRET_APP_KEY;

// Signal Led
const int buildinLed = 5;

//Settings
#define Button 3
#define WorkingLed 4
#define LightSensorPin A1
#define LightSensorTreshold 500
#define SendingInterval 900000 //15min
#define MisuseTreshold 10

//Variables
bool ButtonTurnOn=false;
int millisValue=0; //Variable for millis() value for sending data and calculating time from last data
float Temperature = 0; //Temperature from sensor
float sumTemperature = 0; //Sum for calculating average
float BodyTemp; //Average body temperature
int LightSensor = 0; //Value from light sensor
int LightTreshold = 100; //Treshold for light sensor
uint8_t MisuseCounter=0; //Counter for misuse counting
int n = 0; // Number of mesurements -> we send data on 10 min intervals (set in SendingInterval Define)
int TurnOffTime = 0; //Time when button is off
int MisuseCount=0; //Counter of misuse

/****************************************************************************************************************************************************/
void setup() {  
  
  Serial.begin(115200);
  delay(3000);
  Serial.println("Hello Colibri IoT :)");

  pinMode(Button, INPUT_PULLUP);
  pinMode(WorkingLed,OUTPUT);
  pinMode(buildinLed, OUTPUT);

  if (!modem.begin(EU868)) {  // Use your regional band (eg. US915, AS923, ...)
    Serial.println("Error: Failed to start module!");
    while (1) {}
  };

  ledBlink(buildinLed);
  
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());
  
  Serial.println();
  Serial.println("Starting LoRaWAN JOIN procedure ...");

  if (!modem.joinOTAA(appEui, appKey)) {
    Serial.println("Error: Join procedure failed! Please move closer to the LoRaWAN GW.");
    digitalWrite(buildinLed, HIGH);
    while (1) {}
  }
  ledBlink(buildinLed);

  // Set poll interval to 60 secs. 
  modem.minPollInterval(60);
  // NOTE: independently by this setting the modem will
  // not allow to send more than one message every 2 minutes,
  // this is enforced by firmware and can not be changed.

}
/****************************************************************************************************************************************************/
void loop() {
  ButtonTurnOn=digitalRead(Button);//read Button to see if mask is in use

  if(ButtonTurnOn==false){    
    Serial.println("Device is in ready state"); //Device is not in use, we send some debugging info over serial monitor
    Serial.println();
  }

  if(ButtonTurnOn == true){
    millisValue = millis(); //start mesuring time
  }

  while(ButtonTurnOn == true){  //our main code that is called every 2 seconds
  digitalWrite(WorkingLed, LOW);

   if (SHT30_Read(SHT30_ADDRESS)) {  //if sensor is connected
      
      LightSensor = analogRead(A1); //read light sensor
    
      Temperature = SHT30_GetTemp(); //get temperature

      Serial.print("Light : ");   //print some debug info in serial monitor
      Serial.print(LightSensor);
      Serial.println(" /1023");
      Serial.print("Temperature : ");
      Serial.println(Temperature);
    }
    
    n++; //one more mesurement
    sumTemperature += Temperature;

    //misuse counter
    if(LightSensor > LightTreshold){
      MisuseCounter++;
      Serial.print("Light above treshold, Number: ");
      Serial.println(MisuseCounter);
    }

    Serial.println();
    
    //send data on set intervals
    if(millis()-millisValue > SendingInterval){ // calculate if the time has passed
    millisValue = millis();
    
    //calculate average body temperature 
    BodyTemp = sumTemperature/n;
    n=0; //set number of mesurements to 0
    sumTemperature = 0; //set sumTemp to 0

    Serial.println("Sending data"); //print some debug info in serial monitor

    // Format the data for sending   
    int TemperatureHigh = floor(BodyTemp);
    int TemperatureLow = round((BodyTemp-TemperatureHigh)*100);
    
    int errorCode;
    modem.beginPacket();
    modem.print((char)TemperatureHigh); 
    modem.print((char)TemperatureLow);

    //if misuse counter is less than misuse treshold we dont send anything.
    if(MisuseCounter>MisuseTreshold){ 
      MisuseCount = floor(MisuseCounter/MisuseTreshold);
      
      modem.print((char)MisuseCount);
      Serial.println("Misuse detected");
    }
    else{
      modem.print((char)0);
      Serial.println("No misuse detected");
    }
    MisuseCounter = 0;
    
    errorCode = modem.endPacket(true);
  
    ledBlink(buildinLed);
    
    if (errorCode > 0) {
      Serial.println("Info: Message sent correctly!");  //print some debug info in serial monitor
    } else {
      Serial.println("Error: Error sending message!"); //print some debug info in serial monitor
      Serial.println();
    }
    }
   delay(2000);
   ButtonTurnOn=digitalRead(Button); //is the mask still in use?

   if(ButtonTurnOn == false){
    TurnOffTime = millis(); //if mask is not in use add time to TurnOffTime
    }
  }

  if((millis()-TurnOffTime>10000) && (n>0)){ //if mask is not in use for more than 10 second all the data is reset. If the button is pressed again the data is preserved
    MisuseCounter = 0;
    n=0;
    sumTemperature = 0;
    Serial.println("Device restarted!"); //print some debug info in serial monitor
    } 

   //Led blinking when device in idle
   digitalWrite(WorkingLed, HIGH);
   delay(700);
   digitalWrite(WorkingLed, LOW);
   delay(3000);
}

void ledBlink(int ledPin) {
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);  
}

HealthyWorker Dashboard EN

JavaScript
HealthyWorker Dashboard in English
No preview (download only).

Credits

Rok Štrucelj

Rok Štrucelj

1 project • 4 followers
Tilen Cvenkel

Tilen Cvenkel

1 project • 1 follower
Kris Ambroželi

Kris Ambroželi

1 project • 1 follower
klemenpevec

klemenpevec

1 project • 4 followers
Luka Mali

Luka Mali

16 projects • 19 followers
Maker Pro, prototyping enthusiast, head of MakerLab, a lecturer at the University of Ljubljana, founder.
Thanks to Luka Mali.

Comments