Twitter icon
Facebook icon
LinkedIn icon
Google icon
Reddit icon
StumbleUpon icon
Del.icio.us icon

IoT Medical Storage Monitor with AVR-IoT and Adafruit IO

Added to IoTplaybook or last updated on: 03/01/2021
IoT Medical Storage Monitor with AVR-IoT and Adafruit IO

Story

Introduction

Storage of medical supplies may require precise storage conditions, such as temperature-sensitive vaccines and drugs. In pharmacies and medical storage areas, the temperature of the storage location must be checked periodically. And urgent action must be taken if the temperature falls outside the required range.

To give an example, this is a screenshot of a temperature log sheet for the Moderna COVID-19 vaccine. It is provided online by the CDC to be printed out for medical staff to use.

Here it is noted that the medical staff must manually measure and record down the temperatures. Immediate action is required if the temperature falls outside the specified range.

Things used in this project

Hardware components

AVR-IoT WG Development Board
Microchip Technology AVR-IoT WG Development Board
 
× 1

Microchip

 
Gwiot 7941E RFID Reader
https://github.com/gutierrezps/gwiot7941e
× 1  

Software apps and online services

 
Adafruit IO
 
   
Arduino IDE
Arduino IDE
 
  Arduino

Problems Identified

Here we can identify a few problems with the manual approach:

1. Labour-intensive
Due to the pandemic caused by the virus, medical staff are already short-handed. If we could automate the process, it means that they can focus on other important tasks.

2. Insufficient monitoring
The temperatures are taken only twice a day in the above example (AM & PM). If a temperature deviation were to occur, it will only be detected hours later and the medical supplies might already be unusable. If we have a real-time monitoring, immediate action can be taken before any damages occur to restore the temperature as soon as possible.

Solution proposed

In this project, I propose a modular IoT device to do real-time tracking of temperature and other environmental factors such as light. The interval of tracking will be more frequent and less error prone, allowing the medical staff to monitor the conditions with more granularity.

Medical staff can tap their card on a card reader whenever they need to access the storage area. This is because some areas may require security and accountability too.

Below, I will demonstrate how to create the system using the Microchip AVR-IoT WG development board and connecting it to Adafruit IO cloud service.

Setup Board Files for Arduino IDE

Open up Arduino IDE.

Go to File > Preferences.

Enter the following URL in Additional Boards Manager URLs:

https://mcudude.github.io/MegaCoreX/package_MCUdude_MegaCoreX_index.json

Open up Tools > Board > Boards Manager and install MegaCoreX.

After it has been installed, you can choose ATmega4808. Also make sure the Pinout is the "32 pin standard"

The programmer on the AVR-IoT WG is the nEDBG.

You can upload this test code which I made for the AVR-IOT WG Board. It is code to blink all 4 LEDs.

#define LED_RED            (PIN_PD0)
#define LED_YELLOW         (PIN_PD1)
#define LED_GREEN          (PIN_PD2)
#define LED_BLUE           (PIN_PD3)

void setup() {
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_YELLOW, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_BLUE, OUTPUT);
}

void loop() {
  digitalWrite(LED_RED, LOW);
  delay(100);
  digitalWrite(LED_YELLOW, LOW);
  delay(100);
  digitalWrite(LED_GREEN, LOW);
  delay(100);
  digitalWrite(LED_BLUE, LOW);
  delay(100);
  
  digitalWrite(LED_RED, HIGH);
  delay(100);
  digitalWrite(LED_YELLOW, HIGH);
  delay(100);
  digitalWrite(LED_GREEN, HIGH);
  delay(100);
  digitalWrite(LED_BLUE, HIGH);
  delay(100);
}

Pinout for AVR-IoT WG

The AVR-IOT WG uses the ATmega4808 in a 32 pin package.

This is the Arduino pinout provided by MegaCoreX
This is the Arduino pinout provided by MegaCoreX

Pin connections for LED (active-low):

  • LED_RED = PD0
  • LED_YELLOW = PD1
  • LED_GREEN = PD2
  • LED_BLUE = PD3

