Visitors

Sunday, July 9, 2017

Arduino Radar System using Processing Android App and Ultrasonic Sensor





This is an interesting project in which we explore the power of an Arduino and Android to create a Surveillance device which uses Arduino and Ultra Sonic Sensor to broadcast the information to a mobile application (Android) using Bluetooth.


Safety and Security has been our primary concern since ages. Installing a security camera that has night mode with tilt and pan option will burn a big hole on our pockets. Hence let us make an economic device which does almost the same but without any video features.
This device senses objects with the help of Ultrasonic Sensor and hence can work even during night times. Also we are mounting the US (Ultra Sonic) sensor over a servo motor, this servo motor can be either be set to rotate automatically to scan the area or can be rotated manually using our Mobile app, so that we can focus the ultrasonic sensor in our required direction and sense the objects present over there. All the information sensed by the US sensor will be broadcasted to our Smart phone using Bluetooth Module (HC-05). So it will work like a Sonar or a Radar.


Requirements:


Hardware:
  • A +5V power supply ( I am using my Arduino (another) board for power supply) 
  • Arduino Mega (You can use anything from pro mini to Yun)
  • Servo Motor (any rating)
  • Bluetooth Module (HC-05)
  • Ultra Sonic Sensor (HC-SR04)
  • Breadboard (not mandatory)
  • Connecting wires
  • Android mobile
  • Computer for programming


Software:
  1. Arduino Software
  2. Android SDK
  3. Processing Android (To create mobile application)



Arduino Hardware part and Circuit Diagram:


This project involves a lot of components like the Servo Motor, Bluetooth Module, Ultrasonic Sensor etc. Hence if you are an absolute beginner then it would be recommended to start with some basic tutorial which involves these components and then come back here. Check out our various projects on Servo MotorBluetooth Module and Ultrasonic Sensor here.
All components are not powered by the Arduino itself because, the servo motor, Bluetooth module and US sensor altogether draws a lot of current which the Arduino will not be able to source. Hence it is strictly advisable to use any external +5V supply. If you do not have an external +5V supply at your reach, you can share the components between two Arduino boards as I have done. I have connected the Servos power rails to another Arduino board (red colour) and connected the Bluetooth module HC-05 and Ultrasonic sensor HC-SR04 to the Arduino mega. CAUTION: Powering up all these modules using one Arduino board will fry up the Arduino voltage regulator.

Connection diagram for this Arduino Based Sonar Project is given below:




Android Mobile Application for Ultrasonic Radar:


If you do not want to make your own application and instead just want to install the same application used in this tutorial you can follow the steps below.

1. You can directly download the APK file from the below link. This APK file is made for Android version 4.4.2 and above (Kitkat an above). Extract the APK file from the zip file.
2. Transfer the .Apk file from your computer to your mobile phone.
3. Enable installing application from Unknown sources in your android settings.
4. Install the application.



Code: 

 //*Include the required header files**//

#include <Servo.h>
#include <SoftwareSerial.h>
//__End of including headers__//

//**Defining pins for US sensor**//

#define trigPin 4
#define echoPin 5
///__End of defaniton__//

SoftwareSerial Blueboy(10, 11); //Naming our Bluetooth module as Blueboy and defiing the RX and TX pins as 10 and 11

Servo servo;  //Initializing a servo object called servo

//**Global variabel declarations**//

int BluetoothData; 
int posc = 0; 
int flag=10;
//__End of global variable declartion__//


void setup() //Runce only once
{
  servo.attach(9); //Servo is connected to pin 9
  pinMode(trigPin, OUTPUT); //trigpin of US sensor is output
  pinMode(echoPin, INPUT);  //echopin of US sensor is Input
  Serial.begin(38400); //Serial monitor is started at 38400 baud rate for debugging
  Blueboy.begin(9600); //Bluetooth module works at 9600 baudrate
  Blueboy.println("Blueboy is active"); //Conformation from Bluetooth
}

void loop()  //The infinite loop

{

//**Program to start or stop the Survilance devide**//

   if (Blueboy.available())
{
Serial.println("Incoming");   //for debugging
BluetoothData=Blueboy.read(); //read data from bluetooth  
Serial.println(BluetoothData); //for debugging

   if (BluetoothData == 'p') //if the mobile app has sent a 'p'

   {
   flag=0; //play the device in auto mode
   }
   if (BluetoothData == 's') //if the mobile app has sent a 's'
   {
   flag=1; //stop the device and enter manual mode
   } 
Serial.println(flag); //for debugging
}

if (flag==0)

servofun(); //Servo sweeps on own 
if (flag==1)
manualservo(); //Manual sweeping

}

//_End of loop program__//


//**Function for servo to sweep**//

void servofun()
{
  Serial.println("Sweeping"); //for debugging 
  for(posc = 10;posc <= 170;posc++)   // Using 10 to 170 degree is safe than 0 to 180 because some servo might not be operational at extreme angels 
  {                                
    servo.write(posc); // set the position of servo motor
    delay(50);  
  us();    //measure the distance of objects sing the US sensor                
  } 
  
  for(posc = 170;posc >= 10;posc--)   
  {                                
    servo.write(posc);
    delay(50); 
    us();    //measure the distance of objects sing the US sensor             
  } 
  Serial.println ("Scan Complete"); //for debugging
  flag=0;
}
//**End of Servo sweeping function**//


//**Function to control Servo manually**//

void manualservo()
{  
us();

// Get value from user and control the servo

   if (Blueboy.available())
{
BluetoothData=Blueboy.read();
Serial.println(BluetoothData);
  servo.write(BluetoothData);
  Serial.println("Written");
   if (BluetoothData == 'p')
   {
   flag=0;
   }
}
}
//__End of manual control function__//


//**Function to measure the distance**//

void us()
{
 int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1; // Calculates the distance from the sensor
  if (distance<200 && distance >0)
Blueboy.write(distance);       
}
//__End of distance measuring function__//





No comments:

Post a Comment