Target Tracking Robot
Here’s how I used an ultrasonic distance sensor, mounted on a servo motor to make a robot which detects approaching targets. The sweep from the sensor is sent to a PC via the USB serial port to display the radar plot on the screen using code written in ‘Processing’. Once the target is within a specified range the simulated weapon will turn and effectively engage it.
Your design needs to be large enough to house the Arduino UNO and the associated wiring. As both the weapon and the sensor are wired to the chassis, there needs to be sufficient flexibility in the wiring to allow them to rotate freely. The jet turbine image on the top of the chassis was chosen to hide the many holes drilled into the surface to allow the sound to flow freely from the internal speaker unit.
For convenience I design my projects using Ms PowerPoint, as this allows you to easily place clip art graphics and accurately draw geometric shapes like circles for the LEDs and the outline of the fascia.
If you draw items at the correct size they are then printed at that size on an ink jet printer and can then be cut out, and glued onto a piece of hardboard using PVA glue. This allows you to nest the pieces efficiently in order to save on wasted materials. The photo shows the shapes used in the design which were then cut out of the material using an electric fretsaw.
Once the parts have been cut from the hardboard they can be dressed with a file before being glued together. Note that I drilled the holes for the speaker, LEDs and joints before cutting the profile as this makes the process more manageable and ensures that the material doesn’t fail if you cut the profile before drilling the holes. The parts are simply glued together using a strong PVA based wood glue. I also paste the glue around the edges of the material, as this adds significant strength and robustness to the finished hardboard design. In the photo opposite you can see views of the turret components.
The circuit diagram is shown here on the left, with the Arduino UNO on the left, the speaker in the centre, and the two servo motors and ultrasonic sensor to the right. As the unit is powered from a 7.2v battery pack I chose to feed the servo motors directly from this using three diodes to drop the supplied voltage to around 5v. This isolates potential motor transients otherwise being fed into the digital circuitry, and the UNO 5v regulator does not have to cope with supplying the servo motors. The speaker is fed from two digital outputs via different value series resistors to allow the code to select either a high or low output sound level.
The multicoloured LEDs are wired in series and are easily extendible if more are wanted in your design. Different colours are used to indicate the selected mode.
The single push switch operation is counted by the code to determine which mode the user wants to place the unit in. A single push effectively resets the unit to its default state.
The echo distance data measured by the ultrasonic sensor, and its angle, are sent over the USB serial interface to code written in ‘Processing’ which then presents this as a simple radar plot in a window on your PC. This interface also allows you to select functions with the mouse pointer and send instructions to the Arduino UNO. In the image opposite you can see this plot, along with buttons for selecting functions and text fields in which the transmitted and received instructions are presented.
This interface was designed in PowerPoint, then saved as a .png image which is loaded into the window. Clicking in the top left hand corner of the window will toggle the display of the mouse x and y coordinates. You can also click and drag in the outer radius of the chart to move the ultrasonic radar about its axis.
The following files can be downloaded to help you complete this project. Each has a hyper-link and an associated description. Depending on how your web browser is configured the links will either open the files directly into the browser or offer them as downloads.
Circuit Diagram - a drawing of what is seen in the view above. Use it as a guide to wiring up your project.
Parts list - the things you will need and budget prices.
Physical Templates - drawings produced in Ms PowerPoint. Ensure that they do print at the correct size, if used directly on hardboard.
Software Code - the all important Arduino .ino file which runs the project. See comments below on coding.
Processing Code - the code used by ‘Processing’ to display the radar plot, including the background graphics.
This project relies on the use of three libraries; one for producing tones; one for driving the two servo motors; and the third to drive the multi-coloured LEDs. The first two are included as part of the IDE and the third is the Adafruit NeoPixel library, which can be obtained from the GitHub site here.
The following notes will help you understand how this project works in principle. Each note has a bold heading for quick reference and they are listed in alphabetical order.
.ino File - when you download this file remember to place it in a folder with the same name, otherwise the Arduino IDE will not load it and display an error message.
.pde File - this is the source code used by Processing. The folder contains the 800 x 528 pixel background image, created in PowerPoint and saved as a bitmap file. You will need the open source IDE to run this file, which you can obtain from their home site here.
Push button - on the front edge of the chassis box, this switch is used to select the mode of operation. The unit powers up into Mode 0 which is the safe default state. Pressing the button once briefly will take it into Mode 1, which is a safe (Green) scanning state in which only the sonar rotates. Pressing the button twice briefly will take it into Mode 2, which is the defensive (Red) state.
Serial Port - Note that in this design the serial port baud rate must be set to at least 19200 to ensure that messages are sent and received correctly. It is used in this design for two purposes. One is to send command codes to the unit to set modes of operation. You can use this feature to manually send instructions using the serial monitor interface of the IDE. When the unit is scanning with the ultrasonic sensor it sends out the distance measured at regular intervals, which can then be plotted on a graph by code running on the PC.
If you feel that I haven’t included enough information to allow you to tackle a project of this type then send me an email explaining what you need. Or if you just want to give me some general feedback on this site, or to suggest projects what I might include which would be interesting to you, I’d be pleased to hear from you.