CECS 347 Spring 2019 Final Project Robot Car With Distance Sensors and LCD Display

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

CECS 347 Spring 2019 Final Project

Robot Car with Distance Sensors and LCD Display

By

Hung Le and Vinh Vu

May 14th, 2019

Description: Utilize the wheeled robot with

Added features of LCD Display and distance sensors

To construct an obstacle avoiding car

Introduction
The final project requires students to apply their hardware and software knowledge to

finalize the obstacle avoidance robot. All output and input signals are driven by the Tiva-C

TM4C123G LaunchPad Microcontroller. The robot’s main design and purpose consist of having

the car to avoid detected interfering objects and to navigate itself around the obstacles on its

path. Two sensors are mounted on the chassis at different angles to detect the objects and the

LCD screen displays the sensors’ distances away from obstacles, in centimeters, and the PWM

cycle. PWM cycle controls different speeds of the car, ranging from 0% to 100% cycles. The

goal of designing the obstacle avoidance robot is to implement additional features of sensors and

LCD and connectivity to the existing wheeled robot for an advanced car.

Operations:

The obstacle avoidance robot requires the use of pulse width modulation (PWM), analog-

to-digital conversion (ADC), and Nokia 5110 with synchronous serial interface (SSI). Hardware

components consist of two DC motors, H-bridge driver, battery pack, chassis frame, two sharp

IR sensors, Nokia 5110 LCD red model, a potentiometer, and a clean voltage filter. The

potentiometer outputs different voltage values that control pulse width modulation and its duty

cycle in software which results in changing the motor’s speed. At 0V, the motors have no

motion; as the voltage increases, the duty cycle for PWM increases which results in faster speed

until reaches a 3.3V analog signal. Each different PWM duty cycle represents different speeds on

the two DC motors ranging from 0% to 100%.

Analog-to-digital conversion values are received from the two sharp IR sensors mounted

on the front of the robot. Different ADC values represent the various closeness of detected

obstacles. Higher ADC values represent closer objects to the sensors while lower ADC values

signify that the objects are further away. The Nokia 5110 screen is used to display both sensors’

distances from obstacles, in centimeters, and the PWM duty cycle. If the obstacle is out of range,
the string “out” will be displayed. When the two sensors cannot detect any obstacles in their

ranges, the robot car stops in its track. The car also stops when both sensors detect an obstacle

too close to them. No premade motor controller can be used; all have to be coded in Keil and

programmed on the Tiva-C TM4C123G LaunchPad Microcontroller.

Theories

The final project demonstrates our understanding of interfacing hardware analog

components with TM4C123G and successfully apply the concept of pulse width modulation

(PWM), analog-to-digital conversion (ADC), synchronous serial interface (SSI) with the Nokia

5110, and wiring physical components. The Tiva board is encoded with C hex file and connected

to a DC motor H-bridge driver through a four-pin input signal that drives both DC motors. The

H-Bridge has four control pins that can be used to control 2 DC motors. Motor A and motor B

are driven through Port A pins 1 through 4. PA1 and PA3 signals from the microcontroller drive

the PWM speeds of motors. PA2 and PA4 signals drive the direction of motor rotation, high or

low.

Pulse width modulation generates digital output waves of fixed frequency (duty cycle)

but allows the potentiometer to vary the duty cycle, from 0% to 100%. By using a potentiometer

to drive the PWM, we are able to adjust the speed of the robot based on the generated duty cycle.

The potentiometer output range is 0V to 3.3V. At 0V, the motors remain stationary; as the

voltage increases when turning the potentiometer, the motors speed up until reaches 3.3V analog

signal is reached. For this particular project, the max allowable speed is 98% high on the duty

cycle to assure safe driving of the DC motors and its driver alongside achieving a fast speed. The

minimum speed of this robot is set to 0% duty cycle meaning the robot will be stationary until

the potentiometer increases the voltage.


TM4C123G’s ADC collects and sample data using programmable sequencers. All sample

sequencers have the same functionalities except for the number of samples they can collect. The

car uses sequencer 1 with the number of samples equal to four and the maximum sampling rate

being 125k samples/second. Port E is initialized to intakes ADC values coming from both

sensors and calculate the distance based on those data. In order to precisely convert the collected

ADC values to distance, a controlled data-collecting experiment was conducted. ADC along with

voltage values are recorded on a table when an object is placed 5 cm-70 cm away from one

sensor, with 5 cm increments. Based on recorded values, a best-fit equation is generated to

convert ADC values to distance. The calculated distance is then utilized to determine DC motor

speeds in order to avoid obstacles along its path. Another method of finding the distance from

ADC value is table lookup. Recorded values from the experiment are saved in a list inside the C

code. Table lookup methodology takes the ADC value coming from the sensors, finds its next

larger and smaller value from the recorded table, and calculates the distance based on the ADC

