Francisc Camillo
Published © GPL3+

Sumobot

The project is designed and built for our Control System Project, this sumobot could be the future of machine learning, and neural nets.

BeginnerWork in progress1.5 hours815
Sumobot

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×4
IR transmitter (generic)
×4
IR receiver (generic)
×4

Software apps and online services

Arduino IDE
Arduino IDE

Code

Sumobot

C/C++
//library declaration
#include <AFMotor.h>
#include <NewPing.h>

//Ultrasonic pin declaration
#define trigPin 46
#define echoPin 44
NewPing sonar(trigPin, echoPin);

//message storage
String message;

//adjustedEnemySensing for enemy sensing
float adjustedEnemySensing = 100;
float adjustedWhiteSensing = 75;

//pin configuration of IR Sensors
int IR_One = A14;
int IR_Two = A12;
int IR_Three = A10;
int IR_Four = A8;

float val, valTwo, valThree, valFour;

AF_DCMotor motorLeft(2, MOTOR12_64KHZ);        // create motor #2, 64KHz pwm, Left Motor
AF_DCMotor motorRight(1, MOTOR12_64KHZ);         // create motor #1, 64KHz pwm, Right Motor

long calculated;
int dels = 500;

void setup() {
  	// put your setup code here, to run once:
	Serial.begin(9600);
	motorLeft.setSpeed(250);
	motorRight.setSpeed(250);
}

void loop() {
  // put your main code here, to run repeatedly:
	motorLeft.run(BACKWARD);
	motorRight.run(FORWARD);
  //delay(2500);
  senseEnemy();
  if (calculated < adjustedEnemySensing){
      motorRight.run(BACKWARD);
      motorLeft.run(BACKWARD);
      delay(500);
    }
	if (analogRead(IR_One) < adjustedWhiteSensing && analogRead(IR_Two) >  adjustedWhiteSensing ){
    Serial.println("1: ");
    Serial.print(analogRead(IR_One));
    Serial.println("2: ");
    Serial.print(analogRead(IR_Two));
    motorLeft.run(FORWARD);
    motorRight.run(BACKWARD);
    delay(dels);
  }

  if (analogRead(IR_Two) < adjustedWhiteSensing && analogRead(IR_One) > adjustedWhiteSensing){
    Serial.println("1: ");
    Serial.print(analogRead(IR_One));
    Serial.println("2: ");
    Serial.print(analogRead(IR_Two));
    motorLeft.run(BACKWARD);
    motorRight.run(BACKWARD);
    delay(dels);
  }

  if (analogRead(IR_One) < adjustedWhiteSensing && analogRead(IR_Two) < adjustedWhiteSensing){
    Serial.println("1: ");
    Serial.print(analogRead(IR_One));
    Serial.println("2: ");
    Serial.print(analogRead(IR_Two));
    motorLeft.run(BACKWARD);
    motorRight.run(RELEASE);
    delay(dels);    
  }

  if (analogRead(IR_Two) < adjustedWhiteSensing && analogRead(IR_Three) > adjustedWhiteSensing){
    Serial.println("2: ");
    Serial.print(analogRead(IR_Two));
    Serial.println("3: ");
    Serial.print(analogRead(IR_Three));
    motorLeft.run(BACKWARD);
    motorRight.run(BACKWARD);
    delay(dels);    
  }

  if (analogRead(IR_Two) > adjustedWhiteSensing && analogRead(IR_Three) < adjustedWhiteSensing){
    Serial.println("2: ");
    Serial.print(analogRead(IR_Two));
    Serial.println("3: ");
    Serial.print(analogRead(IR_Three));
    motorLeft.run(RELEASE);
    motorRight.run(BACKWARD);
    delay(dels);    
  }


  if (analogRead(IR_Two) < adjustedWhiteSensing && analogRead(IR_Three) < adjustedWhiteSensing){
    Serial.println("2: ");
    Serial.print(analogRead(IR_Two));
    Serial.println("3: ");
    Serial.print(analogRead(IR_Three));
    motorLeft.run(BACKWARD);
    motorRight.run(BACKWARD);
    delay(dels);    
  }

  if (analogRead(IR_Three) < adjustedWhiteSensing && analogRead(IR_Four) > adjustedWhiteSensing){
    Serial.println("3: ");
    Serial.print(analogRead(IR_Three));
    Serial.println("4: ");
    Serial.print(analogRead(IR_Four));
    motorLeft.run(RELEASE);
    motorRight.run(BACKWARD);
    delay(dels);    
  }

  if (analogRead(IR_Three) > adjustedWhiteSensing && analogRead(IR_Four) < adjustedWhiteSensing){
    Serial.println("3: ");
    Serial.print(analogRead(IR_Three));
    Serial.println("4: ");
    Serial.print(analogRead(IR_Four));
    motorLeft.run(RELEASE);
    motorRight.run(FORWARD);
    delay(dels);        
  }

  if (analogRead(IR_Three) < adjustedWhiteSensing && analogRead(IR_Four) < adjustedWhiteSensing){
    Serial.println("3: ");
    Serial.print(analogRead(IR_Three));
    Serial.println("4: ");
    Serial.print(analogRead(IR_Four));
    motorLeft.run(RELEASE);
    motorRight.run(FORWARD);
    delay(dels);    
  }

  if (analogRead(IR_One) < adjustedWhiteSensing && analogRead(IR_Four) > adjustedWhiteSensing){
    Serial.println("1: ");
    Serial.print(analogRead(IR_One));
    Serial.println("4: ");
    Serial.print(analogRead(IR_Four));
    motorLeft.run(FORWARD);
    motorRight.run(RELEASE);
    delay(dels);    
  }

  if (analogRead(IR_One) > adjustedWhiteSensing && analogRead(IR_Four) < adjustedWhiteSensing){
    Serial.println("1: ");
    Serial.print(analogRead(IR_One));
    Serial.println("4: ");
    Serial.print(analogRead(IR_Four));
    motorLeft.run(RELEASE);
    motorRight.run(FORWARD);
    delay(dels);    
  }

  if (analogRead(IR_One) < adjustedWhiteSensing && analogRead(IR_Four) < adjustedWhiteSensing){
    Serial.println("1: ");
    Serial.print(analogRead(IR_One));
    Serial.println("4: ");
    Serial.print(analogRead(IR_Four));
    motorLeft.run(FORWARD);
    motorRight.run(FORWARD);
    delay(dels);    
  }

  //else{
  //  motorLeft.run(BACKWARD);
  //  motorRight.run(BACKWARD);
  //}
}

void senseEnemy(){
  long calculated;
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS)
  calculated = uS / US_ROUNDTRIP_CM; // Convert ping time to distance in cm and print result (0 = outside set distance range)
  message = "Ping: ";
  message.concat(calculated);
  Serial.println(message);
}

Credits

Francisc Camillo
10 projects • 17 followers
Computer Engineering Student with Passionate Advocacy in Creating world changing hardware and software applications
Contact

Comments

Please log in or sign up to comment.