4. Page | 1
Introduction:
We come across situations where we need to keep a watch over prohibited areas to avoid
trespassing. Now keeping human labor for this purpose is costly and also not reliable for
keeping a watch over an area 24×7. So, for this purpose an ultrasonic radar project for
unauthorized human/animal or object detection system. The system can monitor an area of
limited range and alerts authorities.
For this purpose, we use a microcontroller circuit that is connected to an ultrasonic sensor
mounted on a servo motor for monitoring. We also interface an LCD screen (Laptop Monitor)
for monitoring the detection status. The radar keeps monitoring the environment checking
the ultrasonic sensor echo. As soon as an object is detected the data of detection is processed
and sent to authorities with an alert of where exactly the object was detected. Thus, ultrasonic
radar proves to be a very useful system for 24×7 monitoring of a particular area/region.
In this lab project, we tried to implement an ultrasonic radar. We did not use the conventional
easier methods, rather we used ATMEGA 328 microcontroller for programming and
instruction sets.
5. Page | 2
Components
● ATMEGA 328P
● Sonar Sensor (HC-SR04)
● Servo Motor (SG90)
● Breadboard
● FTDI FT 232RL USB to Serial Adapter
● 16 MHz Crystal Oscillator
● Capacitors (22pF)
● Resistance
● Push Button
● Jumper Wires
SIMPLE BRIEF TO THE USED COMPONENTS:
ATMEGA 328P
ATMEGA328P is high performance, low power controller from Microchip. ATMEGA328P is
an 8-bit microcontroller based on AVR RISC architecture. It is the most popular of all AVR
controllers as it is used in ARDUINO boards.
6. Page | 3
Where to Use ATMEGA328P
Although we have many controllers ATMEGA328P is most popular of all because of its
features and cost. ARDUINO boards are also developed on this controller because of its
features.
● With program memory of 32 Kbytes ATMEGA328P applications are many.
● With various POWER SAVING modes, it can work on MOBILE EMBEDDED
SYSTEMS.
● With Watchdog timer to reset under error it can be used on systems with minimal
human interference.
● With advanced RISC architecture, the controller executes programs quickly.
● Also, with in chip temperature sensor the controller can be used at extreme
temperatures.
These all features add together promoting ATMEGA328P further.
How to Use ATMEGA328P
ATMEGA328 is used similar to any other controller. All there to do is programming.
Controller simply executes the program provided by us at any instant. Without programming
controller simply stays put without doing anything.
As said, first we need to program the controller and that is done by writing the appropriate
program file in the ATMEGA328P FLASH memory. After dumping this program code, the
controller executes this code and provides appropriate response.
Entire process of using an ATMEGA328P goes like this:
⮚ List the functions to be executed by controller.
⮚ Write the functions in programming language in IDE programs.
⮚ ATMEGA328P programming can also be done in ARDUINO IDE.
⮚ After writing the program, compile it to eliminate errors.
⮚ Make the IDE generate HEX file for the written program after compiling.
⮚ This HEX file contains the machine code which should be written in controller flash
memory.
⮚ Choose the programming device (usually SPI programmer made for AVR controllers)
which establishes communication between PC and ATMEGA328. It can also be
programmed using ARDUINO UNO board.
⮚ Run the programmer software and choose the appropriate hex file.
⮚ Burn the HEX file of written program in ATMEGA328P flash memory using this
program.
⮚ Disconnect the programmer, connect the appropriate peripherals for the controller
and get the system started
How to Use ATMega328P using Arduino
Since ATmega328P is used in Arduino Uno and Arduino nano boards, an Arduino Uno board
can be directly replaced by a ATMega328P chip. For that first the Arduino bootloader needs
to be installed into the chip. This IC with bootloader can be placed on Arduino Uno board and
burn the program into it. Once Arduino program is burnt into the IC, it can be removed and
used in place of Arduino board, along with a Crystal oscillator and other components as
7. Page | 4
required for the project. Below is the pin mapping between Arduino Uno and ATmega328P
chip.
Applications
There are hundreds of applications for ATMEGA328P:
● Used in ARDUINO UNO, ARDUINO NANO and ARDUINO MICRO boards.
● Industrial control systems.
● SMPS and Power Regulation systems.
● Digital data processing.
● Analog signal measuring and manipulations.
● Embedded systems like coffee machine, vending machine.
● Motor control systems.
● Display units.
● Peripheral Interface system.
Sonar Sensor HC-SR04
The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It
offers excellent non-contact range detection with high accuracy and stable readings in an
easy-to-use package. It comes complete with ultrasonic transmitter and receiver modules.
8. Page | 5
Features
Here’s a list of some of the HC-SR04 ultrasonic sensor features and specs:
● Power Supply :+5V DC
● Quiescent Current : <2mA
● Working Current: 15mA
● Effectual Angle: <15°
● Ranging Distance : 2cm – 400 cm/1″ – 13ft
● Resolution : 0.3 cm
● Measuring Angle: 30 degree
● Trigger Input Pulse width: 10uS
● Dimension: 45mm x 20mm x 15mm
How Does it Work
The ultrasonic sensor uses sonar to determine the distance to an object. Here’s what
happens:
1. The transmitter (trig pin) sends a signal: a high-frequency sound. 40Khz to be
precise. The signal duration is 10𝝁s.
2. When the signal finds an object, it is reflected and…
3. … the transmitter (echo pin) receives it.
9. Page | 6
The time between the transmission and reception of the signal allows us to calculate the
distance to an object. This is possible because we know the sound’s velocity in the air.
Pin-out
● VCC: +5VDC
● Trig : Trigger (INPUT)
● Echo: Echo (OUTPUT)
● GND: Gournd
Servo Motor SG-90
Features
● Operating Voltage is +5V typically
● Torque: 2.5kg/cm
● Operating speed is 0.1s/60°
● Gear Type: Plastic
● Rotation : 0°-180°
10. Page | 7
● Weight of motor : 9gm
How to use
After selecting the right Servo motor for the project, comes the question how to use it. As we
know there are three wires coming out of this motor. To make this motor rotate, we have to
power the motor with +5V using the Red and Brown wire and send PWM signals to the
Orange color wire. Hence, we need something that could generate PWM signals to make this
motor work, this something could be anything like a 555 Timer or other Microcontroller
platforms like Arduino, PIC, ARM or even a microprocessor like Raspberry Pie. Let us look
at this picture to understand the rotation clearly.
From the picture we can understand that the PWM signal produced should have a frequency
of 50Hz that is the PWM period should be 20ms. Out of which the On-Time can vary from
1ms to 2ms. So, when the on-time is 1ms the motor will be in 0° and when 1.5ms the motor
will be 90°, similarly when it is 2ms it will be 180°. So, by varying the on-time from 1ms to
2ms the motor can be controlled from 0° to 180°
Applications
● Used as actuators in many robots like Biped Robot, Hexapod, robotic
arm etc.
● Commonly used for steering system in RC toys
● Robots where position control is required without feedback
● Less weight hence used in multi DOF robots like humanoid robots
11. Page | 8
16 MHz Crystal Oscillator
Crystal oscillator, also called plug-ins passive crystal, is a passive component with
Piezoelectricity; When added voltage to a quartz crystal piece, its physical appearance will
change, providing stable and precise frequency as a result. A resonator could not vibrate itself
without clock signal in circuit system.
A crystal oscillator, particularly one using a quartz crystal, works by distorting the crystal with
an electric field, when voltage is applied to an electrode near or on the crystal. This property
is known as electrostriction or inverse piezoelectricity. When the field is removed, the quartz
- which oscillates in a precise frequency - generates an electric field as it returns to its previous
shape, and this can generate a voltage. The result is that a quartz crystal behaves like an RLC
circuit, but with a much higher Q.
Quartz crystals are manufactured for frequencies from a few tens of kilohertz to hundreds of
megahertz. More than two billion crystals are manufactured annually. Most are used for
consumer devices such as wristwatches, clocks, radios, computers, and cellphones. Quartz
crystals are also found inside test and measurement equipment, such as counters, signal
generators, and oscilloscopes.
FTDI FT 232RL USB to Serial Adapter
12. Page | 9
The USB to TTL serial adapter is based on the high quality and very popular FTDI FT232RL
chipset and is an excellent way to connect TTL serial devices to a PC through a USB port.
This USB to TTL serial adapter is ideal for many uses, including:
● Programming microprocessors such as ARM, AVR, etc
● Working with computing hardware such as routers and switches
● Serial communication with many devices such as GPS devices
● Serial terminals on devices like the Raspberry Pi
Unlike most USB to TTL serial adapters, this adapter supports both 5V AND 3.3V operation.
The adapter comes with a right-angle connector fitted allowing you to use it straight away. If
anyone needs to access any of the other inputs or outputs of the FT232RL, all the useful
signals are provided as through-hole solder pads - ideal for use with straight headers into a
breadboard, for example.
● DTR: Data Terminal Ready - an output used for flow control
● RX: Serial data Receive pin
● TX: Serial data Transmit pin
● VCC: Positive voltage output - this is controlled by the jumper. If the jumper is set to
5V, this will provide a 5V output. If the jumper is set to 3.3V, this will provide a 3.3V
output.
● CTS: Clear to Send - an input used for flow control
● GND: Ground or 0V
For most uses,
● RX on this board goes to the TX pin of the device
● TX on this board goes to the RX pin on the device
● GND on this board goes to GND on the device
So, these are the main components used in this project. We also used some regular
components like breadboard, connector wires, capacitors, push button etc.
13. Page | 10
The Project Overview
The following block diagram represents the whole working procedure of this project.
14. Page | 11
Schematic Circuit Diagram
How does it work
The microcontroller sends signal to the servo and rotates it by 1◦
The servo motor rotates the two sonars (Each sonar covers 180◦)
In case of echo, the ATMEGA measures the distance and the angular distance is
measured via the rotation of servo.
These data are sent to computer via a Serial Adapter.
Data are then processed to show output using Processing3 software.
17. Page | 14
Conclusion
Since it was a model project, the Radar’s range is limited to 40-80 cm. For better range and
results more powerful sonar sensors could be used. And in real applications microwave
sensors could be used.
Another drawback of our project is we didn’t consider temperature differences. So, in
different temperatures we will get slightly different results.
Also, our Radar can’t give any idea of objects shape but only the angle and distance. so, there’s
a good scope for improvement but that will require huge amount of image processing which
is out of our course syllabus.
19. Page | 16
Appendix
This is the “Processing” code to show continuous radar output on screen.
import processing.serial.*;
import processing.opengl.*;
import toxi.geom.*;
import toxi.processing.*;
ToxiclibsSupport gfx;
Serial port;
String serialAngle;
String serialDistance1,serialDistance2;
String serialData;
float objectDistance1,objectDistance2;
int radarAngle, radarDistance1, radarDistance2;
int index1=0,index2=0;
//int sz=650,la=600,hl=310,nl=8,na=5,hcm=40;//sz=size,la=last arc distance,hl=highest line
distance,nl=number of line,na=number of arc,hcm= hightest cm
int sz=700,nl=8,na=5,hcm=40;
int la=sz-50;
int hl=la/2+10;
PFont f;
void setup()
{
size (700, 700);
gfx = new ToxiclibsSupport(this);
smooth();