Ultrasonic Pursuit Automobile Using Atmega

Ultrasonic Pursuit Automobile

We’ve implemented an autonomous pursuit vehicle capable of chasing a designated target using ultrasonic transmissions. The system is demonstrated by chasing a second, human-controlled, RC car. The pursuit unit is equipped with a 24kHz transmitter and two 40kHz receivers, while the target unit has a 24kHz receiver and a 40kHz transmitter. The target unit responds with an ultrasonic pulse emission when its receiver detects an incoming pulse. By timing the respective response times on the two receivers, the pursuit unit calculates the relative position of the target unit. A PID control mechanism then directs the motor to follow the target.

Ultrasonic Pursuit Automobile

By installing a simple transducer pair, the system can theoretically be adapted to follow any target. Some practically useful applications might be as a game, or as a shopping cart that follows a designated shopper. Since the pursuing unit’s microcontroller can observe real-time position data of the target system, installing a well-developed version of such a system on police cars and with civilian installation, speed measurements can be performed by a pursuit vehicle as opposed to having to use speed guns.

working in lab

High Level Design

The complete system consists of two RC cars, their respective MCUs, and the respective associated circuits. Final operation of the system does not require a stationary power source or a computer. The user, using the bundled remote control, drives the target unit. The pursuit unit takes no user input, and follows the target unit in real time, as long as the latter remains within a certain angular and distance range.

The pursuit unit (equipped with an ATMega1284p) periodically emits 24kHz pulses. The target unit (ATMega644) asynchronously waits for an incoming 24kHz pulse and immediately responds with a 40kHz pulse. This response pulse is picked up by two separated receivers on the pursuit unit. Timing the arrival of the incoming pulses at the two receivers allows us to calculate the relative position of the target unit. Finally, the microcontroller controls the motors on the pursuit unit to direct it towards the target unit.

Rationale and Inspiration

All three of us are interested in control systems and their physical implementation. We considered ideas for mobile control systems, and soon settled on the idea of a pursuit vehicle. A primary design motivation was to maximize microcontroller implementation and automation. Therefore, our system does not require connection to any stationary device, such as a power supply or a computer. Additionally, human input is restricted to controlling the movement of the target system, and auditory inputs for coordinate measurement are handled by the microcontrollers.

Background Math

The theoretical framework of the project uses the known value of the airspeed velocity of an unladen soundwave (i.e. the speed of sound in standard conditions), and the resulting time differences in path traversals. The following figure shows the coordinate system used in the project:

Coordinate system of setup

The origin (and thus the coordinate system) is relative to the pursuit system. Points A and B are on the front of the pursuit system, while X represents the current position the back of the target system. The positive y-axis is assumed to be in the direction that the pursuit car faces. The constant x1 is known, while the distances tA and tB are determined by timing the pulse travel times.

As shown in the above figure, using the time difference between pulse arrivals and simple trigonometry, we can estimate the relative angular position of the target unit as deviated from the y-axis. By experimentally accounting for circuit and computation overhead on each response pulse and accounting for path doubling, we can calculate the distances tA and tB of the two receivers from the back of the target unit. This, with the known angular position, gives the distance of the target car along the y-axis, a measure that is used to control the pursuit unit’s motor speed for chasing.

Logical Structure

The project consists of two interacting but independently operating systems. The pursuit system, operated on an ATmega1284p, has four primary stages: the periodic pulse emission stage, the response pulse detection stage, the target relative coordinate computation stage, and the PID motor control. The target system, operating on an ATmega644, has two parallel processes: the human-operated movement control, and the asynchronous response pulse emission.


Hardware Tradeoffs

We had initially considered using RF amplitude detection on three RF receivers to attempt to triangulate the relative position of the moving target. A discussion with Prof. Land revealed that RF triangulation is extremely difficult to practically implement due to strong interference. It would also be impossible to distinguish reflected RF waves from direct transmissions due to the very high velocity of electromagnetic waves. For these reasons, we switched to using ultrasound, using the measured ultrasonic pulse transmission times to estimate the target unit’s position.