Pin connections for temperature sensor (MCP9808 with I2C):

  • I2C address = 0x18
  • I2C SDA = PA2
  • I2C SCL = PA3

Pin connections for light sensor (TEMT6000)

  • Analog read on PD5

Pin connections for WiFi (WINC1510 module with SPI)

  • SPI MOSI = PA4
  • SPI MISO = PA5
  • SPI SCK = PA6
  • WIFI CS = PA7
  • WIFI IRQ = PF2
  • WIFI RST = PA1
  • WIFI EN = PF3

Install relevant libraries for the AVR-IoT WG

These are the built-in devices on the board:

  • TEMT6000 Light sensor
  • MCP9808 Temperature sensor
  • WINC1510 WiFi ModuleWINC1510 WiFi Module

There are Arduino libraries for each of them, so we need to install them too.

For the MCP9808 Temperature sensor, install Adafruit MCP9808 Library.

For the WINC1510 WiFi Module, install the official Arduino WiFi101 library.

For the TEMT6000 Light sensor, no library is needed and we can read an analog pin to get the lightpercentage like this:

int reading = analogRead(LIGHTSENSORPIN); //Read light level
float percent = reading / 1023.0 * 100; //Get percent of maximum value (1023)

Test that the WiFi module works

Open up the WiFiSSLClient example.

Add the following lines to the beginning of the setup() function.

WiFi.setPins(
    PIN_PA7, // CS
    PIN_PF2, // IRQ
    PIN_PA1, // RST
    PIN_PF3 // EN
  );

Also input your WiFi credentials

Upload it and you should see the Google page being printed to the serial monitor.

Update the SSL Certificate for Adafruit IO

As we will be connecting to Adafruit IO, we need to upload the certificate for “io.adafruit.com” to the WiFi module.

Adafruit has published some guides on how to do so, but I will also go through the instructions specifically for the AVR-IoT WG Board below.

First open up the example for the WiFi101 Firmware Updater.

Add the following lines to the beginning of the setup() function.

Serial.begin(1000000);
  WiFi.setPins(
    PIN_PA7, // CS
    PIN_PF2, // IRQ
    PIN_PA1, // RST
    PIN_PF3 // EN
  );

It should look like this. Once you have edited the code, upload it to the board

In short, we are setting the pin connections in the library to be that of the AVR-IoT WG pinout. The serial communication between the ATmega4808 to the WiFi module is also set to have a baud rate of 1000000.

Note:
The baud rate of 1000000 is not actually documented well and I had to look into the back-endcode to figure this out.https://github.com/arduino/WiFi101-FirmwareUpdater-Plugin/blob/659735277fd8c10a474782b63e1d999d681d3bbf/src/cc/arduino/plugins/wifi101/UpdaterImpl.java#L67-https://github.com/arduino/WiFi101-FirmwareUpdater-Plugin/issues/44

Next, open up the Firmware Updater tool.

Choose the correct COM port and test that the communication to the WiFi module is working by clicking "Test connection".

Click on "Add domain" and type in "io.adafruit.com".

If all is well, you will see a success message.

Setup Adafruit IO dashboard

Go to Adafruit IO. You should see your dashboards in your account.

Click on "Newdashboard" and enter the name for this project.

The new dashboard will reflect on the page, let's click on it to set it up.

You will see an empty dashboard. Create a new block.

Here you will see options for many blocks.

I'm going to choose the following blocks.

  • Line chart: for temperaturesensor
  • Gauge: for light sensor
  • Stream: for entry log

After choosing line chart, I created a "temp" feed and selected it for the line-chart.

You can change the parameters of the line chart, I simply filled in the title and left the rest at default.

Similarly, for stream block and gauge block, I created each a feed for "entry-log" and "light" respectively.

Your dashboard will look like this now

Connecting AVR-IoT to Adafruit IO

On Adafruit IO, click on "My Key". These will be the credentials you put into the Arduino code, do not share it publicly with others.

The key will be placed in the code in board_secrets.h

Now with the IoT cloud dashboard fully set up, we can create our application!

