Configure Microcontroller Using Mpu6050 and Mcu ESP8266 (V 0.9)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

CONFIGURE

MICROCONTROLLER
USING MPU6050 AND MCU
ESP8266 (V 0.9)

Group Assignment 1
Internet of Things
Team 4

Team 4

Muhammad Mushlikh : 2402225944


Malvinsyah Arinata : 2402226032
Azura Sakan Taufik : 2402225931
Table of Contents
Table of Contents .................................................................................................................. 2
1. Preparation.................................................................................................................... 3
1.1. Hardware .........................................................................................................................3
1.2. Software ...........................................................................................................................3
2. Configuration ................................................................................................................ 4
2.1. Hardware Configuration ..................................................................................................4
2.2. Software Configuration ....................................................................................................6
3. Deploy & Test ................................................................................................................ 9
4. Notes & Summary ........................................................................................................ 10

2|I n t e r e t o f T h i n g s – M P U 6 0 5 0
1. Preparation
This step provides all the needed materials in the form of software and hardware.
1.1. Hardware
No Device Name Qty Description
1 MCU ESP8266 1 There are some version about this device, make sure we now
the exact version to decide the driver software that we need to
install and it decide the board type to be used.
2 Breadboard 1 Its an optional item, because we can replace it functionality
using jumper cable (female to female).
3 Data Cable 1 It has to be a data cable, not the charging only cable.
4 MPU6050 1 It’s an accelerometer, gyroscope, and thermometer sensor.
There are some type about this sensor device, we can choose
any type but we have to know the other tools we need for each
type.
5 Jumper Cables 4 It’s an optional item. There are 3 type of the jumper cable : male
to male, female to female, and male to female. On my case, I
use the male to male cable.

1.2. Software
No Device Name Description
1 Arduino IDE Main software that we need to make a
program/code to be uploaded into the
microcontroller
2 Adafruit Library A software library containing constructing
method that can be use to gather information from
the sensor device (MPU6050).
3 MCU Port Driver Driver that used to make the MCU port got
acknowledge by the operating system.

3|I n t e r e t o f T h i n g s – M P U 6 0 5 0
2. Configuration
This step provides a thorough step-by-step process of integrating the software and the hardware.
2.1. Hardware Configuration
a. Plug the MCU ESP8266 into the breadboard.

b. Plug the MPU6050 sensor into the breadboard.

c. Connect the pins using the jumper cable as follows:

4|I n t e r e t o f T h i n g s – M P U 6 0 5 0
MCU ESP 8266 MPU6050 Pins
Pins
D1 → SCL
D2 → SDA
3V3 → VCC
GND → GND

d. Connect the microsonctroller into the laptop using a data cable.

5|I n t e r e t o f T h i n g s – M P U 6 0 5 0
2.2. Software Configuration
a. Open Arduino IDE on computer
b. Create new sketch

c. Write the following code on the sketch we create earlier. These code MPU6050 library
by AdaFruit.

6|I n t e r e t o f T h i n g s – M P U 6 0 5 0
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

#define accelRange MPU6050_RANGE_8_G


#define gyroRange MPU6050_RANGE_500_DEG
#define bandwith MPU6050_BAND_21_HZ

Adafruit_MPU6050 mpuObj; //Instantiate class Adafruit_MPU6050 as mpuObj object

void setup(void) {
Serial.begin(9600); //Setup baudrate on 9600
// while (!Serial)
delay(3000); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("==============================================");
Serial.println("Start of initialization step");

// Try to initialize!
if (!mpuObj.begin()) { //Start mpuObj by running method begin, and check if it failed or succeed
Serial.println("Failed to find MPU6050 chip"); //Print information about the connecting process to MPU6050 device
is failed
}else{
Serial.println("MPU6050 Found!"); //Print information about the connecting process to MPU6050 device is succeed
}

mpuObj.setAccelerometerRange(accelRange); //Setup accelerometer range


Serial.print("Accelerometer range set to: ");
Serial.println(accelRange);

mpuObj.setGyroRange(gyroRange); //Setup gyrometer range


Serial.print("Gyro range set to: ");
Serial.println(gyroRange);

mpuObj.setFilterBandwidth(bandwith); //Setup bandwidh filter value


Serial.print("Filter bandwidth set to: ");
Serial.println(bandwith);

Serial.println("End initialization step");


Serial.println("==============================================");
}

7|I n t e r e t o f T h i n g s – M P U 6 0 5 0
void loop() {

/* Get new sensor events with the readings */


sensors_event_t accelerometerV, gyrometerV, temperatureV; //Define temporary variable that contain
information about sensor information value
mpuObj.getEvent(&accelerometerV, &gyrometerV, &temperatureV); //Get data from sensor and put it into
temporary variable that defined earlier

/* Print out the values */


Serial.print("Acceleration Value (m/s^2) : X= ");
Serial.print(accelerometerV.acceleration.x);
Serial.print(", Y= ");
Serial.print(accelerometerV.acceleration.y);
Serial.print(", Z= ");
Serial.println(accelerometerV.acceleration.z);

Serial.print("Rotation Value (rad/s) : X= ");


Serial.print(gyrometerV.gyro.x);
Serial.print(", Y= ");
Serial.print(gyrometerV.gyro.y);
Serial.print(", Z= ");
Serial.println(gyrometerV.gyro.z);

Serial.print("Temperature (in Celcius degree) : ");


Serial.println(temperatureV.temperature);

Serial.println("--------------------------------------------------------------");
delay(2000);
}

8|I n t e r e t o f T h i n g s – M P U 6 0 5 0
3. Deploy & Test
Now that both hardware & program code is ready. The next step is to upload the program code
into the microcontroller.
a. Open the Serial Monitor and choose the correct baudrate (9600)
b. Choose the correct board type and the port used to be identified by the computer.
c. Open the sketch that we created earlier.
d. Click Deploy button on the top left window.
e. Wait for the uploading process.
f. See the log on the serial monitor. The data gathered are:
• Rotation in x, y and z axes
• Acceleration in x, y and z aces
• Temperature

9|I n t e r e t o f T h i n g s – M P U 6 0 5 0
4. Notes & Summary
As the result that shown on the Image of step 3. It gave the information about the gyro value,
accelerometer value, and temperature value. The code use on this report is still a simple code, it
can be developed for more complex logic like sending it to API in cloud and save it into database.
Or we can also make the circuit to be more complex by add others sensor device.

10 | I n t e r e t o f T h i n g s – M P U 6 0 5 0

You might also like