Our theoretical calculations revealed that the pursuit unit must use three receivers to obtain the exact relative coordinate of the target. Using two receivers results in two possible locations, one in front of and one behind the pursuit system. During initial component testing, we found that our ultrasonic receivers had limited angular response sensitivity and detected incoming pulses almost exclusively from a conical region facing the receiver. Because of this, the third receiver was not practically able to predict which of the two possible locations was the correct one. We ultimately decided to make the tradeoff of using only two receivers and restricting the target unit to be in the front half-plane of the pursuit unit.

Since the theoretical setup preferred transmission and receiving to take place from the same point (points A and X on the coordinate system shown above), we tried using a transducer that would switch between the two roles. Its switching behavior was found to be too unreliable, so we ultimately used a separate receiver and transmitter

Software Tradeoffs

In software, we opted for a timer prescalar to allow us to time longer pulse traversal times and therefore increase range. Doing so naturally decreases the resolution of time measurement and hurts the accuracy of the coordinate calculation. However, our calculations (as shown above) revealed that with a prescalar value of 64, this inaccuracy is around 1.37mm, which is small enough to be considered negligible in the context of our project.

Existing Products

We did not find any online mntion of an autonomous system to chase mobile targets using ultrasound. The commercial drone “AirDog” has the ability of chasing a user wearing a GoPro camera using Bluetooth, but our system is based on a different technology (ultrasound) and has been developed for a fraction of the cost.

We found that several ECE 4760 projects in the past have used auditory pulsing for collision or position detection. For example, the “Clap-E robot” used a similar concept of following a target using auditory pulses.

Our system differs from these other projects in execution and concept. The ultrasonic pursuit vehicle is not reliant on a human generating a signal (such as a clap) to detect position, but performs the automated pursuit control in real-time. Additionally, our system involves chasing a specific mobile target, and thus cannot simply accept incoming reflections from nearby surfaces, as that would hurt proper position determination.

Software Design


Initialization & Timing Setup

The ATMega644 on the target unit is programmed for asynchronous behavior, with no timing control. We begin by initializing PWM control for the pulse emission through port B3. We used CTC to accurately generate square pulses of a particular frequency (for the target unit, this is 40kHz). A timer is set up for timing the pulse emissions, but since the puulse duration isn’t critical to our poject’s operation, we set a comforable prescalar of 256 on timer 2. Finially, initialization enables interrupts to respond to a falling edge output from the tone decoder.

Pulse Emission & Detection

Pulse emission operates via Pulse Width Modulation. The emitPulse() method first resets the timer, and then emits the 40kHz pulse (OCR0A = 199, and OR-ing TCCR0A with 1<COM0A0) for a duration given by pulseLength.

Pulse detection involves a simple external interrupt vector set to trigger the ISR on a falling edge of the tone decoder output – this signifies a 24kHz signal is being received. The ISR has a call to emitPulse() and then clears the interrupt flag after a short delay to prevent responding twice to a single, long pulse from the pursuit system.


Initialization & Timing Setup

Similar to the ATMega644, we initialize PWM to output 24kHz pulses from port D5. Since a timer is now used to measure response times, the prescalar is reduced to 64 to offer better accuracy of roughly 4uSec. The timer also uses an output control register (OCR3A) and a timer compare ISR to periodically call emitPulse() for pulse emission. Two external interrupts are enabled for each of the two 40kHz receivers on the unit, and they are set to trigger on a rising edge output of the peak detector subcircuit. Finally, we enable PWM on four output ports to bidirectionally control the two motors on the car – one each for linear speed and turning angle.

Pulse Emission & Detection

Pulse emission uses TIMER3_COMPA_vect to reset timer 3, emit a 24kHz pulse using CTC, then turn on interrupts for the two receivers. This occurs periodically, once every 120mSec.

Pulse detection involves two separate external interrupt ISRs for the two receivers. Each triggers when the incoming 40kHz pulse is detected by the circuit, saves the timer value to a variable, sets a variable to inform that it executed and disables itself. If the other interrupt has already triggered, the second interrupt calls coordinates() and PIDcontrol() to continue program operation.

Coordinate Computation

The timer variables tA and tB, as obtained at the interrupt, represent the sum of times for the pulse emission, circuit & MCU overhead, and the returning of the pulse. To obtain corrected values, we experimentally calculated the total overhead by placing the two units at a standard distance and noting the variation between the expected and measured timings. After subtracting overhead, we can simply subtract tA from both variables to account for the path doubling of the initial pulse being sent from A to the target unit. The calculation of the target unit’s relative position is then performed directly as described in the ‘Background Math’ section above.

