jhonjorg9
Published © CERN-OHL

Smartphone Controlled Arduino 2WD Robot Car to detect mine b

My research is about developing a robot to find mines bombs, it is called (Smartphone Controlled Arduino 2WD Robot Car to detect mine bomb)

IntermediateFull instructions provided680
Smartphone Controlled Arduino 2WD Robot Car to detect mine b

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Capacitive Proximity Sensor, M30
Capacitive Proximity Sensor, M30
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
HC-06 Bluetooth Module
×1
DC motor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Development Board, Motor Control Shield
Development Board, Motor Control Shield
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE
Android Studio
Android Studio

Story

Read more

Schematics

untitled_PP3tUO7TMn.png

Code

test_motor_bluetooth_servo_obsticalSensor.ino

Arduino
#include <AFMotor.h> //for motor sheild
#include <Servo.h> // for servo motor
#include <NewPing.h> //for obstical sensor
#include <TinyGPS++.h>
#include <SoftwareSerial.h>

SoftwareSerial serial_connection(12, 11); //RX=pin 12, TX=pin 11
TinyGPSPlus gps;
#define TRIG_PIN A2 
#define ECHO_PIN A4 
#define MAX_DISTANCE 100

//motors
 AF_DCMotor motor1(3);
 AF_DCMotor motor2(2);

 //obstical sensor
 NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);
int distance = 0;

//metal sensor
float metalDetected;
int monitoring;
int metalDetection = 0;

 //servo motor
Servo servo;               
int servo_position =0 ;
int pos=0;

//test
int ledPin = 13; 
int state = 0;
int flag = 0; 
 
void setup() {
 // GPS();
  
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 pinMode(8,OUTPUT);// for speaker
 pinMode(5,OUTPUT);// for carLeds
 pinMode(7,OUTPUT);// for carLeds
 servo.attach (10);// Define the servo signal pins
 Serial.begin(9600); // Default connection rate for my BT module
 Serial.println("robot is srtarted");
 serial_connection.begin(9600);//This opens up communications to the GPS
 
  Serial.println("GPS is srtarted");
  }

int readPing() { //it is used for ultrasonic obstical sensor
 delay(70);
 int cm = sonar.ping_cm();
 if(cm==0)
 {
 cm = 250;
 }
 return cm;
}
 
void loop() {
int last_servo_position=0;
distance =  readPing();


 if(Serial.available() > 0){
 state = Serial.read();
 Serial.write(state);
 flag=0;
 }

//motor shield
 if (state == 's') {
 motor1.setSpeed(0);
 motor2.setSpeed(0);
if(pos !=last_servo_position) {
  servo.write(pos);
  //last_servo_position = pos;
  servo.detach();
}
 
 if(flag == 0){
 Serial.println("state: off");
 flag = 1;
 }
 }

 else if (state == 'w') { //forward
     motor2.run(FORWARD);
     motor2.setSpeed(255);
 if(flag == 0){
 Serial.println("state: on");
 flag = 1;
 }
 }
  else if (state == 'x') { //back
     motor2.run(BACKWARD);
     motor2.setSpeed(255);
 if(flag == 0){
 Serial.println("state: on");
 flag = 1;
 }
 }
  else if (state == 'd') { // left
     motor1.run(FORWARD);
     motor1.setSpeed(255);
 if(flag == 0){
 Serial.println("Left: on");
 flag = 1;
 }
 }
  else if (state == 'a') { //right
     motor1.run(BACKWARD);
     motor1.setSpeed(255);
 if(flag == 0){
 Serial.println("Right: on");
 flag = 1;
 }
 }
 else if (state == 'y') { //stop motor1 for left and right
     motor1.setSpeed(0);
 if(flag == 0){
 Serial.println("motor1: on");
 flag = 1;
 }
 }
 else if (state == 'p') { //stop motor2 for forward and backward
     motor2.setSpeed(0);
 if(flag == 0){
 Serial.println("motor2: of");
 flag = 1;
 }
 }
 else if (state == 'e') { //stop motor 1 to turn right or left
     motor1.setSpeed(0);
 if(flag == 0){
 Serial.println("LED: of");
 flag = 1;
 }
 }
// servo motor
 else if (state == 'q')
 {
  servo.attach (10);
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    servo.write(pos);
    minesFinder();   
    ultrasonicSensor();
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    servo.write(pos);              
    minesFinder();
    ultrasonicSensor();
    delay(15);                       // waits 15ms for the servo to reach the position
  }
 }
 ultrasonicSensor();
minesFinder();
delay(50);
    //Serial.println(monitoring);
    
}






void minesFinder()
{
  monitoring = analogRead(metalDetection);
metalDetected = (float) monitoring*100/1024.0;
 if (monitoring < 250)
{
Serial.println("mine bomb is Detected");
//GPS();
digitalWrite(8,HIGH);
digitalWrite(5,HIGH);
digitalWrite(7,HIGH);
delay(2000);
}
else{
//Serial.println("mine bomb is not Detected");
 digitalWrite(8, LOW);
 digitalWrite(5,LOW );
 digitalWrite(7,LOW );
}
}

void ultrasonicSensor()  // ultrasonic obstical sensor
{
 
  distance =  readPing();
  if(distance<=15)
 {
  state='s';
  // motor1.setSpeed(0);
   //motor2.setSpeed(0);

 Serial.println(distance);
 }
 }

  void stopMotorServo()
  {
    int last_servo_position;
    if(pos !=last_servo_position) {
  servo.write(pos);
  last_servo_position = pos;
}
 }
 void GPS()
 {
  while(serial_connection.available())//While there are characters to come from the GPS
  {
    gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
  }
  if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  {
    //Get the latest info from the gps object which it derived from the data sent by the GPS unit
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.println("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println("");
  }
 }

Credits

jhonjorg9

jhonjorg9

1 project • 0 followers

Comments