End-To-End Workout




Our project is called "End-To-End Workout" because we are enabling a full end-to-end experience when you want to workout. From enabling your workout session through Siri, and enabling sets counting of different workouts, to turn on the water tank and lights in your shower that will make your workout exprience much easy and comfortable!
End-to-end workout is a smart fitness tracking system that monitors workout using an accelerator (IMU sensor). By detecting direction changes in the y axis, it counts push-ups and sit-ups during a trainee's workout. We've integrated Blynk to display real-time workout progress and control various features remotely. The system also connects to a Control4 automation system, allowing users to activate devices such as water tanks and lights during their workout. Workout data is sent to a Telegram bot via an HTTP request, providing users with an automated summary of their progress.
In addition End-To-End Workout can record sets separetally, and summarize each set to the Telegram bot. For the set transition our system uses Siri voiceover so the trainee would keep concentrate on the workout.
For detailed explanation of the usage of End-To-End Workout please watch the following video that we created:
Further more we attached the full code and its dependencies for the End-To-End Workout but we recommend to go over every step in this tutorial and write the code as followed in the detailed steps.
Supplies



For the End-to-End Workout (circuit and the box that contains the circuit) we will need
- esp32
- speaker
- IMU sensor (accelerator)
- led strip
- blue led
- 4 AA baterries
- cutting board
- glue
- isolierband
- utility knife
- cardboard
- ruler
- two sided masking tape
- strap with buckles
Building the Circuit

First we'll start by building the esp32 circuit of the End-To-End Workout:
- connect the speaker to pin IO26
- connect the led strip to pin IO16
- connect the IMU sensor to: SCL (IO22), SDA (IO21)
- connect the blue led to pin IO15
- connect the 4 AA batteries to the esp32 power
Building the Strapped Wrapping Box







Note: you can skip this part if you have a suitable wrapping box for the esp32 circuit
In case you don't have any suitable wrapping box let's make one!
Take the cutting board, ruler, utility knife and cardboard.
First cut 2 rectangles from the cardboard, the measurements for those rectangles are 16 X 14 cm. In one of those rectangles cut a hole for the led strip diagonally, this will be the upper rectangle of the wrapping box.
Then cut another 2 rectangles from the cardboard, the measurements for those rectangles are 16 X 5 cm. In one of those rectangles cut a hole for the blue led, try cutting it near the edge of the rectangle so the trainee could see it.
Now cut another 2 rectangles from the cardboard, the measurements for those rectangles are 14 X 5 cm.
Next take the 16 X 14 cm rectangle without the hole for the led strip and place the esp32 circuit from step 1 on it, and using the isolierband stick the esp32 circuit to it.
Now take the other 16 X 14 cm rectangle and stick the led strip to the hole in it using the isolierband. In addition insert the blue led to the hole in the 16 X 5 cm rectangle.
Next glue every rectangle (except the other 16 X 14 cm rectangle) to the base 16 X 14 cm rectangle using the glue.
Now notice that before you glue the last 16 X 14 cm rectangle to the wrapping box make sure to turn on the esp32 and then glue it.
Next we need to connect the strap to the wrapping box. Put 2 pieces of two sided masking tape on the back of the wrapping box and stick the strap to it.
That's it, you just built the strapped wrapping box for the End-To-End Workout!
Connect the Esp32 to Wifi
In order to implemet all the features in End-To-End Workout you need to connect the esp32 to a wifi.
First add those modules
Next add those variables
Create the following function
Then you need to connect to the wifi so add this to your setup function
Integrating With Control4 System

Intro: Control4 is a sophisticated home automation system that integrates various household devices into one unified platform, providing users with enhanced control over their lighting, audio, video, climate, and security systems. Additionally, it supports voice commands through compatibility with popular voice assistants, and offers robust third-party integration, allowing for seamless operation with a wide range of smart home devices.
In case you don't have control4 system, that's fine, you can skip to step 2.
How to integrate?
Step 1:
Send a POST request to:
In the response, extract the "token" field.
Step 2:
Send a GET request to get all controllers registered to an account using the bearer token from Step 1:
Take the "controllerCommonName" field from the response, which should look like "control4_xxx_xxxxx".
Step 3:
Send a POST request to get the director bearer token for full application control, using the bearer token from Step 1 and the controller name from Step 2.
Extract the "authToken" from the response; this will be used for triggering actions in your smart home.
Step 4: Control4 IP
To get your Control4 IP, open the app, click on "Settings" → "More", and find the "IP Address" such as "xxx.xxx.xx.xx".
Step 5: Get Your Relevant Items
Because each house has different component names, retrieve item IDs by sending a GET request using the bearer token from Step 3:
Find your sun-heated water tank by its known name under the "name" field and retrieve its "id" for further actions.
Also, please find your Bathroom light name in the items and save it's id in the relevant place in the ino file.
First add those variables
Now add those functions
Creating Telegram Bot