Motor PID Control

Control of the motors is performed using a standard PID control loop system. The PID system on the front wheels’ motor attempts to keep the angular deviation of the target unit to zero from the y-axis in our coordinate system. For the back motor controlling movement speed, the PID control is defined to keep the pursuit unit at a preset distance (by default, 15cm) from the back of the target unit.

PID Control operation

Hardware Design


The project uses two separate microcontrollers Atmeul Mega644 and Atmel Mega1284 which used to calculate the coordinates from the target car sing the ultrasonic transducers. The Atmel Mega644 was placed on the user car to send a pulse. The Atmel Mega1284 was used on the autonomous car to calculate the coordinate of the user car.

The Atmel Mega644 microcontroller receives the amplified signal from the receiver through amplifier. The amplified signal serves as input to the tone decoder and the tone decoder’s output goes low when it detects a signal with frequency within the bandwidth determined by its associated circuit’s capacitance and resistance values.

Detection Circuit

The tone decoder’s input is the amplified version of the incoming signal that was received by the 24kHz transducer. Therefore the output of the tone decoder after receiving the signal inputs the microcontroller to the external interrupt to detect the falling edge of the signal. The next stage is to emit pulses once the falling edge was detected by the Atmel Mega644. After the Atmel Mega644 receives the signal from the 24KHz, the external interrupt executes and emit pulses of frequency 40KHz via PWM using the 40KHz transmitter. After the PWM emits the signal, the microcontroller then waits for 40ms before clearing the External Interrupt Flag Register (EIFR=1<<INTF0).

The signals that are coming from the 40KHz transmitter on the target unit are received by two distinct 40kHz receivers on the pursuit unit. The two input signals undergo two-stage amplification so that the Atmel Mega1284 microcontroller picks up the voltage with enough amplitude. Each amplified signal is input to the peak detectorwhich outputs a longer duration rising edge. These serve as input to the microcontroller (ports B2 and D3) which interrupts the cpu to calculate the coordinates of the target car by using the aforementioned mathematical formula. Also, the output from the peak detector from each of the receivers inputs the Atmel Mega1284 microcontroller to save the time from each receiver (A and B) and once the two external interrupts executes, coordinates function executes for the target user position which is based on the angle from the chasing car and is located between the two receivers. At the same time PID function executes and adjusts the voltages required for the motor controller to run to adjust the angle of the steering wheels. In this project PID was used to reduce the error for theta to follow the target accurately.

Challenges & Resolutions

Our initial plan to detect incoming ultrasonic pulses was to connect receiver outputs to premade LM567 tone decoder packages with an associated circuit attuned to the proper frequency (40kHz). However, initial circuit tests indicated that the tone decoder’s performance was not always reliable. Prof. Land suggested using a subcircuit with a diode, a capacitor and a resistor (pictured in schematic below) which would output a long duration rising edge in response to the incoming ultrasonic pulse.

However, after a few weeks of using this subcircuit, the microcontroller began triggering several times to the same rising edge. This was a result of the overlaid 40kHz waves on the rising edge. Attempting to fix this in code by disabling external interrupts after the first trigger failed to fix this. With less than a week left to the deadline, we decided to switch back to the tone decoders. The motivation for this decision was that, ideally, a tone decoder would result in a single falling edge that can be used to trigger the external interrupts. However, the interrupts were found to be triggered at a constant time, very soon (roughly 100uSec) after the pulse is emitted by the ATmega1284. We postulated there was a tiny noise-like falling edge on the tone decoder’s output due to the pulse being emitted by the ATmega1284 itself. This issue was successfully resolved by changing EICRA to trigger the external interrupts on a low state (since the tone decoder’s output goes low in response to the appropriate frequency) rather than a falling edge. Soon after, we discovered that the tone decoder had an extremely narrow bandwidth to input signals of amplitude greater than 200mV. By this time, we had discovered that we had overlooked clearing the interrupt flag register when disabling interrupts, so with the proper modifications to our code, we switched back to the circuit suggested by Prof. Land. This finally gave us reliable receiver behavior.

