# ECE 476 Final Project: Cooler-Bot

Created By Daniel Lee (dl285) and Robert Zimmerman (rmz8)

# Contents

## Introduction

Cooler-Bot is an autonomous vehicle that uses ultrasonic transducers to sense distance and direction to a remote ultrasonic mobile unit that it is designed to follow.

Our original goal was to design a vehicle that would carry a beverages for the user and follow them at a distance of about 1m around the Atmel MEGA16L microcontroller. This vehicle would be ideal for example on a golf course, allowing you to play golf and have a beverage at hand. We decided to use ultrasound for location detection. For the robot, we used a modified, gutted RC car. The car follows a small, remote ultrasonic mobile unit. When the distance to the mobile unit exceeds about 1m, the car will travel in the direction of the mobile unit until the distance is again less than 1m.

## High Level Design

### Rationale

The idea for this design came when Rob saw a similar device for carrying golf clubs at a golf course. We decided it would be cool to build something like it. We explored several options for distance and location detection. We decided using RF would be far too difficult because the timing is on the order of very short intervals. Infrared was another option, however a large number of sensors would be required. We settled on ultrasound as result.

### Background Math

Initially, we planned on using trigonometry to calculate exact position of the mobile unit. However, we later determined that comparing two distance measurements would suffice and simplified the code. Distance from each receiver on the car is approximately equal to the time delay between transmission and reception divided by two, multiplied by the speed of sound:

Distance = (Time)•(Speed of Sound)/2

### Logical Structure

Our design process had many stages. First, we tore apart the RC car. We discovered how to power the motors and soldered a board to show motor control. Once the motors were working, we began the task of ultrasonic range finding.

First, we found the resonant frequency of the sensors since there was no datasheet available. We then wrote code to detect and emit short ultrasonic (23.8kHz) pulses. After this, we modified the code to detect distance between an emitter and a receiver. This was then extended to two receivers. We then created a second board that was a simple mobile unit. This board resent any ultrasonic pulses it received, effectively doubling the range. Finally, when all these parts were working, we integrated and tested each system until it worked satisfactorily.

Our project is organized as follows:

MEGA16L
We used the MEGA16L for its A/D capabilities. We chose this over the MEGA32 since we did not need the extra memory. Program details are discussed later.

Rear Motor
This motor was controlled via a MOSFET and powered by the car batteries. This motor is used for forward motion.

Front Motor
This motor is controlled through an H-Bridge and again powered by the batteries. This controls turning of the car.

Ultrasonic transducers
These transducers were found in lab. One transducer on the car is used as a pulse transmitter. The transducer on the mobile unit is used to listen for pulses and then immediately retransmit another pulse. The remaining two transducers on the car are used for receiving this retransmitted pulse, thus allowing us to determine distance and direction.

• A/D Sample Rate - We needed to use a high enough sample rate to detect the 23.8kHz signals, so at least 47,600 samples per second were needed. However, sampling too fast reduced accuracy and caused the timer interrupts to not trigger with precise timing. We eventually chose to run the A/D clock at 1/16th the CPU clock, allowing about 71,000 samples per second. In order to keep up with this sample rate, we had to make the detection code efficient. This sample rate offered about 300 cycles to do all conversion math. To optimize this, we only used the high 8 bits of the conversion and did all conversion math outside of the ADC interrupt to allow timer interrupts to trigger on time.
• Tone Detection - We originally were using a tone detector chip to detect 23.8kHz signals. However, the received signals were small (around 100mV) and needed to be amplified to trigger the tone detector. However this caused positive feedback and falsely triggered the detectors often. As a result, we wrote code to detect the tone off the ADC inputs. This code worked well, however it required optimization as discussed above.
• Receiver Positioning - The positions and relative angles of the receivers affected the quality of reception. We experimented with several orientations and eventually decided to put the two receivers about 1 ft apart and angle them about 30 degrees away from center. Also, software thresholds for tone detection were affected by positioning and had to be optimized by trial and error. Too low a threshold allowed false triggering, however too high a threshold reduced range to an unusable amount.

## Standards

There are no applicable standards for our project. However, we imagine the noise would annoy several types of animals.

## Patents

This type of location is common enough and well known enough that it seems unlikely that there are any active patents regarding our project.

# Program and Hardware Design

## Program Details

The program on the MEGA16L on the car was used to transmit and detect an ultrasonic pulse, and to control the motors when it was proper. Timer1 and Timer2 were set to overflow at 23.8kHz, and thus OC0 and OC2 produced 23.8kHz square waves. OC2 was switched on and off to power the transmitter, and it was pulsed for a short duration several times a second. OC0 was feed back to an input pin for tone detection.

Tone detection was accomplished using the AD converter in differential mode with 10x gain. Each sample was "multiplied" by the feedback OC0. In reality, the sampled value was multiplied by 1 if OC0 was high, and -1 if OC0 was low. The resulting was low pass filtered by averaging the last 8 samples. This reports a high number if the input is 23.8kHz, but very small input otherwise since:

Any noise will simply be low pass filtered out.

