Santiago Ortega
Created July 16, 2020 © GPL3+

TinTracker Initiative

An IOT System that measures waste levels in hospitals and shares it on real time, for effective recollection of COVID-19 waste

IntermediateFull instructions providedOver 1 day39
TinTracker Initiative

Things used in this project

Hardware components

Arduino MKR WiFi 1010
Arduino MKR WiFi 1010
10
×10
Adafruit VL53L0x
10
×10
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
10
×10
Amazon Alexa Generic USB Wall Charger Adapter
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Code

Project Prototype

C#
An Arduino IOT Cloud code, using Arduino Web Editor
#include "thingProperties.h" // Library for IoT Cloud
#include <Arduino_MKRENV.h> // Library for MKR ENV Shield
#include <Arduino.h>        // required before wiring_private.h
#include <wiring_private.h>

Uart Serial3 (&sercom3, 1, 0, SERCOM_RX_PAD_1, UART_TX_PAD_0); // Definition of TX on D0 (SERCOM3.0) and RX on D1 (SERCOM3.1)

void SERCOM3_Handler()    // Interrupt handler for SERCOM3
{
  Serial3.IrqHandler();
}

void getTFminiData(int* distance, int* strength) {
  static char i = 0;
  char j = 0;
  int checksum = 0; 
  static int rx[9];
  if(Serial3.available()) {  
    rx[i] = Serial3.read();
    if(rx[0] != 0x59) {
      i = 0;
    } else if(i == 1 && rx[1] != 0x59) {
      i = 0;
    } else if(i == 8) {
      for(j = 0; j < 8; j++) {
        checksum += rx[j];
      }
      if(rx[8] == (checksum % 256)) {
        *distance = rx[2] + rx[3] * 256;
        *strength = rx[4] + rx[5] * 256;
      }
      i = 0;
    } else {
      i++;
    } 
  }  
}

void setup() {
 // Initialize serial and wait for port to open:
 Serial.begin(9600);
 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
 delay(1500); 
 // Defined in thingProperties.h
 initProperties();
 // Connect to Arduino IoT Cloud
 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
 /*
    The following function allows you to obtain more information
    related to the state of network and IoT Cloud connection and errors
    the higher number the more granular information you’ll get.
    The default is 0 (only errors).
    Maximum is 4
*/
 setDebugMessageLevel(4);
 ArduinoCloud.printDebugInfo();
 if (!ENV.begin()) {
   Serial.println("Failed to initialize MKR ENV shield!");
   while(1); // To see if MKR ENV is working
 }
  
  /*
     We have to tell the Arduino core to change the MUX type before we reassign the SERCOM to this pin
     You can do that by calling pinPeripheral(pinnumber, function) which is an internal function.
     Assign pins 3 & 4 SERCOM functionality
 */
  Serial3.begin(115200); // Start serial connection
  
  pinPeripheral(0, PIO_SERCOM); //Assign TX function to pin 0
  pinPeripheral(1, PIO_SERCOM); //Assign RX function to pin 1
  
}
void loop() {
 
 ArduinoCloud.update(); // Read sensors
 // Your code here 
 humidity = int(ENV.readHumidity());

 temperature = int(ENV.readTemperature());

 delay(1000); 
  
int distance = 0;
int strength = 0;

  getTFminiData(&distance, &strength);
  while(!distance) {
    getTFminiData(&distance, &strength);
    if(distance) {
      Serial3.print(distance);
      Serial3.print("cm\t");
      Serial3.print("strength: ");
      Serial3.println(strength);
    
    capacidad= distance/95.00*100;
    dist = distance;
    }
  }
}
        
void onHumidityChange() {
 // Do something
}

void onTemperatureChange() {
 // Do something
}

Credits

Santiago Ortega

Santiago Ortega

1 project • 0 followers

Comments