design_document_mpu6050 Atmel cycle
design_document_mpu6050 Atmel cycle
1
Table of Contents
1. Introduction………………………………………………………………………….........3
1.1 Statement of Purpose………………………..……………………………...…..3
1.2 Objectives……………………………………….…………………………..…3
3. Calculations…………………………………………………………………………….....11
4. Tolerance Analysis……………………………………………………………………......13
8. Citations……………………………………………………………………………………20
9. Appendix……………………………………………………………………………………21
2
1. Introduction
Cyclists are often required to use their hands to indicate when they are about to make a
turn. This is often difficult and dangerous, especially when biking at nighttime. Several products
exist on the market for bicycle turn signals, however all of these products force the cyclist to
have to move their hands off of their handlebars to indicate a turn. The current products on the
market require the cyclist to have to use a control box located in between the handlebars. This is
dangerous for the cyclist to be looking at the controls as opposed to the road. The purpose of our
project is to create a wireless turn signal for bikers to use without needing to move their hands
off the handlebars.
1.2 Objectives:
Goals:
· Ability to make turns while keeping hands on the handlebars and eyes on the road
· Notify a driver behind when braking or slowing down
· Ability for turn signal to be visible to a driver behind during night times
Functions:
· Wirelessly controlled turn signal
· After the turn is completed, turn signal automatically turns off
· Brake signal using an accelerometer
· Cyclist is notified while the turn signal remains on
Benefits:
· Cyclist can keep his hands on the handlebar at all times
· Cyclist will avoid dangerous situations that might arise from making a turn on a road
· Ability to ride safely at night
Switch turns off automatically after turn is completed
Features:
· Easily mountable bicycle turn signal
· Easily readable LED screen that shows when the turn signal remains on for the
cyclist’s convenience
· Bluetooth compatibility with the turn signal and turn signal switches
3
2. Design
Overall system block diagram:
2.1.a Microcontroller
The microcontroller (ATMEGA328P-U) will collect all the inputs coming from the turn signal
switches and MPU6050 (gyroscope + accelerometer). Also, it outputs signals to the Transmitter,
that transmit data to the Turn/Brake signals located at the seatpost. The turn switches will be
connected to microcontrollers digital pins (pin 7 and 8) to get the input data. MPU6050 will use
the serial connection, I2C (SDA pin 27, SCL pin 28) to input the accelerometer and gyroscope
data and will use a digital pin 2 (pin 4) to trigger interrupts on the microcontroller. The
microcontroller will use UART to communicate with the Transmitter. It will use the serial Tx
(pin 3) connection of the microcontroller. The microcontroller will also control the sleep mode of
4
the Transmitter by controlling its PDN pin. It will put the transmitter into sleep mode when it is
not transmitting data. Also, the microcontroller will use a 16MHz crystal as its frequency-
determining component. The crystal will be grounded using 22pF capacitors as seen in the
Figure below. The microcontroller uses to single female pin connected to Rx (pin2) with the sole
purpose of loading program to the microcontroller. Additionally, it will have a reset switch (pin
1) to restart the program. The microcontroller will be powered from a 3.3V source that comes
from the Power Module.
At any time, the microcontroller will read the accelerometer data of the bicycle. Once it
determines that the bicycle decelerates above the threshold acceleration in -x-axis of the
accelerometer, then it will transmit signal to the Transmitter to turn on the Brake signal. Another,
function of the microcontroller is, once the biker presses the turn signal, it will output data to the
transmitter to turn the corresponding turn signal. Then, it will start to analyze the MPU6050’s
gyroscope data. It will measure the yaw, pitch and roll angles of the bicycle to determine the
turn. Once it detects that the turn is completed, it will send signal to the transmitter to turn off the
turn signal automatically.
5
The microcontroller, that is located at the seatpost will receive a serial data from the
Receiver. It will decode the data and feed it to the Turn/Brake signals located in the back end of
the bicycle using the pins 15, 16 and 17.
The InvenSense MPU-6050 chip will be used for this portion of the design. The chip
includes a total of 6 axis, 3 axis for gyroscope as well as 3 axis of accelerometer. It will
communicate with the microcontroller by a I2C serial connection (SDA, SCL). Also, it will send
an interrupt signal to microcontroller to indicate that there are data ready to be transferred from
the FIFO buffer register to the microcontroller. This module will analyze the bicycle motion to
determine whether the cyclist is applying brakes or making a turn.
The design will be powered by a 3.3V power from the Power Module. The electronic
design can be seen from the figures and table below.
6
Figure 5 - Detailed MPU6050 Circuit
This module will analyze the bicycle motion. It will detect when a turn is taking place
and when brakes are applied. The gyroscope feature of the MPU6050 chip will detect that cyclist
making a turn by the measurement of the yaw-pitch-roll angle change. As seen in the figure
below, the cyclist takes a turn between the 209 - 287 iterations of the turn. During the 90 Degree
turn, we can observe that the yaw angle of the bicycle also shifted 90 degrees in the positive
direction. Also, there was a temporary shift in the Pitch and Roll angles during the turn since
cyclist also tilted to the side of the turn and rotate the handle bar. Therefore, during a turn,
gyroscope reading shows the degree turn up to desired accuracy and it also provides shift in
angle in pitch and roll angles to separate an actual turn from a slight change in direction over
time.
7
We will also be reading the accelerometer of MPU6050 chip to detect cyclist braking. As
the cyclist decelerates higher than some threshold acceleration, which will be determined by
testing braking acceleration data under various trains and conditions like asphalt, dirt, flat
surface, downhill or uphill, the microcontroller will understand that the cyclist is braking.
2.3 Power:
The power supply supplies power to each component block and consists of a single
lithium ion battery (3.7 V, 2000 mAh nominal). We will attach this to an LP5912 linear regulator
in order to regulate the voltage at a constant 3.3V. We will require two of these power supplies,
one for the circuitry at the handlebars and one for the circuitry at the bumper. The size of the
overall design will be small since we are only using a single battery for each power supply. This
circuit should deliver around 7.4 Watts/hr which should be enough to power each chip in our
design:
(2000 mAh * 3.7V)/1000 = 7.4 Wh
The schematic for the linear regulator is shown below with pin outs, taken from the TI
datasheet for LP512:
8
Figure 7 - Power Plot for Vin from 3.8V to 4.4V and Output Voltage Ripple
2.4 RF Receiver:
This block represents the receiving end of our front-end/back- end communication link. It
consists of a single Linx RXM-315- LR chip, a simple power regulator for the chip, and a
receiving antenna. The purpose of the receiver module is to pick up on the signals sent by the
corresponding transmitter module mounted on the front-end device. It will then deliver the
digital data to the External Interface block to that the proper turn signal and/or brake signal can
be displayed. The communication link in this project consists of the receiver continuously
running and searching for signals at 315 MHz. As such, the PDN pin of the receiver will be
pulled up to Vcc.
9
Figure 8 - RF Receiver RXM-315- LR
2.5 RF Transmitter
This block represents the transmitting end of our front-end/back-end communication link.
It consists of a single Linx TXM-315-LR chip, a simple power regulator for the chip, and a
transmitting antenna. The purpose of the transmitter module is to receive the signals sent by the
microcontroller mounted on the front-end device and send them wirelessly to be picked up by the
receiving module on the back-end device. In the communication link implemented in this
project, the transmitter PDN pin will be connected to a digital output of the microcontroller. This
will allow the transmitter to be turned on and to send signals only when it is needed (as dictated
by the microcontroller), thus conserving power on the front-end device.
10
(Fix it)
11
Figure 10 - Turn/Brake Signals with LED Design
The PCB will be mounted by attaching a universal-size clamp onto the bicycle seat post. Then an
extender rod will be attached to the clamp so that the PCB can be situated behind the bicycle
seat. See Figure 9 for a rough idea of this mechanical mounting scheme.
12
2.7 Right/Left Turn Signal Switches:
This will be located on the handlebar of the bicycle. It will be located at a reachable
distance from the cyclist's hands. The switches will send input to the microcontroller about the
state of the switches.
2.8 SD Card:
This module will be required for debugging purposes. It will be useful in recording the
data we read from the MPU6050 chip to analyze the data further. The SPI method for writing
data will be implemented. The circuit diagram of the module can be seen from Figure 3.
13
3. Calculations
The MPU6050 will be powered by 3.3V source from the Power Module. It requires a
range of 2.375 - 3.46 V to operate. In order to operate Accelerometer + Gyroscope of the
MPU6050 chip, it requires a current of about 3.8A.
Power Required = 3.8 mA x 3.3V = 12.54mW
The values used in the following calculations were gathered from the RXM-315-LR datasheet.
The values used in the following calculations were gathered from the TXM-315-LR datasheet.
14
Since the design of the program is not finalized, the minimum parameters are given below.
Program Size: 14,848 bytes/32,256 bytes
Global Variables: 578 bytes of dynamic memory
Local Variable: 1470 bytes
According to the LED data sheets, the maximum power dissipation for the red LED is 130 mW
and the maximum power dissipation for the yellow LED is 85 mW. Furthermore, from the
BSS101 MOSFET datasheet, we gather that the maximum power dissipation is 0.60 W. With
these figures in hand, we can calculate the worst case power consumption for the external
interface as follows:
= 3.92 𝑊
Since we will be driving the LEDs with 20 mA of current, we can calculate their typical power
consumption by multiplying the typical drive current with the 3.6 V operating voltage.
Furthermore, we gather the typical power consumption for the MOSFETs from the datasheets as
0.45 W. Thus, we calculate the typical power consumption as follows:
15
4. Tolerance Analysis
Critical Component: Turn Signal Completion Detection
Acceptable Tolerance:
We have determined that the most critical portion of our turn signal is that it can detect
that a turn has been completed and that the signal is turned off automatically. An acceptable
tolerance would be detection of a turn angle at 90 degrees (turning onto a street). The angle of
the bicycle frame (the Yaw) should experience a turn of 90 degrees with a 10% tolerance.
Furthermore, the tilt angle should be 15 degrees with 10% tolerance. Finally, the handlebar turn
angle should be 45 degrees with tolerance 10%. This tolerance level makes it unable to
determine when the cyclist is changing lanes. It will only determine if the cyclist is making a full
right or left turn.
Test Procedure:
We will test the bicycle on the road at a four-way intersection. Using an Arduino attached
to an MPU-6050 chip sitting in the middle of the bicycle’s handlebars, we tested the handlebar
angle of turn, the tilt of the bike from side to side, and finally the turn angle of the entire
bicycle’s frame. From our data, we determined that the most effective way to determine if a
bicycle has completed a turn is from the entire bicycle’s frame angle of turn. This can be seen in
the third graph titled “90 degree turn.”
Presentation of Results:
We present our results in three graphs of data that show the angle of the bicycle’s tilt,
handlebars, and frame respectively over time. It can be seen that the turn angle for tilt is around
17 degrees (Figure 10) which falls within our tolerance. The yaw angle is 89 degrees which falls
within our tolerance (Figure 11). The handlebar turn angle is 42 degrees which also falls within
our range of acceptance (Figure 12).
16
Figure 11 - Gyroscope reading for rotating handle bar of bicycle
17
5. Requirements and Verifications
Microcontroller 1. The microcontroller has 1a. Send a 16-bit message from the
UART functionality for front microcontroller to the
transmitting 16-bit serial bits transmitter
using a 9600 baud rate to the 1b. Use an oscilloscope to read the
transmitter when turn, left or message that is being send to the
right signal needs to be on. DATA pin of the transmitter.
2. Timer interrupts should be 1c. See if the serial data being send
provided every 0.5s for the turn and the serial data that can be read
signals. matches.
3. The software can read the 2a. Set a Timer interrupt every 0.5
data from the MPU6050 seconds.
and switches and provide 2b. At every interrupt, toggle the
correct feedback to the back end value of the signal.
microcontroller through Tx/Rx 2c. Continuously send this message
module. through one of the microcontroller
pin.
2d. Use an oscilloscope to check to
see a square wave with a period of
1s.
3a. Confirm that once, either the left
turn or right turn switches is pressed,
corresponding turn lights toggles.
3b. Once the cyclist applies a brake,
the brake light flashes and stop
flashing once the braking stops.
3c. Once the cyclist completes a turn
greater than 60 Degrees, the
corresponding turn signal stops
signalling automatically with 90%
efficiency.
18
Receiver and 1. The communication link 1a. Program the microcontroller to
transmitter can transmit and receive send each 3-bit word a total of 5
signals of three bits over times (total of 40 sent signals) to the
the minimum length of transmitter.
the bike necessary (34 1b. Verify that the receiver, which
inches) will be at least 34 inches away,
2. The PDN (power down) correctly picks up on at least 35 of
pin of the transmitter the transmitted signals by
operates as intended connecting an oscilloscope to the
output data pin of the receiver.
2a. Program the microcontroller to
send (10) 3-bit signals to the
transmitter WHILE the PDN pin is
pulled high. Verify the transmitter
sends out these signals by
connecting a scope to the ANT pin
of the transmitter.
2b. Program the microcontroller to
send (10) 3-bit signals to the
transmitter WHILE the PDN pin is
pulled low. Verify the transmitter
does not send out any signals by
connecting a scope to the ANT pin
of the transmitter.
Gyroscope 1. Gyroscope can detect 1a. Bring the gyroscope value of the
yaw, pitch and roll angle at test to ~0 Degrees.
angles with a maximum 1b. Use a gauge to specify turn
bias error of 3% (~10.8 angles every 10 Degrees for a 360
Degrees) turn.
2. Gyroscope should be 1c. Slowly rotate the gyroscope to
able to detect a check whether desired rotation
minimum of 180 angles matches the desired angle
Degrees of turn per markings.
second with a maximum
19
of 10 Degree/second 2a. Bring the gyroscope so that the
error. angle at test reads a value of 0
Degrees.
2b. Shift the gyroscope continuously
on the ground every 1 second at a
180 Degree angle.
2c. Read the value from the
gyroscope and check whether it can
accurately match the desired 180
degrees.
User Interface 1. The left and right 1a. Connect microcontroller to two
switches on the testing LEDs.
handlebars interface 1b. In the microcontroller, match the
with the microcontroller input from the switches to the output
successfully with no that goes to the LEDs.
debouncing 1c. Test whether switches functions
properly by comparing with the
LEDs.
1d. Also, count the number of times
button is pressed and compare the
results to make sure there is no
debounce error.
External Interface 1. Each of the three LED 1a. Program the back
blocks turns on/off when microcontroller to send a square
dictated by the back end wave with period of 1 second and
microcontroller. duration of 10 seconds. to each of
the three MOSFETs. Verify that all
LEDs turn on and off
correspondingly. Repeat 3 times.
Point Distribution:
Microcontroller -This module should successfully gather inputs from the 10 points
switches and MPU6050 chip.
20
-It should successfully analyze the data to determine the state
of the bicycle (making a turn, finished the turn, braking)
-It should be in communication with the Transmitter to control
the turn signals.
Microcontroller This module should successfully read and decode the serial 5 points
(Decoder) data from the receiver and control the blinking conditions of
the Turn/Brake signals accordingly.
Transmitter This module should successfully do a serial data transfer from 7.5 points
microcontroller to receiver
Receiver This module should successfully receive a serial data transfer 7.5 points
to microcontroller to receiver
MPU6050 This module should successfully read the yaw, pitch, roll 5 points
angles and the acceleration of the bicycle in the x, y and z axis.
Power to Front This module should successfully supply steady state power to 5 points
to the front-end circuit.
Power to Back This module should successfully supply steady state power to 5 points
the back-end circuit
External Interface This module should successfully display the turn/brake signals 5 points
(LEDs) that is easily visible to the surrounding
Total 50 points
21
6. Parts & Schedule
6.1 Parts:
Total $47.69
22
6.2 Schedule:
23
12/4 Final Proposal Natalya Bapst
Final Proposal Hanna Zayed
Final Proposal Bora Cukurova
24
7. Ethics & Safety
Since our project is based on increasing the safety of the consumer, it is necessary that
our project design will neither damage the components of the bicycle nor harm the user in
anyway. This follows the first code of the IEEE Code of Ethics:
“To accept responsibility in making decisions consistent with the safety, health, and
welfare of the public, and to disclose promptly factors that might endanger the public or
the environment” [4]
Throughout the design portion of our project, we will learn a great deal about wireless
communications and power systems to ensure that our design operates safely and correctly. This
will give our team competence in designing the circuitry and handling volatile components such
as the Lithium Ion batteries used in our project. This follows the fifth and sixth codes of the
IEEE Code of Ethics:
“To improve the understanding of technology; its appropriate application, and potential
consequences; To maintain and improve our technical competence and to undertake
technological tasks for others only if qualified by training or experience, or after full
disclosure of pertinent limitations” [4]
Finally, our competence in understanding the limitations of our power system and the
circuitry that it must power is necessary, especially with the handling of Lithium Ion batteries.
Knowledge of the tolerance levels of voltage and power are necessary for each component, from
LEDs to microcontrollers and beyond. Through this, we follow the ninth code:
Finally, we will credit any help received on this project and acknowledge and correct any
errors throughout the course of our design such that the seventh code of the IEEE Code of Ethics
is followed:
“To seek, accept, and offer honest criticism of technical work, to acknowledge and
correct errors, and to credit properly the contributions of others” [4]
25
8. Citations
[1] Arduino, "Arduino playground - MPU-6050," 2016. [Online]. Available:
http://playground.arduino.cc/Main/MPU-6050. Accessed: Sep. 21, 2016.
26
9. Appendix
Pseudo Code:
Global Variables:
left_turn_signal //left turn signal state
right_turn_signal //right turn signal state
turn_state_indicator //HIGH when turn signal is activated and turn is about to happen
turn_state //Indicates wheterh turn started, being made or
completed
MPU6050 control variables
MPU6050 rotation variables (x,y,z,yaw,pitch,roll)
Interrupt setups:
MPU6050 interrupt pin
Timer1
turn_detection()
{
To be continued...
}
int MPU6050_data()
{
Wait for MPU6050 interrupt is available
Reset MPU6050 interrupt flag
Check MPU6050 FIFO register overflow
Else read all available data from FIFO register
Calculate raw data for x,y,z,yaw,pitch,roll
write raw data to SD Card
}
void setup()
{
Initialize MPU6050
Initialize Transmitter
Initialize Timer1 ~ 1 second intervals
Initialize SD_card
}
void loop()
{
run MPU6050_data() function
else
27
set brake signal low
if turn_state_indicator is HIGH
Run turn_detection()
28