Application Wiring & Block Diagram

I will make use of the Gwiot 7941E RFID module which is a 125kHz RFID Card Reader Module.

Connect the Gwiot 7941E's TXD to the AVR IoT's RX pin. Also connect VCC to 3V3 and GND to GND. (Note that although the module states that it needs 5V, it is fine to power it with 3V3 only. It also saves us the trouble of using resistors to do level conversion from 5V to 3V3)

This is how the final application is connected together. Ensure the wiring follows this diagram.

My final system looks like this. Note that I had bricked the debugger in my case, so I have an Arduino Nano attached which serves as the programmer to the AVR-IoT.

Application Wiring & Block Diagram

I will make use of the Gwiot 7941E RFID module which is a 125kHz RFID Card Reader Module.

Connect the Gwiot 7941E's TXD to the AVR IoT's RX pin. Also connect VCC to 3V3 and GND to GND. (Note that although the module states that it needs 5V, it is fine to power it with 3V3 only. It also saves us the trouble of using resistors to do level conversion from 5V to 3V3)

This is how the final application is connected together. Ensure the wiring follows this diagram.

My final system looks like this. Note that I had bricked the debugger in my case, so I have an Arduino Nano attached which serves as the programmer to the AVR-IoT.

Application Software & Cloud Dashboard

I have attached my program code on Github.

The code will update the temperature & light details to Adafruit IO every 5 seconds. If a card has been tapped, the entry log will also reflect the changes.

These are the resources I used on how to use the Adafruit IO API

Upload the Arduino code to the board. If everything goes well, the board will start uploading the data periodically.

In Adafruit IO, open up Monitor and you can verify the messages that come in

The incoming data or any errors will reflect on this page

This is how the dashboard looks like.

The data updates in real-time and live monitoring can be done.

Demonstration of complete app

In this demo, I show the light sensor reacting to a torchlight, the temperature sensor shows that it is adjusting to the warmer environmental temperature, and the RFID card reader reads the ID of the card and creates an entry log. This is all updated live on Adafruit IO cloud dashboard.

Conclusion

In this project story, I have made a cloud IoT application for medical drug storage facilities. I have successfully connected the device to the Adafruit IO cloud service.

That's all for now, and I hope my project is detailed enough especially for beginners. Please let me know if you have any questions.

Schematics

Schematic & Block Diagram

Code

Blinky for AVR-IoT WG Board - Arduino

 

#define LED_RED            (PIN_PD0)
#define LED_YELLOW         (PIN_PD1)
#define LED_GREEN          (PIN_PD2)
#define LED_BLUE           (PIN_PD3)

void setup() {
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_YELLOW, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_BLUE, OUTPUT);
}

void loop() {
  digitalWrite(LED_RED, LOW);
  delay(100);
  digitalWrite(LED_YELLOW, LOW);
  delay(100);
  digitalWrite(LED_GREEN, LOW);
  delay(100);
  digitalWrite(LED_BLUE, LOW);
  delay(100);
  
  digitalWrite(LED_RED, HIGH);
  delay(100);
  digitalWrite(LED_YELLOW, HIGH);
  delay(100);
  digitalWrite(LED_GREEN, HIGH);
  delay(100);
  digitalWrite(LED_BLUE, HIGH);
  delay(100);
}

Application Code - zst123 / avr-iot-medical-storage-monitor

IoT Medical Storage Monitor with AVR-IoT and Adafruit IO — Read More

https://www.hackster.io/zst123/iot-medical-storage-monitor-with-avr-iot-and-adafruit-io-81c5e3

Latest commit to the master branch on 12-27-2020 - Download as zip

Credits

zst123

zst123

Hi I am new to the Hackster.io community. I am active in Hackaday.io for hardware projects and also on Github for my software projects

 

Hackster.io

This content is provided by our content partner Hackster.io, an Avnet developer community for learning, programming, and building hardware. Visit them online for more great content like this.

This article was originally published at Hackster.io. It was added to IoTplaybook or last modified on 03/01/2021.