ESP8266 & MPU6050 Tilt Angle Monitor on IoT Blynk
interface MPU6050 Gyro/Accelerometer Sensor with NodeMCU ESP8266 & measure tilt angle on OLED Display. Measured till angle is monitored on Blynk IoT Cloud
- Suitable forB.Tech/Diploma ESP8266/IoT students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
We will interface MPU6050 Gyro/Accelerometer Sensor with NodeMCU ESP8266 & measure tilt angle. The measured till angle is monitored on Blynk using IoT Cloud.
Overview
In this post we will learn how to
Measure Tilt Angle using MPU6050 & NodeMCU ESP8266
. This can be done by simply
interfacing MPU6050 6 axis Gyro/Accelerometer Sensor with ESP8266
. The Accelerometer sends X, Y, and Z acceleration forces. We need to convert the forces into X, Y, Z 3D angle to determine the
3D Orientation
of the sensor. The measured
tilt angle
is sent to the
Blynk Application
using the Blynk
cloud
. Hence the tilting position can be monitored over IoT.
The
gyroscope
measures rotational velocity or rate of change of the angular position over time, along the X, Y and Z-axis. It uses MEMS technology and the Coriolis Effect for measuring. The outputs of the gyroscope are in degrees per second, so in order to get the angular position, we just need to integrate the angular velocity.
You can refer to the previous post where we measured tilt angle using MPU6050 Gyro/Accelerometer & Arduino:
Measure Tilt Angle Using MPU6050
. Apart from this the MPU6050 can also be used to measure and
control speed of DC Motor
Components Required
Following are the components required for making this project. All the components can be easily purchased from Amazon. The component purchased link is added.
S.N.
Components
Quantity
Purchase Links
Nodemcu ESP8266 Board
Amazon
AliExpress
MPU6050
Amazon
AliExpress
OLED Display
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
MPU6050 Gyro/Accelerometer Sensor
Introduction:
The InvenSense MPU-6050 sensor contains a
MEMS accelerometer
and a MEMS gyro in a single chip. It is very accurate, as it contains 16-bits analog to
digital conversion
hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The sensor uses the I2C-bus to interface with the Arduino.
The MPU-6050 is not expensive, especially given the fact that it combines both an accelerometer and a gyro.
MPU6050 Pinout:
The MPU-6050 module has 8 pins:
INT:
Interrupt digital output pin.
AD0:
I2C Slave Address LSB pin. This is 0th bit in 7-bit slave address of device. If connected to VCC then it is read as logic one and slave address changes.
XCL:
Auxiliary Serial Clock pin. This pin is used to connect other I2C interface enabled sensors SCL pin to MPU-6050.
XDA:
Auxiliary Serial Data pin. This pin is used to connect other I2C interface enabled sensors SDA pin to MPU-6050.
SCL:
Serial Clock pin. Connect this pin to microcontrollers SCL pin.
SDA:
Serial Data pin. Connect this pin to microcontrollers SDA pin.
GND:
Ground pin. Connect this pin to ground connection.
VCC:
Power supply pin. Connect this pin to +5V DC supply.
3-Axis Gyroscope:
The MPU6050 consist of 3-axis Gyroscope with Micro Electro Mechanical System(MEMS) technology. It is used to detect rotational velocity along the X, Y, Z axes as shown in below figure.
3-Axis Accelerometer:
The MPU6050 consist 3-axis Accelerometer with Micro Electro Mechanical (MEMs) technology. It used to detect angle of tilt or inclination along the X, Y and Z axes as shown in below figure.
Circuit: ESP8266 & MPU6050 Tilt Angle Monitor on IoT Blynk
Here is the circuit diagram for
interfacing MPU6050 Gyro/Accelerometer
with
NodeMCU ESP8266
. The circuit can be assembled on breadboard.
Both the
MPU6050
&
OLED display
are
I2C Module
. So we need only 2 wires for interfacing them with NodeCMU. The SDA pins of both modules are connected to D2 of NodeMCU ESP8266 & SCL to D1. Supply
3.3V power
to both modules.
Setting Up Blynk IoT Application for Remote Weight Monitoring
Blynk
is an application that runs over Android and IOS devices to control any
IoT based application
using Smartphones. It allows you to create your Graphical user interface for IoT application. Here we will set up the
Blynk application
to monitor MPU6050 Angles over Wi-Fi using NodeMCU ESP8266.
So download and install the
Blynk Application
from Google Play store. IOS users can download from the App Store. Once the installation is completed, open the app & sign-up using your Email id and Password.
Now follow the photos below to set up the complete Blynk application.
So create gauge and value display. After the successful creation of the Project, go back to setting and click on Send Email. You will get an Authenticate ID on registered mail. Save the Authenticate ID. You will need to enter this on code.
Source Code/Program
The
source code/program
for
interfacing MPU6050 with ESP8266 on IoT cloud
is given below. We will need few libraries to compile the code. So download the
libraries
from the link below and add it to Arduino Library.
Adafruit_SSD1306 :
https://github.com/adafruit/Adafruit_SSD1306
Adafruit_GFX :
https://github.com/adafruit/Adafruit-GFX-Library
Blynk ESP8266 Library
Make sure to do the following changes in the code. Change the wifi SSDI & Password. And change the Blynk Authentication Token as well.
#include<Wire.h>
#include <SPI.h>
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing reset pin)
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
char
auth
[
]
=
"vB00BQor2wyZ927WnWe5JoBPgOi-fMQ7"
;
// You should get Auth Token in the Blynk App.
char
ssid
[
]
=
"Sri Krishna 3rd."
;
// Your WiFi credentials.
char
pass
[
]
=
"subbu@123"
;
const
int
MPU_addr
=
0x68
;
int16_t
AcX
AcY
AcZ
Tmp
GyX
GyY
GyZ
;
int
minVal
=
;
int
maxVal
=
;
double
;
double
y
;
double
z
;
void
setup
(
)
{
Wire
begin
(
)
;
Wire
beginTransmission
(
MPU_addr
)
;
Wire
write
(
0x6B
)
;
Wire
write
(
)
;
Wire
endTransmission
(
true
)
;
Serial
begin
(
9600
)
;
Blynk
begin
(
auth
ssid
pass
)
;
if
(
!
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
)
{
Serial
println
(
F
(
"SSD1306 allocation failed"
)
)
;
for
(
;
;
)
;
// Don't proceed, loop forever
}
display
display
(
)
;
delay
(
)
;
display
clearDisplay
(
)
;
display
clearDisplay
(
)
;
display
setTextColor
(
WHITE
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
(
"MPU Angles"
)
;
display
display
(
)
;
delay
(
3000
)
;
}
void
loop
(
)
{
Blynk
run
(
)
;
Wire
beginTransmission
(
MPU_addr
)
;
Wire
write
(
0x3B
)
;
Wire
endTransmission
(
false
)
;
Wire
requestFrom
(
MPU_addr
true
)
;
AcX
=
Wire
read
(
)
<<
Wire
read
(
)
;
AcY
=
Wire
read
(
)
<<
Wire
read
(
)
;
AcZ
=
Wire
read
(
)
<<
Wire
read
(
)
;
int
xAng
=
map
(
AcX
minVal
maxVal
)
;
int
yAng
=
map
(
AcY
minVal
maxVal
)
;
int
zAng
=
map
(
AcZ
minVal
maxVal
)
;
=
RAD_TO_DEG *
(
atan2
(
yAng
zAng
)
+
PI
)
;
y
=
RAD_TO_DEG *
(
atan2
(
xAng
zAng
)
+
PI
)
;
z
=
RAD_TO_DEG *
(
atan2
(
yAng
xAng
)
+
PI
)
;
Serial
(
"AngleX= "
)
;
Serial
println
(
)
;
Serial
(
"AngleY= "
)
;
Serial
println
(
y
)
;
Serial
(
"AngleZ= "
)
;
Serial
println
(
z
)
;
Serial
println
(
"-----------------------------------------"
)
;
display
clearDisplay
(
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
(
"X: "
)
;
display
println
(
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
(
"Y:
Overview
In this post we will learn how to
Measure Tilt Angle using MPU6050 & NodeMCU ESP8266
. This can be done by simply
interfacing MPU6050 6 axis Gyro/Accelerometer Sensor with ESP8266
. The Accelerometer sends X, Y, and Z acceleration forces. We need to convert the forces into X, Y, Z 3D angle to determine the
3D Orientation
of the sensor. The measured
tilt angle
is sent to the
Blynk Application
using the Blynk
cloud
. Hence the tilting position can be monitored over IoT.
The
gyroscope
measures rotational velocity or rate of change of the angular position over time, along the X, Y and Z-axis. It uses MEMS technology and the Coriolis Effect for measuring. The outputs of the gyroscope are in degrees per second, so in order to get the angular position, we just need to integrate the angular velocity.
You can refer to the previous post where we measured tilt angle using MPU6050 Gyro/Accelerometer & Arduino:
Measure Tilt Angle Using MPU6050
. Apart from this the MPU6050 can also be used to measure and
control speed of DC Motor
Components Required
Following are the components required for making this project. All the components can be easily purchased from Amazon. The component purchased link is added.
S.N.
Components
Quantity
Purchase Links
Nodemcu ESP8266 Board
Amazon
AliExpress
MPU6050
Amazon
AliExpress
OLED Display
Amazon
AliExpress
Connecting Wires
Amazon
AliExpress
Breadboard
Amazon
AliExpress
MPU6050 Gyro/Accelerometer Sensor
Introduction:
The InvenSense MPU-6050 sensor contains a
MEMS accelerometer
and a MEMS gyro in a single chip. It is very accurate, as it contains 16-bits analog to
digital conversion
hardware for each channel. Therefor it captures the x, y, and z channel at the same time. The sensor uses the I2C-bus to interface with the Arduino.
The MPU-6050 is not expensive, especially given the fact that it combines both an accelerometer and a gyro.
MPU6050 Pinout:
The MPU-6050 module has 8 pins:
INT:
Interrupt digital output pin.
AD0:
I2C Slave Address LSB pin. This is 0th bit in 7-bit slave address of device. If connected to VCC then it is read as logic one and slave address changes.
XCL:
Auxiliary Serial Clock pin. This pin is used to connect other I2C interface enabled sensors SCL pin to MPU-6050.
XDA:
Auxiliary Serial Data pin. This pin is used to connect other I2C interface enabled sensors SDA pin to MPU-6050.
SCL:
Serial Clock pin. Connect this pin to microcontrollers SCL pin.
SDA:
Serial Data pin. Connect this pin to microcontrollers SDA pin.
GND:
Ground pin. Connect this pin to ground connection.
VCC:
Power supply pin. Connect this pin to +5V DC supply.
3-Axis Gyroscope:
The MPU6050 consist of 3-axis Gyroscope with Micro Electro Mechanical System(MEMS) technology. It is used to detect rotational velocity along the X, Y, Z axes as shown in below figure.
3-Axis Accelerometer:
The MPU6050 consist 3-axis Accelerometer with Micro Electro Mechanical (MEMs) technology. It used to detect angle of tilt or inclination along the X, Y and Z axes as shown in below figure.
Circuit: ESP8266 & MPU6050 Tilt Angle Monitor on IoT Blynk
Here is the circuit diagram for
interfacing MPU6050 Gyro/Accelerometer
with
NodeMCU ESP8266
. The circuit can be assembled on breadboard.
Both the
MPU6050
&
OLED display
are
I2C Module
. So we need only 2 wires for interfacing them with NodeCMU. The SDA pins of both modules are connected to D2 of NodeMCU ESP8266 & SCL to D1. Supply
3.3V power
to both modules.
Setting Up Blynk IoT Application for Remote Weight Monitoring
Blynk
is an application that runs over Android and IOS devices to control any
IoT based application
using Smartphones. It allows you to create your Graphical user interface for IoT application. Here we will set up the
Blynk application
to monitor MPU6050 Angles over Wi-Fi using NodeMCU ESP8266.
So download and install the
Blynk Application
from Google Play store. IOS users can download from the App Store. Once the installation is completed, open the app & sign-up using your Email id and Password.
Now follow the photos below to set up the complete Blynk application.
So create gauge and value display. After the successful creation of the Project, go back to setting and click on Send Email. You will get an Authenticate ID on registered mail. Save the Authenticate ID. You will need to enter this on code.
Source Code/Program
The
source code/program
for
interfacing MPU6050 with ESP8266 on IoT cloud
is given below. We will need few libraries to compile the code. So download the
libraries
from the link below and add it to Arduino Library.
Adafruit_SSD1306 :
https://github.com/adafruit/Adafruit_SSD1306
Adafruit_GFX :
https://github.com/adafruit/Adafruit-GFX-Library
Blynk ESP8266 Library
Make sure to do the following changes in the code. Change the wifi SSDI & Password. And change the Blynk Authentication Token as well.
#include<Wire.h>
#include <SPI.h>
#define BLYNK_PRINT Serial
#include <Blynk.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing reset pin)
Adafruit_SSD1306
display
(
SCREEN_WIDTH
SCREEN_HEIGHT
&
Wire
OLED_RESET
)
;
char
auth
[
]
=
"vB00BQor2wyZ927WnWe5JoBPgOi-fMQ7"
;
// You should get Auth Token in the Blynk App.
char
ssid
[
]
=
"Sri Krishna 3rd."
;
// Your WiFi credentials.
char
pass
[
]
=
"subbu@123"
;
const
int
MPU_addr
=
0x68
;
int16_t
AcX
AcY
AcZ
Tmp
GyX
GyY
GyZ
;
int
minVal
=
;
int
maxVal
=
;
double
;
double
y
;
double
z
;
void
setup
(
)
{
Wire
begin
(
)
;
Wire
beginTransmission
(
MPU_addr
)
;
Wire
write
(
0x6B
)
;
Wire
write
(
)
;
Wire
endTransmission
(
true
)
;
Serial
begin
(
9600
)
;
Blynk
begin
(
auth
ssid
pass
)
;
if
(
!
display
begin
(
SSD1306_SWITCHCAPVCC
0x3C
)
)
{
Serial
println
(
F
(
"SSD1306 allocation failed"
)
)
;
for
(
;
;
)
;
// Don't proceed, loop forever
}
display
display
(
)
;
delay
(
)
;
display
clearDisplay
(
)
;
display
clearDisplay
(
)
;
display
setTextColor
(
WHITE
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
(
"MPU Angles"
)
;
display
display
(
)
;
delay
(
3000
)
;
}
void
loop
(
)
{
Blynk
run
(
)
;
Wire
beginTransmission
(
MPU_addr
)
;
Wire
write
(
0x3B
)
;
Wire
endTransmission
(
false
)
;
Wire
requestFrom
(
MPU_addr
true
)
;
AcX
=
Wire
read
(
)
<<
Wire
read
(
)
;
AcY
=
Wire
read
(
)
<<
Wire
read
(
)
;
AcZ
=
Wire
read
(
)
<<
Wire
read
(
)
;
int
xAng
=
map
(
AcX
minVal
maxVal
)
;
int
yAng
=
map
(
AcY
minVal
maxVal
)
;
int
zAng
=
map
(
AcZ
minVal
maxVal
)
;
=
RAD_TO_DEG *
(
atan2
(
yAng
zAng
)
+
PI
)
;
y
=
RAD_TO_DEG *
(
atan2
(
xAng
zAng
)
+
PI
)
;
z
=
RAD_TO_DEG *
(
atan2
(
yAng
xAng
)
+
PI
)
;
Serial
(
"AngleX= "
)
;
Serial
println
(
)
;
Serial
(
"AngleY= "
)
;
Serial
println
(
y
)
;
Serial
(
"AngleZ= "
)
;
Serial
println
(
z
)
;
Serial
println
(
"-----------------------------------------"
)
;
display
clearDisplay
(
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
(
"X: "
)
;
display
println
(
)
;
display
setTextSize
(
)
;
display
setCursor
(
)
;
display
(
"Y:
Technologies used
Hardware components
- ESP8266
- Arduino
- SSD1306
- OLED
- MPU6050
Software & tools
- Blynk
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.