In this project a fitness tracker for dogs and a related website are introduced. During a walk the tracker is attached to the dog in a way that is possible according to the dog’s size (we used tape to fix the case of the tracker onto a dog’s coat). With the developed tracker it is possible to recognize the steps of a dog and to count them. From this information the walked distance can be calculated by multiplying the number of steps with an average step width. The mentioned data is then displayed in diagrams on a website for the user.
During an outside walk with the dog no Wi-Fi connection is necessary, the tracker supervises the steps by itself. It also tracks the data faster by just readying the data from the sensor and not having to report it to the website every time. After a fixed time of a few seconds the tracker is again and again shortly searching for a Wi-Fi connection before continuing to recognize steps. That makes it possible for the hardware to reconnect to Wi-Fi again and upload the data to the website when the user returns home from the walk.
To create this project, we took small steps and always made sure that everything worked as it should before we went on to implement the next step. In the following we describe what the steps were and what we did during these.
Step 1: Connect the board and the sensor (communication via I2C)
For this project we wired the NodeMCU Board and the gyroscope sensor as it is shown in the following picture.
We put everything on a breadboard and made sure that it fits together with the USB cable and the small power bank into our case.
For the settings for programming the NodeMCU Board using the Arduino IDE and for an example sketch we used the information from the website https://www.electronicwings.com/nodemcu/mpu6050-interfacing-with-nodemcu. In doing so we were able to see if the connection between the board and the sensor was working as the sensor data was displayed on the serial monitor of the Arduino IDE.
Step 2: Connect the board to Losant using Wi-Fi connection
In order to connect the board to Losant using a Wi-Fi connection we used different libraries. Which specific libraries are needed, how to setup Losant for the connection with the board and which code to use for this purpose is all laid out in detail on the website https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor. In the example on that website another sensor than the one in this project is used, but the sensor part can simply be replaced by the code for the gyroscope sensor from step 1.
Step 3: Finalizing the code
As we finished step 1 and step 2, we had a code consisting of a mixture between reading the data from the sensor and reporting it to Losant. In this step we finalized our code by bringing the different functions into the right order and changing a few things we wanted different for our project. During this we found out that just 30 messages in 15 seconds can be reported to Losant otherwise the connection will get lost. That is why we need about half a second to load up one set of data. For tracking the dog’s steps this is difficult because the steps of a dog are usually faster than half a second and therefore the steps happening while sending the old data to Losant won’t be recognized. That will lead to a wrong number of steps. As a solution we implemented that if the tracker does not have a Wi-Fi connection, which is the case during a walk, it can read the sensor data round about every 100 milliseconds.
An important part to implement was also the algorithm to recognize the steps of the dog. This uses the acceleration on the z-axis of the sensor as the dog moves a little bit up and down while walking. To make the evaluation of the steps more accurate, also the acceleration into the moving direction, which in this case was the acceleration in y-direction, was included. The numbers for the limits used in this algorithm were evaluated during tests. This step recognition is more a rough estimation and might not always be very accurate. The distance is, as mentioned above, calculated by multiplying the number of steps with an average step width, which is set in this project to 20 centimeters.
// Step detection reacts as the sensor moves in z- and y-direction (y-direction is the walking direction)
if (Az > 1 || Az < 0) {
if (Ay >= 0.80 || Ay < 0) {
stepCounter = stepCounter + 1;
distance = distance + 0.2;
}
}
Step 4: Creating a website
We found it necessary to show the number of steps and the walked distance not only on the serial monitor as it is not practical. Therefore, we created a website using the dashboard from Losant. For this we already built up a connection via Wi-Fi. A screenshot from the implemented website is shown in the picture below.
We think this project is a good start into IoT and has a lot of potential for further development. We already have a lot of fresh ideas for working on this fitness tracker for dogs. For example, the case and the hardware could be smaller to attach it better to the dog. Also, more functions for tracking additional fitness data of the dog may be implemented like the activity time of the dog, …
Thank you for reading!
Comments
Please log in or sign up to comment.