Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
AhmedAzouz
Published © LGPL

How to Make Arduino Sumo Robot

A self-controlled robot with specific dimensions and features. It is also designed in hostile shapes which qualify it to fight.

BeginnerFull instructions provided6 hours53,345
How to Make Arduino Sumo Robot

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
any Arduino version can be applied
×1
DC Motor, 12 V
DC Motor, 12 V
there are two designed
×2
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Sumo Robot Laser Cut

sketch-up file for the robot design

Schematics

Motors wiring

Code

Arduino Code

Arduino
/*

 by ahmed Azouz
  https://www.instructables.com/id/How-to-Make-Ardu...

 Download the lib from here first
  https://github.com/ErickSimoes/Ultrasonic/blob/ma...

*/
#include Ultrasonic.h

Ultrasonic ultrasonic(4,3);

const int IN1=5;
const int IN2=6;
const int IN3=9;
const int IN4=10;
#define IR_sensor_front A0 // front sensor
#define IR_sensor_back A1 // rear senson
int distance ;

void setup() 
{
Serial.begin(9600);
delay (5000); // as per sumo compat roles
}
void loop()
{
  
 int IR_front = analogRead(IR_sensor_front);
 int IR_back = analogRead(IR_sensor_back);
 distance = ultrasonic.read();
 ROTATE(200); // start rotete if (distance < 20){
    Stop();
    while (distance < 20 ) {
    FORWARD(255); 
    distance = ultrasonic.read();
    IR_front = analogRead(IR_sensor_front);
    IR_back = analogRead(IR_sensor_back);
    if ( IR_front > 650 || IR_back > 650 ) { break;}
    delay(10); }
  
  
 if (IR_front < 650 )  // < 650 means white line
   {
   Stop();
   delay (50);
   BACKWARD(255);
   delay (500);
   } 
   
 if (IR_back < 650 )  //
   {
   Stop();
   delay (50);
   FORWARD(255);
   delay (500);
   }
   
   /* ----------- debugging ----------------
  Serial.print(ultrasonic.Ranging(CM));
  Serial.println("cm");
  Serial.println("IR front :");
  Serial.println(IR_front); 
  Serial.println("IR back :");
  Serial.println(IR_back);  
*/ 

} //--------------------------------------------
void FORWARD (int Speed){
  //When we want to let Motor To move forward,
  // just void this part on the loop section .
  analogWrite(IN1,Speed);
  analogWrite(IN2,0);
  analogWrite(IN3,0);
  analogWrite(IN4,Speed);
}//--------------------------------------------
void BACKWARD (int Speed){
  //When we want to let Motor To move forward,
  // just void this part on the loop section .
  analogWrite(IN1,0);
  analogWrite(IN2,Speed);
  analogWrite(IN3,Speed);
  analogWrite(IN4,0);
}//--------------------------------------------
void ROTATE (int Speed)
{
  //When we want to let Motor To Rotate ,
  // just void this part on the loop section .
  analogWrite(IN1,Speed);
  analogWrite(IN2,0);
  analogWrite(IN3,Speed);
  analogWrite(IN4,0);
}//--------------------------------------------
void Stop(){
  //When we want to  Motor To stop ,
  // just void this part on the loop section .
  analogWrite(IN1,0);
  analogWrite(IN2,0);
  analogWrite(IN3,0);
  analogWrite(IN4,0);
}

Credits

AhmedAzouz
10 projects • 156 followers
High qualified software engineer, Creativity and Technology have always been a big part of my life.

Comments