I'm excited to share this Full-stack IoT Activity Tracker, this will transform raw sensor data into an actionable insights. The Accelerometer, Gyroscope, and the WiFi are all built in the RT-Thread RT-Spark development board, and this project integrates an embedded system, cloud computing, and mobile development into a seamless end-to-end architecture.
The system captures real-time accelerometer and gyroscope data, transmitting it via Wi-Fi into a PythonAnywhere backend. There, a custom-trained Machine Learning model (Scikit-learn) classifies user activities such as walking or running with negligible latency. Results are instantly synchronized with a dedicated Android application, providing users with a sleek, responsive interface for activity monitoring.
Embedded System DevelopmentI. Installation of RT-Thread Studio
A. System Requirements
Before installing the app, make sure that your computer meets the following system requirements:✅Operating System: Windows, Linux, or macOS
✅RAM: 4GB or higher recommended
✅Disk Space: Several GB of free space
✅Java Runtime Environment (JRE) installed (preferably version 8 or later)
Please be guided that in this procedure, we will be using a Windows 11 Operating System.
B. Download and Install RT-Thread Studio IDE1. Download the RT-Thread Studio IDE here: RT-Thread Studio
2. Click SDK Manager. Install the “STM32F407"(v1.2.0) and "Debugger_Support_Package packages. After the installation, close the SDK Manager.
3. Click on the “File” tab on the upper left portion of the RT-Thread Studio then click on the “New -> RT-Thread Project”.
4. Select “Base on Board”. On the board selection portion, select "STM32F407-RT-SPARK" with type set to "Template". Once done, click the finish button.
5. In the RT-Thread Settings, install the following packages:
- WebClient: A HTTP/HTTPS Client for RT-Thread (v2.2.0)
- rw007: SPI WIFI rw007 driver (v2.0.1)
- cJason: Ultralightweight JSON parser in ANSI C (vlatest)
- Enable sensor drivers and install icm20608: a 3-axis gyroscope and a 3-axis accelometer driver library (vlatest)
For the Onboard Peripheral devices, enable the following:
For the Components, enable the following:
For the Kernel, set the following value:
Once everything is done, save it and it will automatically generate files for your project. Build the project and Upload it to the board by clicking the download button at the top.
Now, you will see in the terminal that the Accelerometer and Gyroscope are now connected to WiFi:
II. Setup Cloud Server
In this project, I will be using PythonAnywhere as a server because it offers a free cloud hosting however, this server has only free tier which includes: 512MB storage, 1 web app, and 100k requests/day. 1. Create a PythonAnywhere account on this link: pythonanywhere.com
2. In the Dashboard, click Bash Console and type the following command to create a directory and activate virtual environment:
mkdir iot
cd iot
python3.13 -m venv venv
source venv/bin/activate
3. In the Web, click "Add a new web app" (I will be using flask v3.13), and then in the "Code" section, set the source code to the directory path that you created earlier.
4. Inside the "iot" directory, there will be a generated "flask_app.py, " change its entire code to the "flask_app.py" that I attached in the CODE section.
5. Next, go back to the RT-Thread Studio, Build your project and Upload it to the board by clicking the download button at the top. After that, click the monitor icon to open the terminal. Now, you will see that your sensor readings are sent to the pythonanywhere server. The data can be viewed in the "sensor_log.txt".
To achieve activity recognition, I will be using the dataset.csv from Kaggle: Run or Walk and utilizing Google Collab to create a lightweight design for this model, then use again the PythonAnywhere to integrate the machine learning framework (Scikit-learn).1. Download the dataset.csv from Kaggle Run or Walk
2. Create an account in Google Collab and click "New Notebook", then type the commands in the code section and run it.
3. Download the files and upload it to the "iot" directory in the PythonAnywhere.
4. In the "Code" section, change the source code into the following and also update its wsgi file. Now, in the browser type your web url and you will see the activity recognition dashboard in which the sensor readings of the board will be displayed. The data will be updated for every 2 seconds.
I. SQLite Database Setup
1. In the Bash Console, I just type the following command:
2. Paste the code to it and save. Then run this command: python3 database_setup_sqlite.py
3. Next, I just created a new file inside the "iot" directory and name it "flask_app_complete.py, " then paste the new code. In the Web section of PythonAnywhere, just edit the source code and set it to the following as well as its wsgi file, then reload the Web App.
4. Next, run the updated code for the STM32 in the RT-Thread Studio and refresh the dashboard, the following are the results:
To see the full results, here's the video link: Activity Recognition with Databa
Mobile App DevelopmentIn creating the mobile app, I will be utilizing Android Studio, Kotlin as the programming language, and Voley, an HTTP library developed by Google, in order to communicate with the cloud service.
I. Installation of Android Studio
1. Download Android Studio from this link: Android Studio
2. Install with default settings and launch it.
3. Create a new project, go to File → New → New Project and select Empty Activity and configure the following:
Name: Activity_Recognition
- Name: ActivityRecognitionApp
- Package name: com.example.activity_recognition
- Save location: Choose your folder
- Language: Kotlin
- Minimum SDK: API 24 (Android 7.0)
4. Once the project loads, the main interface appears. At the center is the Editor Window, where all code and layout files are edited. On the left side, click Project to open the Project Tool Window. Ensure the view is set to AndroidOnce the project loads, the main interface appears. At the center is the Editor Window, where all code and layout files are edited.
Here you will see:
- java / kotlin – contains the main logic files
- res – contains layouts, images, and resources
- AndroidManifest.xml – defines app permissions and components
5. In the Project window: Expand java, your package name, and click MainActivity.kt. At this stage, no changes are required. This confirms the activity is correctly created. Next, expand the res folder -> layout folder -> activity_main.xml.
At the top-right of the editor, switch between:
- Code for XML editing
- Design for visual UI
- Split to view both
6. To add a New Activity (Login Screen), go to the Project panel on the left. Expand kotlin + java, right-click your package name, and click New → Activity → Empty Views Activity. This will open the activity creation window. After that, configure the "Activity", then modify "AndroidManifest.xml, and design your app.
7. After designing, connect your Android phone to your laptop via USB, just go to the settings of your phone, click AboutPhone → Softwareinformation → Buildnumber (click it 7 times to enable Developer options). In the Developer Options, turn on the USB Debugging, then in the Android Studio, add your device to it.
8. Next, build the project and run it, and click the Download Information to save the app in your device.
9. Now, you will see what's inside the app, and navigate through its different functions.
To see the full results, watch the video through this link: Activity Recognition App
AI Assistants : Gemini and Claude AI






Comments