To determine distance, a timer was run concurrently with the A/D converter. To assure accurate timing, A/D math was done outside of the interrupt to allow the timer to trigger as close to its intended time as possible. The timer had two functions, first to control pulse output and also to then count the time until pulse detection. Each time a pulse was detected by the A/D routine or enough time had elapsed, the A/D input was switched to the other speaker. This way both speakers were sampled and enough time was given for the A/D converter to settle before reading it. Originally, we intended to sample the left and right receivers quickly in succession, however this would not work since the A/D converter needs about 125 microseconds to settle when inputs are switched. This corresponds to minimum observable distance of about 4cm, which was too small for this project. Because we alternated inputs, we could observe both distances by speeding up the pulse rate.

The distance was calculated by averaging the two observed distances. This is not an exact result, but provided enough accuracy for our purposes since the two receivers were relatively close. The rear motors were started whenever the distance exceeded a maximum value experimentally determined to be around a meter. The motors were then stopped if the distance was determined to be less than this value. The motor was pulsed at a 50% duty cycle. This was done because the car's motor was far too powerful and would often stop but still have enough momentum to attack the user. This resulted in the user running away causing the car to chase them due to positive feedback. We initially intended to calculate angle, however we decided this was unnecessary. We could simply determine rough direction by comparing the distances of the two receivers; for example, if the distance was shorter for the left receiver, this would mean that the user to the left of the car. This provided sufficient accuracy to steer the vehicle.

Occasionally, one or both receivers would not be able to hear the retransmitted pulse. To mitigate this issue, we only updated distance values when a valid measurement occurred. This is valid since we assume the user does not move particularly fast and is probably close to the last known position. After a long period of receiving from only one receiver, we would assume that the user was 45 degrees in the direction of the working receiver by adjusting the blind receiver distance to be slightly greater than the working receiver distance. This is valid because we tilted our receivers, so if the user is too far to the right or left of the car, one of the receivers will lose signal. This concludes the car code.

The mobile unit used code similar to the car code. However, the A/D converter simply ran until detection, at which point a pulse was transmitted followed by some silence to settle the transceiver. A/D conversion was then restarted. Refer to appendix for code.

mobile unit

## Hardware Details

We started from an RC car base. We removed the RF components, leaving simply the body and the motors and wheels. We found that the motors were simple 6V DC motors. We also kept the battery pack as a power source.

The motor setup is shown in the schematic appendix.
The BUZ71 and diode is the same circuit used for Lab 5 (the fan). The H-Bridge chip was used to control the front (turning) motor.

The transceivers operate at 23.8kHz and were somewhat large. The two receivers were placed about 25cm apart. The leads were connected to the A/D converter. PORTA0 and PORTA1 were used for one transceiver and PORTA2 and PORTA3 were used for the other. Using differential mode offered more accuracy (less noise) and built in gain. The transmitter was hooked from the OC2 pin (PORTD7) to ground. When the OC2 pin was active, this created a 23.8kHz square wave pulse. The three transceivers were mounted on a foam core board and placed on the grille of the car.

Sensor Locations

On the mobile unit, the transceiver was also hooked to PORTA0 and PORTA1. However, it was also connected to OC2 and gated via a BUZ71 to ground. This allowed it to transmit when OC2 was active and the transistor was on, and to receive when both were off.

To power the car MCU board, the 6V array of AA batteries was used. This is lower than the required minimum for the board regulator, however it simply produces a reduced voltage (about 4.75V) and works fine. The motors are not driven off the regulator since it can only source about 100mA. The motors require about 0.8A and run straight off the batteries. We added an external power switch to avoid opening the car to start and stop it.

For the mobile unit board, we used a 9V battery. This well within recommended range and is very portable.

Given the correct materials, anyone in this course could easily recreate this project using our code. However, if different transceivers or a different car were used, modifications would be necessary.

## Things That Didn't Work

We first tried sensing ultrasound using standard microphones. This did not work since these microphones are not designed to work well about 20kHz. Professor Land kindly provided us with actual ultrasound sensors which solved our problem.

Later, we were having trouble with the mobile unit before we found our timing problems. This caused us to rethink our design. We tried a design that used the mobile unit simply to output pulses 1 second apart. The car would ideally hear the first pulse and use this first measurement as the threshold at which to start or stop. Subsequently, the car would use the relative delay from the user. This did not work well at all due to even worse timing issues. We never truly did figure out what went wrong, but going back to our original idea, we managed to correct our problems.

The H-Bridge controlling the front motors had a large output resistance. This caused the motor to be too weak to turn the vehicle. We could not obtain a better chip in time, so we were forced to remove a spring that caused the wheels to tend toward the center. This caused a slight serpentine motion, but improved the car's ability to turn.

# Results of the Design

Because of the \$50 limit, we chose to use the free ultrasonic receivers. While these receivers work very well, they are somewhat directional and worked best within about 2m. As a result, because of the way our receivers are position, the car only follows reliably when the mobile unit is at the same height as the car. More expensive receivers could likely mitigate this issue.

Taking readings several times per second made the car significantly more responsive. However, this also reduces battery life by increasing the duty cycle of the transmitters.

