SumoBot using HC-SR04, TCRT5000, L298n


hey guys have been working on sumobot project using 2xdc motors & 2xtcrt5000 & l298n motor driver &arduino uno, when run code find problems,
shuch motors move half revolution , down, ultra sonic sencor dosen't detect objects should.
the code use modified 1 online blog.
so please need code.!
this copy of  the code uploaded arduino  

code: [select]
#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
#define ir_sensor_back a1
int distance ;


void setup()
{
serial.begin(9600);
delay (5000);
}

void rotate (){
void loop();

  
 int ir_front = analogread(ir_sensor_front);
 int ir_back = analogread(ir_sensor_back);
 distance = ultrasonic.ranging(cm) ;
   analogwrite(in1,200);
  analogwrite(in2,0);
  analogwrite(in3,200);
  analogwrite(in4,0);

void stop();
 if (distance < 20){
    
  analogwrite(in1,0);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,0);
    }
    void forward ();
    while (distance < 20 ) {
  analogwrite(in1,255);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,255);
    distance = ultrasonic.ranging(cm);
    ir_front = analogread(ir_sensor_front);
    ir_back = analogread(ir_sensor_back);
    if ( ir_front > 650 || ir_back > 650 ) { break;}
    delay(10); }
  }

int ir_front = analogread(ir_sensor_front);
int ir_back = analogread(ir_sensor_back);
void loop(){
 if (ir_front <= 650 ) ;
   analogwrite(in1,0);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,0);
   delay (50);
  analogwrite(in1,0);
  analogwrite(in2,255);
  analogwrite(in3,255);
  analogwrite(in4,0);
   delay (500);

     if (ir_back <= 650 );
  
     analogwrite(in1,0);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,0);
   delay (50);
     analogwrite(in1,255);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,255);
   delay (500);
   }
  


and code found , modified
code: [select]
#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 // الحساس الامامي
#define ir_sensor_back a1 // الحساس الخلفي
int distance ;

void setup()
{
serial.begin(9600);
delay (5000); // حسب قوانين السومو
}


void loop()
{
  
 int ir_front = analogread(ir_sensor_front);
 int ir_back = analogread(ir_sensor_back);
 distance = ultrasonic.ranging(cm) ;
 rotate(200); // يبدأ الروبوت بالدوران

 if (distance < 20){
    stop();
    while (distance < 20 ) {
    forward(255);
    distance = ultrasonic.ranging(cm);
    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 يعني اللون ابيض
   {
   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 :");
  serial.println(ir_back);  
*/ --------------------------------------  

}



//--------------------------------------------
void forward (int speed){
  //when want let motor move forward,
  // void part on loop section .
  analogwrite(in1,speed);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,speed);
}


//--------------------------------------------
void backward (int speed){
  //when want let motor move forward,
  // void part on loop section .
  analogwrite(in1,0);
  analogwrite(in2,speed);
  analogwrite(in3,speed);
  analogwrite(in4,0);
}

//--------------------------------------------
void rotate (int speed){
  //when want let motor rotate ,
  // void part on loop section .
  analogwrite(in1,speed);
  analogwrite(in2,0);
  analogwrite(in3,speed);
  analogwrite(in4,0);
}


//--------------------------------------------
void stop(){
  //when want  motor stop ,
  // void part on loop section .
  analogwrite(in1,0);
  analogwrite(in2,0);
  analogwrite(in3,0);
  analogwrite(in4,0);
}

please read this:-
how use forum
because post breaking rules posting code.


Arduino Forum > Using Arduino > Project Guidance > SumoBot using HC-SR04, TCRT5000, L298n


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts