Project in progress # Beach cleaning Bot © GPL3+

A simple 4WD robot capable of picking up garbage littered on the beach.

• 551 views
• 0 respects

## Components and supplies

The beach cleaning bot was a result of a 27 hour hackathon conducted in college for which we secured third place. A lot of problems exist because of excessive garbage and waste in our beaches. It is extremely harmful for various animals both on the shore and in the sea. Eventually since all this debris is washed into the sea, it pollutes that as well. This manages to affect us indirectly as this garbage is eaten by fish which are consumed by man.

Our beach cleaning bot is a primitive prototype to combat this menace and threat by automating the same. The project needs a ton of improvements, modifications and upgradations but this is the basic and general idea.

### How our system works

Step1-Aerial picture of the beach using a drone or other Unmanned Aerial Vehicles.

The first and foremost step would be to obtain an aerial view of the beach. This is important as it tells us where obstacles are, where the garbage is, where to start and where to end.

Step 2-Image processing of the aerial view and extracting information.

Next we perform image processing on the picture obtained to extract all the useful information from it. Now I will be honest- I have not worked with image processing before and this was my first time. So I simplified the image processing by a lot by making the aerial view myself using Microsoft Paint.

Here the yellow region represents sand and free region for the robot to move along. Red represents garbage. Blue is the start and green is the end. I know its not the perfect image or even realistic at that but its a start. Lets assume this is the aerial view of the beach taken by the drone.

Now the code below, written in python using OpenCV converts the image into a 8*8 2D array, where start is represented by 2, end is represented by 4, free movable space by 0, obstacles by 1 and garbage by 3.

``import cv2import numpy as npimg=cv2.imread('C:\\Users\\Me\\Desktop\\imagineer beach.jpg')cv2.imshow('image',img)d = img.shapeprint (d)z=0arr= np.zeros([8, 8], dtype = int)nitk=[]for i in range(18,278,37):    for j in range(18,278,37):        nitk.append(img[i][j])####print(img[i][j])print(nitk)k=0for i in range(0,8):    for j in range(0,8):        b=nitk[k]        g=nitk[k]        r=nitk[k]        if(b>220 and (g>155 and g<170) and r<10):            arr[i][j]=2            #print("blue")        elif(b<10 and (g>230 and g<255) and r>230):            arr[i][j]=0            #print("yellow")        elif(b<10 and (g<10) and r<10):            arr[i][j]=1            #print("black")        elif((b>30 and b<50) and g<32 and r>230):            arr[i][j]=3            #print("red")        elif(b<80 and (g>170 and g<185) and r<40):            arr[i][j]=4        k=k+1print(arr)cv2.waitKey(0)cv2.destroyAllWindows()``

After this we obtain a 2D array like this.

Now its time to find the shortest path from start to end, without going over obstacles and ideally through garbage. For this we use the Grass fire algorithm

``s=[0,0]e=[7,7]i=-1h=0x=sy=sprint(arr)if(x+1<8 and arr[x+1][y]!=1 and arr[x+1][y]==0):    arr[x+1][y]=iif(y+1<8 and arr[x][y+1]!=1 and arr[x][y+1]==0):    arr[x][y+1]=iif(x-1>-1 and arr[x-1][y]!=1 and arr[x-1][y]==0):    arr[x+1][y]=iif(y-1>-1 and arr[x][y-1]!=1 and arr[x][y-1]==0):    arr[x][y-1]=iprint(arr)while(arr>=0 and arr>=0):    b=np.where(arr==i)    j=len(b)    k=0    while(k<j):        x=b[k]        y=b[k]        if(x+1<8 and arr[x+1][y]!=1 and arr[x+1][y]==0):            arr[x+1][y]=i-1        if(y+1<8 and arr[x][y+1]!=1 and arr[x][y+1]==0):            arr[x][y+1]=i-1        if(x-1>-1 and arr[x-1][y]!=1 and arr[x-1][y]==0):            arr[x+1][y]=i-1        if(y-1>-1 and arr[x][y-1]!=1 and arr[x][y-1]==0):            arr[x][y-1]=i-1        k+=1    print(arr)    print(" ")    i-=1``

Finally we must now extract the shortest path from start to end. I have not written the code to pass the garbage till now. Just from start to end(I will update the code with garbage route soon).

Now we need to extract coordinates of where the bot has to go to maneuver through the beach.

