top of page
Writer's pictureRamesh G

Radar Monitor using Ultrasonic sensor


In this tutorial we are learn to finding Object distance and angle (radar monitor) using Ultrasonic sensor and Servo Motor. Radars have long been used for detecting objects far away and mapping them on a display. With a number of military and arial applications radars are widely used these days. This advanced Arduino sonar system can be used to monitor local patch area and can also scan suspicious object. We propose to demonstrate this concept using arduino based radar project. This Arduino sonar project system continuously scans the area at 180 degree angle using Servo motor and the radar provides the angle as well as distance of the object from the source and value sent to OLED display. It makes use of an ultrasonic wave to simulate sonar or radar sweep 180 degree. It is mounted on a Servo motor to create sweep angles and rotate the ultrasonic sensor.


Circuit Diagram

Components Required


Arduino Uno - 1 no

Ultrasonic Sensor HC-SR04 - 1no

Ultrasonic Sensor Mounting Bracket - 1

Servo Motor MG90S - 1no

OLED 0.96 SSD1306 - 4 PIN - 1no



HC-SR04

HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc, Trigger, Echo and Ground respectively. This sensor is a very popular sensor used in many applications where measuring distance or sensing objects are required. The module has two eyes like projects in the front which forms the Ultrasonic transmitter and Receiver. The sensor works with the simple high school formula that

Distance = Speed × Time

Refer more Data sheet Download


OLED SSD1306-I2C 128X64 Display Module 0.96 inch


This is a 0.96 inch Blue-Yellow OLED display module. The display module can be interfaced with any microcontroller using SPI/IIC protocols. It is having a resolution of 128x64. The package includes display board,display, 4 pin male header presoldered to board.


OLED (Organic Light-Emitting Diode) is a self light-emitting technology composed of a thin, multi-layered organic film placed between an anode and cathode. In contrast to LCD technology, OLED does not require a backlight. OLED possesses high application potential for virtually all types of displays and is regarded as the ultimate technology for the next generation of flat-panel displays.

ssd1306

Specifications :

Viewing angle : greater than 160 degrees

Supported platforms : for arduino, 51 series, MSP430 series, STIM32 / 2, SCR chips

Low power consumption : 0.04W during normal operation

Support wide voltage : 3.3V-5V DC

Driver IC : SSD1306

Communication : IIC, only two I / O ports

No font : The software takes word modulo

Backlight : OLED self light, no backlight

Interface: VCC: 3.3-5V GND: Ground SCL: Serial Clock SDA: Serial

Installing the Arduino Library

Installing SSD1306 OLED Library – Arduino

Download Adafruit_SSD1306_Library , we need to use this library for OLED

Download Adafruit_GFX_Library , we need to use this library for OLED


Follow the next steps to install those libraries.

1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.


2. Type “SSD1306” in the search box and install the Adafruit SSD1306 library version 1.2.9 library from Adafruit.


3. After installing the SSD1306 library from Adafruit GFX version 1.4.13 in the search box and install the library.


4. After installing the libraries, restart your Arduino IDE.


After installing the required libraries, copy the following code to your Arduino IDE.


Subscribe and Download code.


Arduino Code:

#include <SPI.h>

#include <Wire.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>


#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels


// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)//unstroke for yellow+blue OLED // double stroke for Blue OLED

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);


#include <Servo.h>


Servo servo;


const int trig = 2, echo = 3 ;

int pos = 0, distcm = 0;

void setup()

{

Serial.begin(9600);

display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

pinMode(trig, OUTPUT);

pinMode(echo, INPUT);

servo.attach(9);


display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(7,0);

display.clearDisplay();

display.println("DOFBOT PROJECTS");

display.setTextSize(2);

display.setTextColor(WHITE);

display.setCursor(0,10);

display.println("WELCOME");

display.display();

delay(3000);

}


void loop()

{

for (pos = 0; pos <= 180; pos += 1)

{

servo.write(pos);

delay(50);

Serial.println(radar());

display.clearDisplay();

// text display tests

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(0,0);

display.println("RADAR SCANNING..");

display.setTextColor(BLACK, WHITE);

// 'inverted' text

//display.println(3.141592);

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(0,16);

display.print("DISTANCE SERVO");

display.setCursor(0,30);

display.print(" IN CM DEGREE");

display.display();

display.setTextColor(WHITE);

display.setCursor(0,45);

display.setTextSize(2);

display.print(radar());

display.setCursor(90,45);

display.setTextSize(2);

display.print(pos);


// display.println(0xDEADBEEF, HEX);

display.display();

}

for (pos = 180; pos >= 0; pos -= 1)

{

servo.write(pos);

delay(50);

Serial.println(radar());

display.clearDisplay();

// text display tests

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(0,0);

display.println("RADAR SCANNING....");

display.setTextColor(BLACK, WHITE);

// 'inverted' text

//display.println(3.141592);

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(0,16);

display.print("DISTANCE SERVO");

display.setCursor(0,30);

display.print(" IN CM DEGREE");

display.display();

display.setTextColor(WHITE);

display.setCursor(0,45);

display.setTextSize(2);

display.setTextSize(2);

display.print(radar());

display.setCursor(90,45);

display.setTextSize(2);

display.print(pos);

// display.println(0xDEADBEEF, HEX);

display.display();

}

delay(50);

}

long radar(void)

{


digitalWrite(trig, HIGH);

delayMicroseconds(15);

digitalWrite(trig, LOW);

long dur = pulseIn(echo, HIGH);

distcm = dur / 58;

return distcm;

delay(300);


}


After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and Open Serial monitor and see the result in Serial monitor.


Comments


bottom of page