A concern from the very beginning was avoiding interference on a system’s receiver’s due to its own transmitter outputs. Our initial method of tackling the problem was to disable external interrupts for a brief duration while emitting the pulse. Of course, this also made the receivers liable to missing the response ultrasonic pulse from the target unit – this meant our system would have a ‘minimum range’ inherent to it. Additionally, this didn’t prevent undesirably detecting reflected pulses from very nearby surfaces that return to the pursuit system before the response pulse. We tried to attach pieces of foam around the cars to absorb most sound, but it wasn’t reliably preventing reflections. We were successfully able to avoid this by using two distinct ultrasonic frequencies, with one system emitting and receiving different frequencies.

For almost the entirety of our mathematical foundation to determine the target system’s relative coordinates was based on using pythagorean properties to determine the x and y coordinates, this determine the relative angle for the pursuit system car to turn. This included a square root and atan computation that would occasionally yield surprising results. We finally switched to using a trigonometric method to determine the relative angle of the target system directly, and obtain a rough estimate of the distance using this.

As we approached a functional design, we had some issues with wheel traction on the target unit car. This was resolved quite easily by rearranging the position of the breadboard and the battery pack in order to shift the center of mass further back, thereby providing the back wheels sufficient traction to move the car.

The hardware design of the motor controllers for the steering system and the speed system was done using an H-bridge. The H-bridge chosen was an L293D. This H-bridge offered two separate H-bridges. Combining the H-bridge with two PWM outputs from the microcontroller allowed bidirectional control of the motor. By changing which PWM signal was active, the motor would turn either clockwise or counter clockwise. To gain access to the motor terminals the shell of the RC car was removed. After observing the existing circuitry the motor terminal wires were identified and new leads soldered. These leads were then run to the H-bridge, allowing full control of the cars speed and steering systems by the microcontroller.

In order for the signal from the ultrasonic transducers to be detected by the microcontroller, the signal first had to be amplified. Since the frequency of our signal was fairly high an LF 353 op-amp was used since it has a specified bandwidth of 3 MHz. This gave a maximum gain of 75 for a 40 kHz input. Since the input amplitude was as low as 20 mv at times a two stage amplification was used. The rails of the op-amp were 4.5v. This was supplied by a 9v battery. The voltage of the battery was split by using an op-amp circuit provided by the lab instructor (see appendix).

In order for the signal from the ultrasonic transducers to be detected by the microcontroller, the signal first had to be amplified. Since the frequency of our signal was fairly high an LF 353 op-amp was used since it has a specified bandwidth of 3 MHz. This gave a maximum gain of 75 for a 40 kHz input. Since the input amplitude was as low as 20 mv at times a two stage amplification was used. The rails of the op-amp were 4.5v. This was supplied by a 9v battery. The voltage of the battery was split by using an op-amp circuit provided by the lab instructor (see appendix).


Speed of Execution & Accuracy

A PID control algorithm was used to control the steering wheels for turning right, left, and straight. The relative angle that was calculated was used as the feedback signal for the system. The reference signal was set to zero, as that indicated that the pursuit unit was directly inline with the target unit. If the relative angle was calculated to be anything other than zero, the PID algorithm turned the car in the appropriate direction. The different gains of the PID control, the proportional gain, the derivative gain, and the integral gain, were selected through an iterative process. We chose to have a quicker response time at the cost of overshoot due to the need to keep up with the target unit. It was acceptable for the pursuit unit to to “swerve”, but it would not have been acceptable for the unit to turn too slowly as this would cause the unit to lose connection with the target unit (due to the poor angular sensitivity of our sensors).

A PID control algorithm was also used to keep the pursuit unit at a specified distance from the target unit. The trail distance was determined to be about 15 cm. This was chosen as it was a large enough distance that the angular sensitivity of the sensors was not a factor but close enough that the target unit could be a greater distance and still maintain connection with the pursuit unit. This target distance was used as the reference input to the PID algorithm and the y value calculated during the angle calculation was used as the feedback input. Again the PID gain values were chosen through an iterative process. As with the steering the pursuit unit speed was designed to have a very quick response time at the cost of large overshoot. The reasoning for this was that it was observed that since the pursuit car had more weight, its top speed was lower than that of the target car.