``m=0n=0f=0barr= np.zeros([18, 3], dtype = int)mini=np.amin(arr)result=np.where(arr == mini)i=resultj=resultp=iq=jprint(i,j)barr=minibarr=pbarr=qm=1n=0x=1while((i!=1 and j!=0) or (i!=0 and j!=1)):    if(arr[i-1][j]==mini+x and i>0):        i-=1        barr[m][n]=mini+x        barr[m][n+1]=i        barr[m][n+2]=j    elif(arr[i][j-1]==mini+x and j>0):        j-=1        barr[m][n]=mini+x        barr[m][n+1]=i        barr[m][n+2]=j    elif(arr[i+1][j]==mini+x and i<6 ):        i+=1        barr[m][n]=mini+x        barr[m][n+1]=i        barr[m][n+2]=j    elif(arr[i][j+1]==mini+x and j<6):        j+=1        barr[m][n]=mini+x        barr[m][n+1]=i        barr[m][n+2]=j        m+=1    x+=1    f+=1    print(barr)#print(arr)#print(barr)print(type(barr))``

Next get them into a CSV file so that they can be fed to the bot.(I am still working on that)

FInally, a set of pictures-

## Code

##### Arduino codeArduino
```#include<AFMotor.h>
#include <Servo.h>
//#include<Wire.h>
#define trigPin1 12
#define echoPin1 10
#define trigPin2 8
#define echoPin2 6
#define trigPin3 4
#define echoPin3 2
//Servo myservo;
int pos = 0,f=0;
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);
void setup() {
//Wire.begin();
Serial.begin(9600);

motor1.setSpeed(200);
motor2.setSpeed(200);
motor3.setSpeed(200);
motor4.setSpeed(200);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
//myservo.attach(9);
}

void loop() {

long duration1, distance1;
digitalWrite(trigPin1, LOW);  // Added this line
digitalWrite(trigPin1, HIGH);
//  delayMicroseconds(1000); - Removed this line
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = (duration1/2) / 29.1;

long duration2, distance2;
digitalWrite(trigPin2, LOW);  // Added this line
digitalWrite(trigPin2, HIGH);
//  delayMicroseconds(1000); - Removed this line
digitalWrite(trigPin2, LOW);
duration2 = pulseIn(echoPin2, HIGH);
distance2 = (duration2/2) / 29.1;

long duration3, distance3;
digitalWrite(trigPin3, LOW);  // Added this line
digitalWrite(trigPin3, HIGH);
//  delayMicroseconds(1000); - Removed this line
digitalWrite(trigPin3, LOW);
duration3 = pulseIn(echoPin3, HIGH);
distance3 = (duration3/2) / 29.1;
Serial.print(distance1);
Serial.print(",");
Serial.print(distance2);
Serial.print(",");
Serial.println(distance3);
if(distance1>15 && distance2>15 && distance3>15)//In the event of no obstacle being detected by any of the sensors
{
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
else if(distance1<15 && distance2>15 && distance3>15 )//If the centre sensor is near an obstacle
{
motor1.run(BACKWARD);//First move back for 1 second
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(1000);
motor1.run(FORWARD);//Then turn left for 1.5 seconds
motor2.run(RELEASE);
motor3.run(FORWARD);
motor4.run(RELEASE);
delay(1500);
}
else if(distance1>15 && distance2<15 && distance3>15)//If the left sensor is near an obstacle
{
motor1.run(BACKWARD);//First move back for 1 second
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(1000);
motor2.run(FORWARD);//Then turn right for 1.5 seconds
motor1.run(RELEASE);
motor4.run(FORWARD);
motor3.run(RELEASE);
delay(1500);
}
else if(distance1<15 && distance2>15 && distance3>15)//If the middle sensor is near an obstacle
{
motor1.run(BACKWARD);//First move back for 2 seconds
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(2000);
motor2.run(RELEASE);//Then turn right(arbitrary,you could go left too)
motor1.run(FORWARD);//For 1.5 seconds
motor3.run(FORWARD);
motor4.run(RELEASE);
delay(1500);

}
else//If its none of the above,just move backwards for 2 seconds
{
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(2000);
}
delay(100);

}
```

#### Published on

May 2, 2020
See similar projects
you might like

#### Trash Built BT Line Drawing Bot - My Bot

Project tutorial by jegatheesan

• 2,106 views
• 9 respects

#### Big Track Rover "ENHANCED EDITION" Obstacle Avoidance Bot

Project showcase by Sam

• 2,350 views
• 1 comment
• 3 respects

#### Bluetooth Controlled Bot (Using Adafruit L293D Motor Driver)

Project showcase by Chandran N

• 14,562 views
• 18 respects

#### Obstacle Avoidance Bot Using IR Sensors

Project tutorial by Chandran N

• 11,427 views
• 1 comment
• 13 respects

#### Home Safety Bot

Project showcase by HomeSafety

• 5,621 views