Project Report
Electronics Workshop-II
1
ASTRAL
Arduino-based Surveillance
and Tracking Radar with
Advanced Lasers
2
Table of Contents
2
Aim 3
Abstract 4
Components Required 5
Theory 10
Code Explanation 17
Our Research 27
Future Prospects 30
Conclusion 32
3
Aim
The aim of this project is to design and build a functional radar system using an Arduino
microcontroller. This system should be able to:
1. Detect objects in its vicinity using ultrasonic sensors.
2. Measure the distance and angle of the detected objects.
3. Display the results of the scan on a TFT display for visual representation.
4. Provide numerical data on distance and angle via an LCD screen.
5. Implement a laser defense mechanism that activates automatically when objects
approach a certain distance.
6. Allow user control to trigger a laser attack at an even closer range.
4
Abstract
This project describes the design and construction of an Arduino-based radar system with
laser defense capabilities. The system utilizes an ultrasonic sensor for object detection and
distance measurement. A servo motor rotates the sensor to achieve a sweeping scan,
visualized on a TFT display. The detected object's distance and angle are also displayed on
an LCD. For added defense, a laser module activates when an object comes within close
proximity (10 cm), with a user-controlled touch sensor triggering a laser attack at an even
shorter range (5 cm). This report details the components, functionalities, and software
development behind this interactive radar system.
5
Components Required
Hardware:
● Microcontroller:
○ Arduino Uno
● Sensors:
○ Ultrasonic Sensor
○ Touch Sensor
● Displays:
○ TFT Display
○ LCD Display
● Actuators:
○ Servo Motor
○ Laser Module
● Other Components:
○ Breadboard
○ Jumper Wires
○ Power Supply (e.g. USB cable or battery pack)
Software:
● Arduino IDE (Integrated Development Environment)
6
7
8
9
Fig 1. (a) Ultrasonic Sensor with Servo Motor (b) Touch Sensor (c) Laser Module
(d) TFT Display (e) LCD Display (f) SD Card Module
(g) Speaker (h) Audio Amplifier
10
Theory
Radar Functioning with Sonar
Traditional radar systems use radio waves to detect and measure the distance of objects.
Imagine throwing a pebble across a lake – the ripples travel outwards, bounce off the
opposite shore, and return. Radar works similarly, but with radio waves traveling at the
speed of light. By measuring how long it takes the radio wave to make this round trip, the
radar can figure out how far away the object is.
In our project, we're taking a similar approach, but on a much smaller scale and with sound
waves instead of radio waves. This method is called sonar (SOund Navigation And Ranging).
Sound waves travel way slower than radio waves – around 343 meters per second at room
temperature, which is about the speed of sound traveling through the air. But for short-range
detection like in our project, sonar offers a practical and affordable solution.
Let's break down how radar with sonar works in detail:
1. Sending the Signal: Our ultrasonic sensor acts like a tiny speaker, blasting short bursts of
high-frequency sound waves we can't hear into the environment.
2. Sound Travels Outward: These sound waves travel in all directions from the sensor, just
like ripples on a pond. The specific frequency, or pitch, of the sound waves we use can be
chosen depending on how far we want to "see" and how detailed we want the picture to be.
3. Bounce Back: When the sound waves bump into an object, some of that sound energy
bounces back towards the sensor like an echo. The strength of this echo depends on the size,
material, and surface of the object it hit.
4. Hearing the Echo: The ultrasonic sensor also acts like a microphone, listening for these
returning echoes from objects. It has a special part that can pick up these sound waves.
11
5. Timing is Key: The Arduino is like a super precise stopwatch in this process. It starts timing
the moment the ultrasonic sensor sends out the sound waves and stops the timer when it
hears the echo come back.
6. Distance Revealed: Knowing the speed of sound (a constant value programmed into the
Arduino) and how long the sound wave took to travel back and forth, the Arduino can
calculate the distance to the object using this formula:
Distance = (Speed of Sound Round Trip Time) / 2
Here, round trip time refers to the total time it took for the sound wave to travel to the object
and back. Dividing by 2 accounts for the fact that the sound wave traveled the distance once
to the object and again back to the sensor.
7. Putting it all Together: The calculated distance information is then used by the Arduino to
update the visual representation on the TFT display (if we're using one) and the numerical
values on the LCD. The TFT display might show a sweeping line or little icons representing
objects based on the distance and angle (explained later). The LCD would typically show the
distance in centimeters or meters.
Advantages of using Ultrasonic Sensor
● Budget-Friendly: Ultrasonic sensors are much cheaper than fancy radar systems.
● Power Efficient: They don't need a lot of power to work, which is perfect for our
battery-powered Arduino project.
● Safe for Indoors: The sound waves we use are inaudible to humans and don't pose any
health risks.
● Great for Short Ranges: Since we only need to detect objects within a few meters,
sonar offers a practical solution.
Disadvantages of using Ultrasonic Sensor
● Not a Big Fan of Noise: Sound waves can be affected by things like temperature,
12
humidity, and even background noise, which can sometimes mess with the accuracy.
● Limited Range: Compared to radar, sonar has a much shorter effective range because
sound travels slower.
● Picky with Materials: The reflection of sound waves depends on the material of the
object. Sonar might have trouble detecting objects that absorb sound waves, like thick
curtains.
Overall, our project leverages the core principle of radar using sonar technology for
short-range object detection. By measuring the time it takes for sound waves to travel to an
object and back, the system can calculate the distance and provide a visual and numerical
representation. While sonar has its limitations, it's a practical and cost-effective choice for
our specific application.
13
Deep Dive into Component Functionalities
The success of our Arduino-based radar system hinges on the precise interaction between
various components. Let's delve into the nitty-gritty of each component and how they work
together:
1. Arduino UNO:
The Arduino serves as the brain of our system. It's a programmable microcontroller that
receives sensor data, controls other components, and executes the program logic we've
written.
Data Hub: The Arduino acts as a central hub for information exchange. It receives raw data
from the ultrasonic sensor (distance measurement) and touch sensor (user input).
Decision Maker: Based on the received data and programmed logic, the Arduino makes
decisions. For instance, it determines if an object is close enough to trigger the laser defense
or if the user has activated the touch sensor for a laser attack.
Communication Master: The Arduino communicates with the TFT display (if used) and LCD
using specific protocols to send instructions and update information. It essentially tells the
displays what to show.
Signal Sender & Receiver: The Arduino sends control signals to the servo motor, dictating its
movement and the sweep pattern for the ultrasonic sensor.
2. Ultrasonic Sensor:
The Eye of the System: This sensor acts as our primary object detection tool. It emits
high-frequency sound waves beyond human hearing and detects their echoes reflected off
objects.
Sound Pulse Generator: The sensor generates short bursts of ultrasonic sound waves at a
specific frequency. This frequency can be chosen based on our desired range and object
resolution.
Echo Listener: The sensor also functions as a receiver, equipped with a microphone or
piezoelectric crystal to pick up the echoes returning from objects.
14
Data Provider: The sensor doesn't directly calculate distance. Instead, it sends the time it
takes for the sound wave to travel back and forth (round trip time) as raw data to the
Arduino.
3. TFT Display:
Visual Representation: This display provides a dynamic visual representation of the radar
scan. It can potentially show a sweeping line indicating the sensor's movement or icons
representing detected objects based on their distance and angle.
Software-driven Graphics: If using Processing software, we can create more advanced
graphical representations on the TFT display, like customizing object icons or color-coding
distance ranges.
Communication Interface: The TFT display receives instructions and data from the Arduino
through a specific communication protocol (like SPI) to update the visuals.
4. LCD Display:
Number Cruncher: This display focuses on numerical data, presenting the calculated
distance and angle of the detected object in a clear and concise format (typically centimeters
or meters for distance and degrees for angle).
Simple Communication: The LCD communicates with the Arduino using a simpler protocol
(like I2C) to receive and display the calculated values.
5. Servo Motor:
The Scanner: This motor plays a crucial role in enabling a sweeping motion for the ultrasonic
sensor. By controlling the servo motor's angle, we can rotate the sensor and achieve a wider
scanning area.
Precise Control: The Arduino sends specific control signals to the servo motor, dictating the
desired angle and sweep pattern. This ensures the sensor covers the entire range of interest.
15
6. Laser Module:
Defense Mechanism: This module acts as a laser defense system, adding an interactive
element to our project. It emits a focused beam of light when activated.
Automatic Trigger (Optional): We can program the Arduino to automatically activate the laser
module when an object comes within a certain predefined distance (e.g., 10 cm).
User-controlled Attack (Optional): The touch sensor can be integrated to provide user control
over the laser attack. When the user touches the sensor, the Arduino can trigger the laser
module even if the object isn't within the automatic activation range (e.g., 5 cm).
Safety First: It's crucial to ensure we use a laser module with a safe operating class and
follow all safety guidelines for laser operation.
7. Breadboard and Jumper Wires:
The breadboard serves as a temporary platform for connecting all the electronic
components using jumper wires. It allows for easy prototyping and troubleshooting. Jumper
wires act as the electrical pathways between the components on the breadboard. They carry
electrical signals and power, enabling communication and data flow between components.
16
Fig 2. Complete Radar System Assembled and Ready for Operation
17
Code Explanation
● Include Libraries:
○ Lines 1-4: These lines include necessary libraries for communication with
different components:
i. SPI.h: For communication with the TFT display (if used)
ii. Wire.h: For communication with the LCD via I2C protocol
iii. LiquidCrystal_I2C.h: Library for controlling the LCD display
iv. Servo.h: Library for controlling the servo motor
v. Ucglib.h: Library for controlling the TFT display graphics (if used)
18
● Define Pins:
○ Lines 5-8: These lines define pin numbers for various components:
i. laserPin: Pin connected to the laser module (pin 7)
ii. ctsPin: Pin connected to the touch sensor (pin 4)
iii. trigPin and echoPin: Pins connected to the ultrasonic sensor for triggering
and receiving sound waves (pins 6 and 5)
19
● Global Variables:
○ Lines 9-18: These lines declare variables used throughout the program:
i. Ymax and Xmax: Define the maximum display resolution for the TFT display
(if used)
ii. base: Sets the starting position (base) for the servo motor sweep
iii. pos: Represents the current position of the servo motor
iv. deg: Stores the calculated angle based on servo motor position
v. x: Loop counter variable
vi. val: Scaling factor for drawing lines on the TFT display (if used)
vii. j: Counter variable used for line drawing (if used)
viii. myServo: Creates a servo object to control the servo motor
ix. lcd: Creates an LCD object to control the LCD display
x. duration: Stores the time taken for the sound wave to travel back and forth
xi. distance: Calculated distance to the object based on travel time
xii. k: Temporary variable used for mapping servo motor position
xiii. ucg: Creates a Ucglib object to control the TFT display graphics (if used)
● Helper Functions:
○ fix(): This function (lines 20-34) is used to draw the fixed elements on the TFT
display (if used). It creates circles and lines representing the scan area and
reference markers.
○ calculateDistance(): This function triggers the ultrasonic sensor, measures the
echo pulse duration, and converts it to distance using the speed of sound.
20
● Setup Function:
○ Lines 45-62: This function runs once when the Arduino starts:
i. Sets delays for initialization
ii. Initializes the servo motor object, attaching it to a specific pin (pin 3)
iii. Initializes the LCD display with backlight
iv. Initializes the TFT display library (if used) with necessary settings
v. Sets the trigger pin for the sensor as output and echo pin as input
vi. Sets the laser and touch sensor pins as output and input, respectively
21
22
23
24
25
● Loop Function:
○ Lines 64-203: This function runs repeatedly:
i. Calls the fix() function to draw fixed elements on the TFT display (if used)
ii. Loops through a range of servo motor positions (80 degrees to 10 degrees
and back):
● Calculates the distance using the calculateDistance() function and prints
it to the serial monitor for debugging
● Maps the servo motor position to a range suitable for controlling the
26
display elements (if used)
● Sets the servo motor position based on the mapped value
iii. Object Detection and Display:
● If the distance is less than 20 cm (adjustable threshold), it indicates an
object is detected:
○ Draws a line on the TFT display (if used) representing the
object's direction based on the current servo motor position.
○ Displays the distance and angle on the LCD.
● Otherwise, it displays "NOTHING IN RANGE" on the LCD.
iv. TFT Display Graphics:
● Draws a line representing the current position on the TFT display.
● Draws background lines and labels for the scan area.
● Displays the distance and angle values on the TFT display.
v. Laser Activation:
● If the distance is less than or equal to 10 cm (adjustable threshold), the
laser module is activated by setting the laserPin to HIGH.
vi. Touch Sensor Integration:
● The code checks the touch sensor state using digitalRead(ctsPin).
● If the distance is less than or equal to 5 cm (adjustable threshold) and
the touch sensor is pressed (reading HIGH), the laser is activated for a
short duration (100ms on, 100ms off) to simulate a laser attack. The
program prints to the serial indicating if the touch sensor is on or off.
27
Our Research
(A) Using the SD Card Module and external speakers
This task explores playing MP3 audio files on an Arduino microcontroller based on the
proximity of an object detected using a sensor.
Playing audio on an Arduino can enhance user experience in various projects. However,
Arduino's limitations make directly decoding MP3 files challenging. This project investigates
alternative methods to achieve conditional MP3 playback based on object detection
distance.
Theoretical Background
● SD Card Module: An SD card module allows the Arduino to access data stored on an
SD card. Communication typically occurs through SPI (Serial Peripheral Interface).
● Speaker for Audio Output - The external speaker needs to be connected to the
Arduino with proper impedance matching to avoid damaging the speaker or the
Arduino board and to provide audio output.
● SD Card Library: Libraries like "SPI.h" and "SD.h" facilitate communication with the
SD card module. These libraries allow reading files, accessing directories, and
managing data transfer.
● Object Detection and Distance Measurement: Ultrasonic sensors or infrared sensors
can be used for object detection. Arduino calculates distance based on the sensor's
response time.
● Conditional Playback: Use an if statement or similar to check the measured distance.
Only when the distance falls within a specific range will the code trigger the MP3
playback.
The MP3 playback would include a set of phrases that would play when specific
conditions of distance were met.These were synthesized using text to speech tools and
28
the resulting output was pitched down using a Digital Audio Workstation to give a
more realistic feel.
Implementation
The code development involved:
1. Library Installation: Installing libraries for SD card communication ("SPI.h" and "SD.h")
and the specific MP3 player module library.
2. Code Development: The code includes:
○ Initialization of the SD card module and MP3 player module in the setup()
function.
○ A loop in the loop() function to:
➢ Read distance data from the object detection sensor.
➢ Check the distance value using an if statement.
➢ If the distance is within the desired range, access the MP3 file on the SD
card and send a "play" command to the MP3 player module.
3. Speaker Connection: A resistor is used to limit the current flowing to the speaker and
prevent damage.
● Connect a resistor in series with the positive (+) lead of the speaker.
● Connect the resistor-speaker combination to an analog output pin of the
Arduino (e.g., pin 9).
● The negative (-) lead of the speaker connects to the Arduino's ground pin (GND).
● An audio amplification module could also be used to enhance the volume
output of the speaker
29
Testing
● Hardware Testing: Verified connections, tested SD card communication with a simple
arduino example file, tested MP3 player functionality, and validated object detection
sensor readings with known distances.
● Speaker Testing - Imported a set of frequencies that could be easily played by the
speaker without the use of an external SD Card. These sound frequencies were
basically modified sine waves and could be played without any complex hardware
● Code Testing: Uploaded the code to the Arduino, placed objects at various distances to
confirm object detection and conditional MP3 playback functionality. Tested different
MP3 files stored on the SD card.
Conclusions
● Arduino's limited resources can restrict complex functionalities.
● Direct MP3 decoding on Arduino is not feasible without using a DAC Converter.
● Pre-converting MP3 to WAV reduces audio quality, and both approaches have
trade-offs between storage space and complexity.
(B) Using python integration and internal speakers
This project explores the integration of Python and Arduino for real-time audio feedback
based on sensor data. The idea is to leverage a sensor (potentially a laser sensor) connected
to the Arduino to detect objects or specific events. The Arduino would then transmit this
information (likely distance data) to a Python script running on a laptop. The Python script,
upon receiving the data, would trigger the playback of predefined audio cues using the
Pygame library.
Theoretical Background
● Real-time Audio Feedback: Provides auditory information based on sensor readings,
enhancing user awareness or triggering specific alerts.
● Flexibility: The Python script can be easily modified to play different audio cues based
on varying data ranges or sensor readings.
30
● Visual Integration (Future Exploration): The concept can be extended to include visual
feedback on the laptop screen alongside the audio cues, creating a more
comprehensive notification system.
Implementation
While the Python code provides a framework for the integration, the actual implementation
requires additional steps:
Arduino Code: Writing Arduino code to interface with the laser sensor. This code should
trigger a serial transmission whenever the laser is activated and include the measured
distance in the transmitted data.
Serial Communication: Ensure proper serial communication is established between the
Arduino and the laptop using the specified serial port (COM5 in this code).
The provided Python code outlines the following functionalities:
● Serial Communication: The serial library establishes communication with the Arduino.
● Scheduled Data Acquisition: The schedule library schedules the main_function to run
every second, ensuring regular data retrieval from the Arduino.
● Data Processing: The main_function reads data from the serial port, converts it to an
integer (assuming distance data), and triggers audio playback based on predefined
distance thresholds.
● Audio Playback: Pygame's mixer module plays different audio files ("authorise.mp3",
"entrance.mp3") based on the received distance value.
Conclusions
This concept demonstrates the potential of combining Arduino and Python for creating
interactive projects with real-time audio feedback. The provided Python code serves as a
starting point, highlighting the communication and data processing aspects. By
implementing the missing Arduino code and ensuring proper serial communication, you can
turn this into a fully functional system for providing audio cues based on sensor data.
31
32
Future Prospects
The provided Arduino code offers a solid foundation for a basic radar system. Here are some
ideas to enhance its functionality and explore more advanced features:
1. Multiple Ultrasonic Sensors:
Integrate multiple ultrasonic sensors positioned at different angles to create a wider scan
area or even a 360-degree coverage.
The code can be modified to handle data from multiple sensors, calculating the object's
direction based on the activated sensor.
2. Servo Motor Speed Control:
Currently, the code sweeps the servo motor at a constant speed.
Implement speed control to adjust the scan rate based on your needs.
A slower scan might provide more precise measurements, while a faster scan can offer a
quicker overview of the environment.
3. Object Tracking:
If your object consistently reflects sound waves, you can attempt to track its movement.
Store previous distance and angle readings and compare them with new data to estimate the
object's trajectory.
4. Data Logging and Visualization:
Modify the code to log distance and angle data over time to a microSD card or transmit it
wirelessly for further analysis.
This data can be visualized on a computer screen using tools like Python's libraries (e.g.,
matplotlib) to create detailed plots or heatmaps of the scanned area.
5. Integration with External Systems:
Connect your Arduino radar system to other devices like microcontrollers or computers.
33
This allows for more complex control logic, data processing, and integration with other
projects (e.g., triggering alarms or controlling robots based on detected objects).
6. User Interface Enhancements:
If using a TFT display, create a user interface that allows for interactive control of the system.
Implement buttons or menus to adjust scan parameters, display modes, or activate
additional features.
7. Machine Learning Integration (Advanced):
Explore integrating machine learning algorithms to improve object classification.
Train the system to recognize different types of objects based on their distance, angle, and
even sound signature (advanced analysis of the echo wave).
8. Advanced Signal Processing (Advanced):
For more robust object detection, delve into advanced signal processing techniques.
This might involve filtering specific frequencies or analyzing the shape of the echo wave to
differentiate between objects and noise.
34
Conclusion
This Arduino radar project demonstrates the power of combining readily available
components to create a functional object detection system. The code provides a solid
foundation for building a basic radar, capable of scanning its surroundings and detecting
objects within a specified range.
We explored various functionalities, including distance measurement, object detection with
visual and audio feedback (through the LCD and laser activation), and the importance of
calibration for accurate results. The project can be further enhanced by incorporating
multiple sensors, advanced data processing, and even machine learning for object
classification.
This project serves as a stepping stone for exploring more complex applications like obstacle
avoidance for robots, security systems with object tracking, or even educational tools for
teaching principles of sonar and radar technology. As you delve deeper into electronics and
programming, the possibilities for expanding and customizing this radar system are truly
vast.
35