In this step we'll create a Telegram bot for sending the workout summary to the user. We'll use BotFather, which is a bot created by Telegram to make bot creation easier. With BotFather, we can create our own bot by following a few simple steps:
Step 1: Open the Telegram app on your computer
To create a Telegram bot, you'll need to have the Telegram app installed on your computer. If you don't have it already, you can download it from the Telegram website.
Step 2: Connect to BotFather
To connect to BotFather, search for "@BotFather" in the Telegram app and click on the result to start a conversation.
Step 3: Select the New Bot option
In the conversation with BotFather, select the "New Bot" option to start creating your new bot. BotFather will guide you through the rest of the process.
Step 4: Add a bot name
Next, BotFather will ask you to provide a name for your bot. Choose a name that accurately reflects the purpose of your bot and is easy to remember, we chose "workout summarizer".
Step 5: Choose a username for your bot
Lastly, BotFather will ask you to choose a username for your bot. This username will be used to create a unique URL that people can use to access your bot. Choose a username that is easy to remember and related to your bot's purpose, we chose "workout_summarizer_bot".
And that's it! With these five simple steps, you can create your very own Telegram bot that you will use to send the workout summarize to the user.
Now you need to extract the token from the last message that BotFather has sent you (see attached image) so you can use it to send requests to the telegram API that will send messages to the user via the bot.
In Addition, in order to send messages to the user via the telegram bot we need to get the telegram chat id of the user.
Follow these steps in order to get the user's chat id:
- Search and open our new Telegram bot
- Click Start or send a message
- Open this URL in a browser https://api.telegram.org/bot{our_bot_token}/getUpdates
- We need to prefix our token with a word bot
- eg: https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates
- We will get a json like this:
- Check the value of result.0.message.chat.id, and the above json this is our chat id: 21xxxxx38
So now we have both the token of the bot and the chat id of the user.
Creating a Make.com Automation for the Telegram Bot






First you will need to create an account in make.com. Next we need to create a new scenario, in your make account go to the Scenarios section and create a new scenario.
Now we need to create a new Webhook, choose a name for the webhook, we chose "summarize workout".
Next you will receive an URL, we will use it to send the workout data from the esp32 to the telegram bot.
Now you need to add to the scenario the Telegram Bot app and configure it:
First we need to create a connection to the telegram bot using the token from step 2 (see attached photo).
Secondly we need to configure the chat id of the user using the chat id that we got from step 2 (see attached photo).
Lastly we need to create the workout summary message that the telegram bot will send to the user:
"Hello! I am your workout summarizer bot!
Here is your workout summary:
Set number: {{2.sets}}
Number of Push-Ups: {{2.pushUps}}
Number of Sit-Ups: {{2.sitUps}}"
This way the workout data that the esp32 will send to Make can be used in the summary message.
Now you need to connect the Webhook module to the Telegram Bot module, drag the plus button in the Webhook module and connect it to the Telegram Bot module (see attached photo).
Next you need to turn on the switch button "immediately as data arrives" (see attached photo).
Now you need to extract the Make.com url of the webhook, click on the webhook in your scenario and copy the address (see attached photo).
Next you can send your workout data to Make.com url (that you just copied) using a GET request with the parameters sets, pushUps and sitUps as seen in the code below.
First add those variables
Then add this function
Integrate With Shortcuts and Siri

.jpeg)
.jpeg)


In order to have the full experience, we recommend to create 4 new shortucts.
- Start Sit-ups
- Start Pushups
- Next Set
- Stop Workout
Each one can be controlled from siri and give you a feedback after the operation is finished.
Each operation is sent to blynk and updates the esp32 modes.
How to create a shortuct?
- In your Iphone, search for "Shortcuts" app
- Click on the + button in order to create your new shortcut
- Select "Add action"
- Search for "URL"
- Press the "URL" placeholder and paste the following URL: https://blynk.cloud/external/api/update?token={your_blynk_token}&V{insert_the_relevant_id_from_the_photo}={insert_the_relevant_id_from_the_photo}
- Congrats! you can start fitting up!
Integrate With Blynk