difference ratio.

The ADC and PWM functionalities work coincide with each other to drive the obstacle

avoidance car. When an object is about 30 cm near the car, the PWM duty cycle is turned off for

the opposite wheel to turn the car away from the obstacle. When both sensors detect objects

within 30 cm range, both wheels’ PWM cycles get turned off and the car stops. When both

sensors detect nothing within their ranges, the car also comes to a half.

The synchronous serial interface is a synchronous serial communication channel for

digital data transmission. We are using one of the SSI to control the Nokia 5110. The LCD has

an 84x48 pixel matrix. Each ASCII value has 7 pixels wide and 8 pixels high; there can be 12

characters and 6 rows to be displayed on the LCD screen. The information to be displayed on the
LCD includes: calculated or table lookup for both IR sensors, PWM duty cycle, and if nothing is

in range then the string “out of strange”.

A clean voltage filter is added onto the car after encountering dirty power problems in

Project 2. The voltage stabilizer includes a 5V voltage regulator with one 10 uF capacitor and

three 0.1 uF capacitors in parallel. The 5V voltage regulator converts the 12V power coming

from the battery into a 5V power supply. The capacitors placed parallelly stabilizing the 5V to

avoid voltage rippling.

There is a software filter implemented inside our program to stabilize the analog signals

for our ADC conversion. The software filter takes in three analog signals and uses the median for

one sampling. By implementing this filter, the input analog signal’s error range is lessened by the

medians.

Hardware
Software

LCD Display:
ROBOT-CT
LT RT
00 00

Pot_data
0000 00%

SYSTICK -----------
1ms

ADC ---------------
SAMPLE ORDER - PE1->PE4->PE5
Right sensor - PE1
Left Sensor - PE4
Potentiometer - PE5

LCD ---------------
RST - GPIO - PA7
C/S - SSI - PA3
DC - SSI - PA6
DIN - SSI - PA5
CLK - SSI - PA2

PWM ---------------
PWM1A - PB6
PWM1B - PB7
Direction - PB0,1,2,3
Forward - PB2,3
Backward - PB0,1

Functions:
● Distance_Cal()
● steering()
● ReadADCMedianFilter()
● speedFromADC()

Distance_Cal(): Input - ADC value


Output - Distance calculated from equation

Steering(): Input - left distance, right distance, speed


Controls PWM signal going to each wheel depending on distance values from

sensors. PWMA indicates left wheel, PWMB indicates right wheel. Stopping

conditions for wheels are when sensors detect objects less than 20 cm or more than 38

cm. If left distance less than 30cm, turn PWMB off (0% duty cycle right wheel),

PWMA remains constant. If right distance less than 30cm, turn PWMA off (0% duty

cycle left wheel), PWMB remains constant.

ReadADCMedianFilter(): Input - ain2, ain 9, ain8

Filter the 3 ADC inputs by sampling 3 times and calculating the median.

Main Function Loop:

Calculate distance from sensors using Distance_Cal(). Calculate pwm cycle value from

potentiometer using speedFromADC(). The three values are then used to control the robot by

utilizing steering() function. Two distance values from sensors are displayed on LCD. If distance

is greater than 50, then “Out” will be outputted instead of a distance value. Current speed and

percentage of PWM is also displayed on LCD.

Conclusion:

While debugging the obstacle avoidance car, major issues involving software and

hardware were encountered. One major hardware problem was the mounting angle of the two
sharp IR sensors. Initially, the sensors were mounted vertically at two front corners of the car.

When the car is in motion, it often comes to a halt even though the obstacles are further away.

After test running the car a few more times, the problem was that the sensors were mounted too

close to the ground along with the vertical mounting position. As a result of the wrong

positioning, the sensors would detect the ground when the car runs since they read outward and

horizontally. To fix this hardware issue, the sensors are raised higher off the ground along with

turning them horizontally. The reason behind the change is that for the sensor to read with its full

range and detect objects at its operation level and not the ground. When we test drive the car on

the final track, the robot car runs into the walls when the PWM cycle is turned to 100%. The

sampling speed for the analog signal was too slow. We sped up the sampling speed to match up

with the maximum PWM cycle controlled by the potentiometer.

One major software logic that was falsely implemented is the driving PWM for both

motors when an obstacle is detected. When an object is detected from the right sensor, the left

wheel is supposed to slow down while the right wheel speeds up in order to steer the car away

from the obstacle. However, the initial software logic speeds up the left wheel and slows down

the right wheel which drives the car into the object rather than dodging it. The solution to this

software issue is simply switching the PWM logic for both motors since they are flipped initially.

After changing the code, the car avoids obstacles as intended and runs smoothly on the final

track.

Demo video link: https://youtu.be/lF3ES5Knzv4

Source Code: https://github.com/hungx92/Wall-Following-Robot.git

You might also like