Monitoring of patients or aged people is an hot topic in medical industry. Doctors, therapist, councillors even family members also want to know what all activities are doing by patients or aged people. Here I'm going to make a prototype of such a system. It will be useful for remote monitoring.
The main sensor is MPU6050 Accelerometer and Gyroscope. It's a low power, inexpensive 6-axis MotionTracking chip that combines a 3-axis gyroscope, 3-axis accelerometer, and a Digital Motion Processor (DMP) in a small package. It can measure angular momentum or rotation along all the three-axis, the static acceleration due to gravity, motion, shock, or vibration. Read More
Here we are using AVR IoT WG board. The AVR-IoT WG development board combines a powerful ATmega4808 AVR® MCU, an ATECC608A CryptoAuthentication™ secure element IC and the fully certified ATWINC1510 Wi-Fi® network controller - which provides the most simple and effective way to connect your embedded application to Google Cloud IoT core platform. The board also includes an on-board debugger and requires no external hardware to program and debug the MCU. Read More
Initially, we need to set up the Arduino IDE for coding. Adding ATmega4808 board, Some libraries will make easy development using Arduino IDE itself.
Adding MegaCoreXRefer here for MegaCoreX source files: https://github.com/MCUdude/MegaCoreX
Next, Let's perform our ~Hello World~ Blink using AVR IoT WG
Blink using AVR IoT WGvoid setup() {
pinMode(PIN_PD0, OUTPUT); //Red
pinMode(PIN_PD1, OUTPUT); //Yellow
pinMode(PIN_PD2, OUTPUT); //Green
pinMode(PIN_PD3, OUTPUT); //Blue
}
void loop() {
digitalWrite(PIN_PD0, LOW);
delay(500);
digitalWrite(PIN_PD1, LOW);
delay(500);
digitalWrite(PIN_PD2, LOW);
delay(500);
digitalWrite(PIN_PD3, LOW);
delay(500);
digitalWrite(PIN_PD0, HIGH);
delay(100);
digitalWrite(PIN_PD1, HIGH);
delay(100);
digitalWrite(PIN_PD2, HIGH);
delay(100);
digitalWrite(PIN_PD3, HIGH);
delay(100);
}
Make sure these settings are done correctly before uploading code.
Awesome... It's working
Next, We need to check our ATWINC1510 wifi module. To check ATWINC1510 install WiFi 101 Library : https://www.arduino.cc/en/Reference/WiFi101
Then add this code snippet below void setup()
WiFi.setPins(
PIN_PA7, // CS
PIN_PF2, // IRQ
PIN_PA1, // RST
PIN_PF3 // EN
);
Then upload WiFiClient Example code.
Note: Replace all Serial to Serial2 to get Serial monitor response.
Awesome. We did all the initial setup.
Interfacing MPU6050Next, we need to interface MPU6050 with AVR IoT WG board. To check MPU6050, Upload this code.
Pin Connection:
AVR IoT WG - MPU6050
3V3. : >> VCC
GND : >> GND
SCL : >> SCL
SDA : >> SDA
#include <Wire.h>
const int MPU6050_addr=0x68;
int16_t AccX,AccY,AccZ;
void setup() {
Serial2.begin(9600);
Serial2.println("Initialize MPU6050");
Wire.begin();
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial2.println("Initialized !!! ");
}
void loop() {
Wire.beginTransmission(MPU6050_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU6050_addr,14,true);
AccX=Wire.read()<<8|Wire.read();
AccY=Wire.read()<<8|Wire.read();
AccZ=Wire.read()<<8|Wire.read();
Serial2.print(" Xraw = "); Serial2.print(AccX);
Serial2.print(" Yraw = "); Serial2.print(AccY);
Serial2.print(" Zraw = "); Serial2.println(AccZ);
}
Output
Perfect MPU6050 is working. cool
Google Firebase SetupNext, we need to push these values into any database for processing and monitoring. Here I'm using google firebase to store my values. Head on to https://console.firebase.google.com/ and log in your account.
Create a project with an appropriate name. Then set-up a Real-time database and store the credentials and database URL
Firebase setup :
Done. We did our database set-up. Next, download the Firebase Arduino library for sending values into the database.
Thankyou for this awesome library : https://github.com/mobizt/Firebase-Arduino-WiFi101
Accelerometer Values into FirebaseHere we need take continues value of MPU6050 for a short period of 3-5 Seconds. Also, Need to push these values into the database. To complete the push operation, taking a short delay. So, we are missing many values of Accelerometer. To avoid this. We are creating a Queue and initially storing values into a Queue for a short time. Later, sending these values into the cloud by the FIFO principle. Thankyou Jacob Sorber for this video.
Here we are making JSON and pushing this JSON to firebase using pushJSON() function.
We are using a countor variable to count the number of values in the queue. To avoid the overflow of values we are limiting queue size by using a count variable.
Perfect. Finally, we have completed our data storing part.
Prediction and outputNext, We need to write some python script to Access data from database.
For that I'm using Firebase-Python module
Create a virtual environment in python install below modules
pip install requests
pip install python-firebase
Then, Access data using python
While pushing json we are using a counter variable to understand each series of data. first 0-200 Data will be in 1st 4 seconds. Then next Series of 0-200 will be the data after pushJSON() function. Taking each series of data separately with an event ID or Timestamp is required to predict activities.
from firebase import firebase
firebase.FirebaseApplication("https://YOURURL", None)
We have completed all our data managing part. Next, we need to make the ML model which will predict values from Accelerometer data. There is a lot of datasets available to predict human activities using Accelerometer Data. Thanks to this awesome author for this blog
We need to make a proper ML model for better prediction. But it was really hard to get a dataset which matches values of MPU6050. So, my model is not working perfectly. Need to make my own dataset or required more research on that.
After making an ML model, need to shape our data and feed into the model, then the output will be stored in another database with a timestamp. This will be accessed through another web app written in the flask. An authenticated person can able to view all the data from there.
Here is my Github repo for this project. Further, Development will be available here.
ChallengesSome of the challenges I faced while developing was. Initially, I was planned to implement Free RTOS and running data reading and pushing as different task simultaneously, But I couldn't do that because of a shortage of memory. Board not working sometimes due to queue overflow. Another one is, not able to get a proper dataset for making the ML model. The available dataset is taking values from different smart mobiles. It's a different value by comparing MPU6050. Maybe it can make through setting some offset values and proper coding.
Comments