The car follows the transmitter very well. We have never observed the car responding to any stimulus other than the mobile unit. The car does occasionally lose signal at large angles. This causes the car to travel in a circle until it finds signal again.

We observed early on in development that the ultrasonic detection was good to several centimeters. This was better than required for our project, so distance detection is fairly accurate on the car. The car does indeed stop when it gets too close. This high accuracy actually allowed us to determine a rough angle given two separate sensor readings. We set the distance threshold arbitrarily to a number that produced a stop distance of about a meter since exact distance was never a goal of this project. If more precise distance was required, we could easily modify the code to the desired threshold.

In order to ensure the safety of the user and the car, the motor speed had to be limited as discussed earlier. The full speed was far too dangerous (we were often chased away by the car) and the car attempted to destroy itself upon the walls of Phillips several times. The speed is now more manageable (at 50% duty cycle). The slower speed also caused the car to perform much more smoothly with less stopping and starting.

Since other groups were using 23.8kHz receivers, we had to make sure to stay far enough away to avoid interference. We never noticed any interference (other than from our own stupidity).

Our project is usable, however the mobile unit would have to be attached to one's foot. It does accomplish its goal of carrying a drink with the optional beverage holder attachment. Because of the limited ultrasound range and high directionality, the user may have to be slightly patient with the device. With more expensive receivers, we are confident that our car would perform even better. The device requires no technical knowledge to use correctly, however it currently takes some back and thigh muscles while bending over and backing up if you are unwilling to attach the mobile unit to your foot.

Car Control Board

# Conclusions

We were pleased with the results of our project. We would have liked less directionality and more range from the car, but it does serve its purpose of following the user. Were we have more time and resources, we would use less directional sensors and possibly more power. Other than this, there is not much we would change.

Our project was not constrained by any standards or regulations. Our design was unique and our own. All the code was our own. Some simple setup code (such as timer and ADC start code) was based off previous labs. It is unlikely that this design is patentable since similar devices exist and the technology is fairly prevalent.

## IEEE Code of Ethics

Electrical Engineers are held to ethical standards by the IEEE. Throughout the project we did our best to maintain these high standards.
1. 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;
We limited the speed of our car to avoid injuring any user. We also made sure to test our project in places where we would trip or disturb anyone.
2. To avoid real or perceived conflicts of interest whenever possible, and to disclose them to affected parties when they do exist;
We offered legitimate help to other groups who asked us questions even though all of us are technically competing for grades. All the other groups we interacted with in lab were quite friendly and obviously took this ethical standard as seriously as we did.
3. To be honest and realistic in stating claims or estimates based on available data;
This lab report is an honest account of our project, and no data has been falsified.
4. To reject bribery in all its forms;
We were not bribed during the course of this project, nor would we have accepted any bribes.
5. To improve the understanding of technology, its appropriate application, and potential consequences;
This has always been the goal of this course and this final project. We have always done our best to follow this philosophy.
6. 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;
We made no claim coming into this class that we were at all competent. We feel that we've improved our skills and are now sufficiently capable designing systems based on Atmel microcontrollers.
7. To seek, accept, and offer honest criticism of technical work, to acknowledge and correct errors, and to credit properly the contributions of others;
We talked with Professor Land and the TAs throughout the project. We accepted and welcomed their advice and criticism. Talking to other groups was also very helpful the overall completion of our project.
8. To treat fairly all persons regardless of such factors as race, religion, gender, disability, age, or national origin;
This was not a problem encountered during this project.
9. To avoid injuring others, their property, reputation, or employment by false or malicious action;
There was never any intent to harm others with our project.
10. To assist colleagues and co-workers in their professional development and to support them in following this code of ethics.
We tried our best to be helpful to other groups and we did not try to mislead them in any way.

# Appendices

## Code

car.c - Code for the car
belt.c - Code for mobile unit

## Schematics

Motor Circuit Schematic

## Budget

 Part Cost (\$) Obtained From RC Car 20.00 Toys R' Us Custom PC Board 5.00 Bruce Land Last Year's Board 2.00 Bruce Land 2 MEGA16Ls 10.00 Bruce Land 4 Ultrasonic Transducers 0.00 Found in Lab 2 BUZ71s 0.00 Found in Lab 2 TC4424 H-Bridges 0.00 Microchip (sampled) Foam Core Board Piece 0.00 Salvaged from Dan 9V Battery Clip 0.50 Radio Shack Batteries (1 9V, 4 AA) 6.00 Estimated Price, found at home Assorted parts (wires, etc.) 0.00 From Lab Total 43.50

Both of us worked together on all parts of the project. We switched off often on each task.

Dan Lee

• Design
• Ordering Parts
• Soldering
• Dremmeling
• Programming
• Prototyping
• Integration and Test
• Final Report

Rob Zimmerman
• Design
• Ordering Parts
• Soldering
• Dremmeling
• Programming
• Prototyping
• Integration and Test
• Final Report

Cooler-Bot
• Not turning
• Running away
• Running in circles
• Hitting walls
• Chasing people
• Annoying dogs

## References

We would like to thank Professor Land and the TAs for all of their help. Thanks to our classmates for taking the time discuss our project.