Devices & Components
Arduino Nano
Dual H-Bridge motor drivers L298
DC Motor, 12 V
Ultrasonic Sensor - HC-SR04 (Generic)
9V Battery Clip
9V battery (generic)
Hardware & Tools
Laser cutter (generic)
Software & Tools
Arduino IDE
Project description
Code
Arduino Code
arduino
1/* 2 3 by ahmed Azouz 4 https://www.instructables.com/id/How-to-Make-Ardu... 5 6 Download the lib from here first 7 https://github.com/ErickSimoes/Ultrasonic/blob/ma... 8 9*/ 10#include Ultrasonic.h 11 12Ultrasonic ultrasonic(4,3); 13 14const int IN1=5; 15const int IN2=6; 16const int IN3=9; 17const int IN4=10; 18#define IR_sensor_front A0 // front sensor 19#define IR_sensor_back A1 // rear senson 20int distance ; 21 22void setup() 23{ 24Serial.begin(9600); 25delay (5000); // as per sumo compat roles 26} 27void loop() 28{ 29 30 int IR_front = analogRead(IR_sensor_front); 31 int IR_back = analogRead(IR_sensor_back); 32 distance = ultrasonic.read(); 33 ROTATE(200); // start rotete if (distance < 20){ 34 Stop(); 35 while (distance < 20 ) { 36 FORWARD(255); 37 distance = ultrasonic.read(); 38 IR_front = analogRead(IR_sensor_front); 39 IR_back = analogRead(IR_sensor_back); 40 if ( IR_front > 650 || IR_back > 650 ) { break;} 41 delay(10); } 42 43 44 if (IR_front < 650 ) // < 650 means white line 45 { 46 Stop(); 47 delay (50); 48 BACKWARD(255); 49 delay (500); 50 } 51 52 if (IR_back < 650 ) // 53 { 54 Stop(); 55 delay (50); 56 FORWARD(255); 57 delay (500); 58 } 59 60 /* ----------- debugging ---------------- 61 Serial.print(ultrasonic.Ranging(CM)); 62 Serial.println("cm"); 63 Serial.println("IR front :"); 64 Serial.println(IR_front); 65 Serial.println("IR back :"); 66 Serial.println(IR_back); 67*/ 68 69} //-------------------------------------------- 70void FORWARD (int Speed){ 71 //When we want to let Motor To move forward, 72 // just void this part on the loop section . 73 analogWrite(IN1,Speed); 74 analogWrite(IN2,0); 75 analogWrite(IN3,0); 76 analogWrite(IN4,Speed); 77}//-------------------------------------------- 78void BACKWARD (int Speed){ 79 //When we want to let Motor To move forward, 80 // just void this part on the loop section . 81 analogWrite(IN1,0); 82 analogWrite(IN2,Speed); 83 analogWrite(IN3,Speed); 84 analogWrite(IN4,0); 85}//-------------------------------------------- 86void ROTATE (int Speed) 87{ 88 //When we want to let Motor To Rotate , 89 // just void this part on the loop section . 90 analogWrite(IN1,Speed); 91 analogWrite(IN2,0); 92 analogWrite(IN3,Speed); 93 analogWrite(IN4,0); 94}//-------------------------------------------- 95void Stop(){ 96 //When we want to Motor To stop , 97 // just void this part on the loop section . 98 analogWrite(IN1,0); 99 analogWrite(IN2,0); 100 analogWrite(IN3,0); 101 analogWrite(IN4,0); 102}
Downloadable files
Motors wiring
Motors wiring

Motors wiring
Motors wiring

Documentation
Sumo Robot Laser Cut
sketch-up file for the robot design
Sumo Robot Laser Cut
Sumo Robot Laser Cut
sketch-up file for the robot design
Sumo Robot Laser Cut
Comments
Only logged in users can leave comments