The accuracy of the system suffered due to several factors. The biggest factor was inaccuracy of our ultrasonic transducers. Had the reliability been greater and the angular sensitivity less, the system would have seen a great improvement in accuracy. Another factor was the quality of the RC cars. Being relatively inexpensive, the steering system of the car was cheap and poorly designed. The voltage to angle relationship was non-linear, making control very difficult.


In situations where the pursuit unit lost signal from either of the receivers the PID algorithm was no longer called. This meant that the speed and direction settings would remain the value that they were set at, resulting in the pursuit unit going off course and crashing. To prevent this a check was added that set the speed of the pursuit unit to zero if the system went 10 periods without receiving a signal on both receivers.

Interference with Other Designs

Our operating frequencies were well in the ultrasonic band, which meant there was hardly any noise at the audio frequency bands at which our project operated.


The system was designed to be largely automated in behavior. The sole required human input is the remote control for controlling the target unit. For simplicity, we use the premade control system of the RC car used as the target unit.


The results of the design met our expectations. The pursuit unit was indeed able to keep up with target unit. The target unit could weave back and forth, and the pursuit unit would keep up with it. The level of performance was good, but could have been better. Due to the issue of weight on the pursuit unit, the target unit could not go full speed without losing the pursuit unit. Given more time the target unit could have been modified to reduce its top speed, allowing the pursuit unit to maintain a steady sustained chance, improving the experience of the user.

Future Work

Future improvements to this system would most be to increase the accuracy and reliability of the ultrasonic transducers. By increasing the accuracy of the transducers the accuracy of the angle measurement and distance measurement would subsequently be improved. This would directly translate to an improvement in the PID algorithm effectiveness. Upgrading the quality of the RC cars used would also have a direct impact of the overall system performance. Using cars that could vary their speed and have improved steering capability would allow for a more dynamic system. The goal of future improvements would be make it difficult for the user to lose pursuit unit. At the moment the user can get away from the pursuit unit quite easily. Once this level of performance is obtained more features could be added to the system. Instead of the pursuit unit being programmed to follow the target unit, it could try to catch the target unit and make physical contact. Conductive bands could be placed on the perimeter of both the target unit and the pursuit unit. Once the bands make contact an electrical signal would trip an external interrupt on the target car causing it to lose power. This would indicate that the game is over. An LCD screen could be added to display the time that the target car evaded the pursuit car for, allowing for competition. For aesthetic purposes the circuitry would be soldered to solder boards, allowing the electronics to be condensed enough to fit inside the shell of the RC car. This would also cut down on the weight of the car.

Intellectual Property Considerations

The method of ultrasonic position detection is well known and is considered public domain. The rest of the circuitry used is fairly basic and well known as well. There is not much in the way of intellectual property considerations for this project. If the project were to be converted into a commercial product then trademark issues would have to dealt with. The RC cars would either have been to designed from scratch or trademark permission would have to be obtained from the patent holders.

Ethical Considerations

During the course of the project the IEEE Code of ethics was strictly followed by all group members. All decisions regarding design were made with the safety of the group and of other lab mates in mind. Any and all dangers were always disclosed for the purpose of awareness. No conflicts of interest were encountered during this project. The claims of the systems abilities are well within the results seen through testing. All forms of bribery were rejected of the course of this project, no matter how tempting they were. The best effort was made to constantly improve the understanding of the technology used and to apply it appropriately while considering possible consequences. Technical tasks that were out of the understanding of the group were not undertaken until all group members had appropriate knowledge of the tasks at hand. Honest criticism was always held in the highest regard by all group members, and all group members gave out honest criticism to any who seeked it. Any errors found were always acknowledged and fixed as soon as possible. Any and all credit was given out to any party who helped or advised on the project. No person was ever discriminated against due to their race, religion, gender, disability, age, national origin, sexual orientation, gender identity, or gender expression. No action was taken by any of the group member to purposefully injury and person or their property. All group members continuously helped peers to follow the IEEE code of ethics. Every possible move was made to make this project safe, enjoyable, and rewarding for all parties involved.

A. Schematics


ATMega644 schematic

Read more: Ultrasonic Pursuit Automobile

Leave a Comment

Your email address will not be published. Required fields are marked *