We want to control and display the workout progress to the trainee, that's when Blynk will be useful.
Open Blynk website and create an account. Now head over to the Developer Zone section and create a new template, then add to this template a new device. Next open the Datastreams and add 7 new datastreams:
- name: Start sit ups workout, pin: V0, data type: Integer, min value: 0, max value: 1, default value: 0
- name: Start push ups workout, pin: V1, data type: Integer, min value: 0, max value: 1, default value: 0
- name: Number of push ups, pin: V2, data type: Integer, min value: 0, max value: 100000, default value: 0
- name: Number of sit ups, pin: V3, data type: Integer, min value: 0, max value: 100000, default value: 0
- name: Set, pin: V4, data type: Integer, min value: 0, max value: 100000, default value: 0
- name: Reset, pin: V5, data type: Integer, min value: 0, max value: 1, default value: 0
- name: Start new set, pin: V6, data type: Integer, min value: 0, max value: 1, default value: 0
Now head over to the Web Dashboard section and add 4 Switch widgets to the dashboard, one for each switch datastream (Start sit ups workout, Start push ups workout, Reset and Start new set), configure each switch widget to its corresponding datastream and name them accordingly (see attached photo).
Next add 3 Number Input widgets to the dashboard, one for each number input datastream (Number of push ups, Number of sit ups and Set), configure each number input widget to its corresponding datastream and name them accordingly (see attached photo).
Download the Blynk app on your phone and follow the same steps in order to create the same workout dashboard in your phone.
Integrate Blynk in the End-to-End workout code:
First define
Add to your setup function this configuration.
note: both V5 (Reset workout) and V6 (Start new set) are hidden because the user controls them via speaking to Siri which is more convenient when working out, so there is no reason for them to be displayed in the Blynk dashboard.
Next add BLYNK_WRITE(V0) and BLYNK_WRITE(V1) functions in order to handle the values of the switch widgets of Start Sit-ups Workout and Start Push-ups Workout
Then add BLYNK_WRITE(V5) and BLYNK_WRITE(V6) functions in order to handle the values of the switch widgets of Reset Workout and Start New Set
the function BLYNK_WRITE(V6) controls of the set counting which is an integral part if this project
Finally, don't forget to add this to your loop function
Push-ups and Sit-ups Counting Using IMU

The main feature that is the core of the project is triggering the push-ups and sit-ups workout count.
We do it using an accelerator that checks if a push-ups or sit-ups set in the workout has happened.
In order to prevent spamming the blynk app, we added a check if we detcted a movment more than 3 times to be sure that it was actually moved. it helped us prevent wrong counting and be sure that the values are correct and works as expected.
How to intergate:
use the accelgyro library
Also you should define those variables to make sure the usage of the accelgyro will work.
Add this to your setup function
How we record push-ups:
How we record sit-ups:
From both of the function, you can see that we send the number of sit-ups/push-ups to the blynk application to show the relevant data to the user.
Pay attention, in order to record sit-ups and push-ups you should integrate with blynk, see next step.
Finally, add this to your loop function
Add a Signal Light

In this step we will add a signal light that indicates whether the workout started, this way the trainee knows when to start the workout.
We will need a led bulb, in our case we used a blue led (as shown in the photo).
Connect the led to the esp32 as written in the Step 1. Now all that left to do is to write the code that will use the led:
First define
Next you will need to add this to your setup function
Now you need to edit BLYNK_WRITE(V0) and BLYNK_WRITE(V1) functions in order to control the signal led respectively to the workout state
In addition you need to edit BLYNK_WRITE(V5) function in order to turn off the led as the Reset Workout switch was on
Add "Success" Lights and Sound

In this step we will add lights and sound to indicate a successful push-up or sit-up. We find it helpful for the trainee to be aware to his workout state without having to glance to the Blynk screen every sit-up or push-up.
We will need a led strip and a speaker, in our case we used a led strip with 13 leds (as shown in the photo).
Connect the led strip and the speaker to the esp32 as written in the Step 1. Now all that left to do is to write the code that will use the led strip and the speaker:
First include the pitches.h file (attached below) in order to play sounds in the speaker and Adafruit modules for the led strip
Next define
Next add this to your setup function
Now let's write the code for the success sequence (lights and sound):
Finally, you need to edit recordSitUps() and recordPushUps() in order to play the success sequence (lights and success melody) every successful push-up or sit-up
Downloads
Using End-To-End Workout
Now that all is done, and you are ready to go, you can select your desired workout:
- Push-ups
- Sit-ups
If Sit-ups has been chosen, put the strapped wrapping box on your belly.
If Push-ups has been chosen, put the strapped wrapping box on your back.
You can start each mode from blynk clicking on the relevant "start" buttons, or you can create the siri shortcuts and use them for hand free usage.
In order to know that the workout has been started, you can see the small blue led turning on, which signs that the workout can start.
In case you want to use the "Sets" feature, you can use it only through siri shortcuts, that's due to our understanding that the trainee won't want to stop the entire workout in order to start the next set, and it will be much easier to do so through siri, otherwise he can just start and stop the whole workout through the blynk app.
You will pay attention that after every success push-ups/sit-ups you will hear a voice and the strapped wrapping box will be shining for a friendly feedback about your success in your workout.
At the end, you can turn off the workout by pressing on the button again, or asking siri to "stop workout" and the blue led light will be turned off.
In addition, at the end of each set (or ending the entire workout) a summary of your workout will be sent to the telegram bot, giving you the full workout data.
Making your life easier, when ending the workout the water tank and bathroom light will be turned on using control4 system.
For more visual explanation, please watch the video attached in the explanation.
We wish you an amazing end-to-end workout, keep fitting up!