Real-Time Acceleration Control Using Bluetooth Mobile App
1. Real-Time Acceleration Control using
Bluetooth Mobile App
Using Arduino mega 2560, stepper motors and sensors
Venkatesh Prasad
UIN: 124003455
Electrical and Computer Engineering Department
venkateshprasad13@gmail.com
Divya Anbalagan
UIN: 224003354
Electrical and Computer Engineering Department
divyaanbalagan7@gmail.com
Lance Alpuerto
UIN: 423004329
Electrical and Computer Engineering Department
Lanceg90@tamu.edu
Abstract — This document illustrates the real-time control of a stepper-motor driven robot, which is fed acceleration input from a
Bluetooth device (a mobile phone). The action of RT controlleris usedto generate error signals from the actual acceleration – data that
is collectedusing an accelerometer. The ultrasonicsensoris usedfordistance measurement andobstacle detection, which causes the robot
to eitherspeedup (absence of obstacle) or slowdown (presence of obstacle).
Keywords—Acceleration control, Ultrasonic sensors, Accelerometer, Real time controller for stepper motor system, Sensors&Actuators,
Bluetooth modules.
2. 2 | P a g e
I. OBJECTIVE AND SIGNIFICANCE
The purpose of this project is to have a deeper understanding of the fundamentals of control systems and the
entire plant that it controls. The automated acceleration control system will allow remote setting of distance
and speed to determine positive and negative acceleration characteristics needed, given no load description.
The two sensors used – ultrasonic and accelerometer – provide critical data about the position and velocity of
the robot, and any objects obstructing its path. In the control system, the proportional and integral gains are set
upon modeling the plant. These values are continuously updated within the real-time control loop based on the
error of the readings. The device will be able to recognize and adjust to any slippage of the wheels at any point
and adjust the torque produced by the motor for steady movement. Finally, the BT application allows the user
to provide the acceleration (distance??) set-point. The robot is then intelligent enough to perform obstacle-
detection to make sure collisions are avoided.
The significance of the project lies in the realization of a complete closed-loop design of a system using sensors,
actuators, digital logic and microcontroller. By doing a real-time acceleration control, safe speeds and minimum
braking distances for moving objects such as cars can be ascertained. In the field of autonomous vehicles,
control through BT is an added feature.
II. ENGINEERING DRAWINGS FOR FINAL DESIGN
A. Robot Modeling and 3D Fabrication
One of the new technologies implemented in our project was the use of 3-D printing to create the robot body.
Instead of procuring the parts as commercial-off-the-shelf, it was built from scratch using Sketchup and
converting it to a .STL file. It was then printed overnight (~9 hours), the material used was ABS.
Prior to building the bot body, calculations were done depending on the parts needed. Space requirements were
estimated to mount the required devices. The main considerations were made with respect to the following:
1. Stepper motor + Motor Drivers
2. 3 Nos. of 9V Batteries
3. Space for BT module, accelerometer, ultrasonic sensor and the Arduino microcontroller
Figure 1 Stepper Motor 42M100B2U Figure 2 9Vx3 Batteries
3. 3 | P a g e
Once the required dimensions were ascertained, the 3D model was built on Sketchup. Shown below are the
lateral and top views of the 3D model. As can be observed, holes were included next to the motor to ensure it
can screwed on to the bot body.
Figure 3 3D View Figure 4 Top View
B. Controller Diagram
Set values
(Ad, Sd, Df)
Run
Calculations
Begin?
Accelerate
a(t) at t=0
Initialize timers
(place A, S, & D
eqs.)
Monitor G(t)
(ΔOCR, a(t), v(t))
Calculate Safe Distance in
Loop
Is
distance>safe_dist
ance?
Accelerate
++a(t)
Decelerate
- -a(t)
CONTINU
E
START
Yes No
4. 4 | P a g e
III. INTEGRATION OF ALL COMPONENTS
A. Stepper Motor + Motor Driver
Stepper motors are used instead of DC motors as they provide a better control of motion. 42M100B2U is the
motor used, and in order to drive this motor, the L298 dual full-bridge driver is used.
B. Battery Sizing
Once the mechanical part of the design was done, batteries were selected depending on the current drawn,
motor voltage rating and size. Since the motors are rated at 12V, a battery with voltage greater than that was
selected. Also, the current drawn by the motors are approx. 100-200mA. One of the issues we faced was the
amount of power consumed by the motors. The Ah ratings of the batteries sufficed even though we did not use
the larger 12V batteries. The smaller batteries were selected as they are a reduced payload that do not occupy
too much space.
Battery Specs: 03 x 9V, 4700mAh, Alkaline
C. Ultransonic Ranging Sensor
The HC - SR04 is used for object detection and distance measurement. The specifications of the sensor outlined
its principle of working. Using two pins, the Trigger and pulse width of Echo, distance calculations are done.
This was preferred over IR sensors as they can detect better in substandard lighting conditions.
D. Digital Accelerometer
The accelerometer is used to provide the real-time actual rate at which the robot is accelerating. Using this data,
and the data that is input from the BT module, the controller calculates the error. The accelerometer we had
initially selected was an analog device, however, the resolution was not small enough to capture the small
changes in acceleration.
Accelerometer Specs: LSM303DLH 3-axis accelerometer and 3-axis magnetometer
E. Bluetooth Module
The BT module connects to the Arduino via Serial1 (TX1 RX1). It is enabled to take commands from the
mobile application, which feeds it with the acceleration values. For this project, additionally, the BT module
was used to read serial data (accelerometer, distance, acceleration readings) onto the phone and stored as BT
logs. The code written to interface the BT module with any mobile device is attached in Appendix B.
IV. PROCEDURE
Highlighted below is the general step-by-step approach to building the project. Further explanation is given in
Appendix B which contains the final code implemented.
Step 1: Designing the mechanical structure
As described above, the robot was built by 3D printing and all the components were mounted on it.
5. 5 | P a g e
Step 2: Testing all the components
This process was time consuming as each component had to be tested and calibrated before it could be
integrated using the Arduino. The following are described in brief:
a) BT
The BT module transmits and receives data from the Arduino. This is then controlled by an app.
Fill this!!
b) Motors
The 2 motors were tested once connected to the L298 drivers. They are connected to run in the bipolar
mode, thus, the motor excitation sequence was: 1010, 1001, 0101, 0110.
Functions are written in the code which initialize the motors and control them to run at commanded speeds.
Initially, the inbuilt Stepper.h and AccelStepper.h libraries were used for speed and acceleration control,
however, writing directly into the pins gave a better control of the delay between the steps.
Timer4 of the Arduino is used for all control purposes – the registers of Timer4 were used for speed and
acceleration control by modifying registers such as TCCRxA/B , OCRxA/B, TIMSKx. The Output
Compare Register was crucial to determining the velocity of the bot’s operation. And its rate of change in
turn, determines the acceleration. Every time the overflow is detected, a step change occurs in the motor.
This is calculated as shown:
Arduino’s timer frequency = 16MHz
Prescaler = 1024
So, every tick would correspond to 64μs
Thus, setting the value of the OCR to, say, 255 16.32ms. This value is the time taken for each step of
the motor. Thus, it is seen that the varying OCR value can control the step time, consequently controlling
the motor speed.
c) Ultrasonic Sensor
The ping is the wave that is transmitted and the echo is the received wave. Timer1 is used to control the
sensor. The timer is initialized to a certain value, and at each loop of the specified time, the ISR to calculate
the echo duration is called. This duration which is the difference in time between the time the ping is sent
out and an echo is received, is then used to calculate the distance at which an object is located.
d) Accelerometer
The digital raw readings from the accelerometer need to be converted to linear acceleration data. This was
one of the most challenging aspects of the project. The issue with the initially used analog accelerometer
was that it was not sensitive enough to detect changes of acceleration in the bot. However, the digital
accelerometer was too sensitive and even the slightest vibration in any of the 3 axes would lead to spillage
and error in the other axes. Thus, a filter was implemented.
Being digital data, RC filters were not used, instead digital code was used for data sampling and smoothing
out the noisy values. The code provides a certain period of time (~10seconds) for sensor calibration wherein
the offsets are calibrated and a zero value is calculated.
Once the values are read, the conversion is done by using:
16-bit digital data 216 corresponds to ±2g (the sensitivity of the sensor selected)
Thus, each bit of data corresponds to 0.05981 cm/s2.
6. 6 | P a g e
Step 3: Writing and integrating the above with the closed-loop controller
Using a Proportional Integral (PI) controller the acceleration of the automated car was directed. The
proportional controller was used to stabilized the otherwise unstable motor. This controller will decrease
the steady state error as we increase the gain constant (kp). Although kp will decrease the systems steady
state error, it will also increase the dynamics, therefore gain of the noise. An additional control technique
was used to further reduce error. The integration controller was used to minimize the steady state error. For
any desired velocity achieved by the motor through the acceleration profile, the error will be reduced. The
data received from the accelerometer was used as for unity gain feedback. The difference in the measured
data and the designated acceleration command was found. Once the error was found, a proportional
controlling constant (kp) was applied. In addition, an integration of the acceleration was determined by the
previous error plus the integrated term of the present error. The use of these two coefficients allowed the
automated car to produce reasonable control from the reference to the output. The full system block diagram
is shown under part II-B
V. EXPERIMENTAL RESULTS
The results were observed real-time and the outputs were recorded. The following screenshots show the
variation of the accelerometer readings when the robot detects a change in speed. What is displayed in Fig.
shows the peaks that correspond to the instants when the bot undergoes a change in speed before and after the
filter is applied. Fig. indicates the output at the serial monitor – as described above the OCR value varies in
order to change the speed. When an obstacle is detected within a range of ~25-30cm, the bot decelerates and
this is observed in the increased OCR value. Lastly, Fig. is a snapshot of a phone screen which has the BT app
installed on it. It continuously streams data from the controller while also allowing the user to select the desired
acceleration.
Figure 5 Serial Monitor Output Figure 6 BT Phone App
Distance from Obstacle: 30
New OCR: 900
Distance from Obstacle: 28
New OCR: 900
Distance from Obstacle: 28
New OCR: 940
Distance from Obstacle: 28
New OCR: 940
Distance from Obstacle: 24
New OCR: 940
Distance from Obstacle: 24
New OCR: 940
Distance from Obstacle: 24
New OCR: 980
Distance from Obstacle: 24
New OCR: 980
7. 7 | P a g e
Figure 7 Accelerometer Readings Before & After Filter
VI. DISCUSSION AND CONCLUSIONS
Some important points to note in the creation of this project would be as follows:
1. Body design must house all necessary components for autonomous control.
2. Determining load torque requirements
3. Sizing motors for desired motor torque
4. Battery sizing to provide for all components
5. Blue tooth connectivity for mobile-wireless initialization
6. Obstacle tracking and avoidance procedures using an ultrasonic sensor
7. Command acceleration implementation
8. Control system for tracking command reference given
9. Frequency of error iterations for optimized control
10. Internal Service Routine guidelines and implementation
11. Delay timing and corrections
Several conclusions were arrived to in this process:
1. The external torque load of the system is of main importance when designing the system.
a. It is necessary to account for all power drawn from the total system in order to appropriately
size the system with a source. If not well designed, the extra torque needed for an additional
source could exceed the torque available.
2. When using multiple sensors, it is necessary to efficiently use them in tandem to produce a muli-variable
controlled system.
a. The delay times and corrections need to be assessed here in length in order for smooth and stable
implementation.
3. Filtering is necessary when using any feedback system because noise, when damping is significantly
difficult, will be present in the corrections and therefore reducing the tracking and amplifying the
instability as the control technique is implemented.
4. The control coefficients can be determined with a model and observed estimation of the system with
the state space analysis, LQI, or LQR. Although possible, the model is inefficient when not accounting
for all much of the disturbance seen by controlling sensors.