Real-Time Motion & Tilt Monitoring With MPU6050, ESP8266 and KiwisIoT Dashboard
by Keerthana Dass in Circuits > Electronics
25 Views, 0 Favorites, 0 Comments
Real-Time Motion & Tilt Monitoring With MPU6050, ESP8266 and KiwisIoT Dashboard
In this project, we will build an IoT-based real-time motion, acceleration, and tilt monitoring system using an ESP8266 NodeMCU, MPU6050 sensor, and KiwisIoT platform.
The MPU6050 is a 6-axis motion sensor that contains an accelerometer and a gyroscope. It can measure acceleration and rotational movement along the X, Y, and Z axes.
The ESP8266 reads the sensor values and calculates the tilt of the sensor. It then connects to Wi-Fi and sends the collected data to the KiwisIoT platform.
The KiwisIoT dashboard displays the sensor information in real time using separate widgets for acceleration, gyroscope, and tilt values.
In this tutorial, we will start from the basics and go step by step, including software installation, ESP8266 setup, library installation, hardware connections, KiwisIoT dashboard configuration, programming, and testing.
By the end of this project, you will have a working system that can monitor the motion and orientation of the MPU6050 through a KiwisIoT dashboard.
Supplies
Hardware
- ESP8266 NodeMCU × 1
- MPU6050 Accelerometer & Gyroscope Module × 1
- Female-to-female jumper wires × 4
- Micro-USB cable × 1
- Computer/Laptop × 1
- Wi-Fi connection × 1
Software
- Arduino IDE
- ESP8266 Board Package
- Adafruit MPU6050 Library
- Adafruit Unified Sensor Library
- KiwisIoT Library
- KiwisIoT Account
Install Arduino IDE
Arduino IDE is the software we will use to program the ESP8266 NodeMCU.
If Arduino IDE is already installed on your computer, you can skip this step and continue to the next step.
Download and install Arduino IDE on your computer.
After installation, open Arduino IDE.
Connect the ESP8266 NodeMCU to your computer using a USB data cable.
Make sure the USB cable supports data transfer. A power-only cable will not allow Arduino IDE to communicate with the ESP8266.
Once the ESP8266 is connected, we can configure Arduino IDE to recognize the board.
Add ESP8266 Board Support
Arduino IDE does not include ESP8266 boards by default, so we first need to add ESP8266 support.
Open Arduino IDE and go to:
File → Preferences
Find the field called:
Additional Boards Manager URLs
Add the following URL:
Click OK.
Next, go to:
Tools → Board → Boards Manager
Search for:
ESP8266
Install:
esp8266 by ESP8266 Community
Wait until the installation is completed.
Select the ESP8266 Board and Port
After installing the ESP8266 board package, we need to select the correct board and COM port.
Go to:
Tools → Board → ESP8266 Boards
Select:
NodeMCU 1.0 (ESP-12E Module)
Next, go to:
Tools → Port
Select the COM port connected to your ESP8266.
The COM number may be different on every computer. For example:
COM7
Your port number may be different.
Once the board and port are selected, Arduino IDE is ready to communicate with the ESP8266.
Install the Required Libraries
Now we need to install the libraries required for the MPU6050, ESP8266, and KiwisIoT.
Open:
Sketch → Include Library → Manage Libraries
Search for the following libraries and install them.
Adafruit MPU6050
Search:
Adafruit MPU6050
Install the library by Adafruit.
Adafruit Unified Sensor
Search:
Adafruit Unified Sensor
Install the library by Adafruit.
KiwisIoT
Search:
KiwisIoT
Install the library by Mugeshwaran R
After installing the libraries, restart Arduino IDE if required.
The ESP8266 Wi-Fi library and Wire library are included with the ESP8266 environment and do not need to be installed separately for this project.
Connect the MPU6050 to the ESP8266
The MPU6050 communicates with the ESP8266 using the I²C communication protocol.
Only four connections are required for this project.
SDA is used for transferring data between the MPU6050 and ESP8266.
SCL provides the clock signal for I²C communication.
VCC supplies power to the sensor.
GND provides the common ground.
Double-check all four connections before powering the circuit.
Create the KiwisIoT Dashboard
Now that the hardware is connected, we need to prepare the KiwisIoT dashboard.
Log in to your KiwisIoT account and create a new dashboard/panel.
Give the dashboard a suitable name, such as:
Motion and Tilt Monitoring
After creating the dashboard, note down the Topic ID.
We will use this Topic ID in the Arduino program so that the ESP8266 knows where to send the sensor data.
Configure KiwisIoT Dashboard Widgets
We will use four channels to organize the sensor data.
Configure the dashboard as follows:
Channel 0 → Acceleration X, Y, Z
Channel 1 → Gyroscope X, Y, Z
Channel 2 → Tilt X
Channel 3 → Tilt Y
Add four widgets to the dashboard.
Use the following names:
ACCELERATION
GYROSCOPE
TILT_X
TILT_Y
Assign each widget to its corresponding channel.
Program the ESP8266
Now that the hardware is connected and the KiwisIoT dashboard is ready, we can program the ESP8266.
The program performs four main tasks:
- Reads acceleration data from the MPU6050.
- Reads gyroscope data from the MPU6050.
- Calculates the X and Y tilt angles.
- Sends the sensor data to the KiwisIoT dashboard through Wi-Fi.
Before uploading the program, replace the Wi-Fi name, Wi-Fi password, and KiwisIoT Topic ID with your own details.
Required Libraries
The program uses the following libraries:
Enter Your Wi-Fi Details
Replace the example values with your own Wi-Fi credentials:
For example:
Enter Your KiwisIoT Topic ID
Replace the Topic ID with the Topic ID of your KiwisIoT dashboard:
For example:
Complete Arduino Code
Upload the Program to ESP8266
Before uploading, make sure the ESP8266 board and COM port are selected correctly.
Click the Upload button in Arduino IDE.
Wait for the compilation and upload process to finish.
After the upload is complete, the ESP8266 will restart and begin reading data from the MPU6050.
Check the Sensor Readings
Open:
Tools → Serial Monitor
Set the baud rate to:
115200
The Serial Monitor should display the acceleration, gyroscope, and tilt values.
View Real-Time Data on KiwisIoT
Once the ESP8266 connects to Wi-Fi and starts sending data, the KiwisIoT dashboard will begin displaying the sensor readings.
The dashboard provides four different views:
- Acceleration X, Y, Z
- Gyroscope X, Y, Z
- Tilt X
- Tilt Y
Move or tilt the MPU6050 and observe the values changing on the dashboard.
Understanding the Tilt Calculation
The MPU6050 gives acceleration values along three axes: X, Y, and Z.
We can use these acceleration values to estimate how much the sensor is tilted.
In this project, we calculate two tilt values: Tilt X and Tilt Y.
Tilt X
The Tilt X angle is calculated using the Y-axis acceleration and the combined acceleration from the X and Z axes.
This converts the calculated angle from radians to degrees.
Tilt Y
The Tilt Y angle is calculated using the X-axis acceleration and the combined acceleration from the Y and Z axes.
The negative sign in the Tilt Y calculation determines the direction of the angle according to the sensor orientation used in this project.
As the MPU6050 is tilted, the acceleration values change. The ESP8266 uses these changing values to calculate the corresponding Tilt X and Tilt Y angles.
The calculated angles are then sent to the KiwisIoT dashboard, allowing us to monitor the sensor's orientation in real time.
Test the Motion and Tilt Monitoring System
Place the MPU6050 on a flat surface and observe the readings.
Then slowly tilt the sensor:
- Forward
- Backward
- Left
- Right
Observe how the Tilt X and Tilt Y values change.
You can also rotate the sensor and observe the gyroscope readings.
The acceleration and gyroscope values will change according to the movement and orientation of the sensor.
Final Result
The project is now complete.
The ESP8266 successfully reads data from the MPU6050 and sends it through Wi-Fi to the KiwisIoT platform.
The KiwisIoT dashboard provides real-time monitoring of:
Acceleration: X, Y, and Z
Gyroscope: X, Y, and Z
Tilt X: X-axis orientation
Tilt Y: Y-axis orientation
This provides a simple way to monitor motion and orientation using an IoT dashboard.
Applications
This type of motion and orientation monitoring can be used as a starting point for:
- Robotics
- Motion monitoring
- Tilt monitoring
- Vehicle orientation monitoring
- Equipment monitoring
- Gesture-based systems
- IoT sensor monitoring
- Educational IoT projects
Conclusion
In this project, we built an IoT-based real-time motion, acceleration, and tilt monitoring system using an ESP8266, MPU6050, and KiwisIoT.
We learned how to connect an MPU6050 to the ESP8266 using I²C communication, read accelerometer and gyroscope data, calculate tilt angles, and transmit the sensor information through Wi-Fi.
The KiwisIoT platform provides an easy way to visualize the sensor data through a real-time dashboard.
This project can also be extended by adding more sensors, charts, alerts, and automation features to create more advanced IoT applications.